fix: keep file-path completions alive in shortcodes during typing#265
Merged
fix: keep file-path completions alive in shortcodes during typing#265
Conversation
Return CompletionList with isIncomplete when file-path items are present in shortcode argument or attribute value completions. This tells VS Code to re-query the provider as the user types rather than filtering a stale result locally, so bare words like "te" surface "test.txt" without needing quotes or a "./" prefix.
Set filterText to the basename so VS Code matches bare words like "te" against "test.qmd" regardless of directory depth. Prefix sortText with "0_" so file-path items rank above snippet suggestions.
File-path completion items in shortcodes now include folder items for directory navigation and use an explicit replacement range that covers the full partial path token. This fixes two issues: directories containing matching files were not shown, and paths with separators (/ and .) were not replaced correctly because Quarto's wordPattern excludes those characters. Changes: - buildFilePathCompletions returns Folder items for parent directories of matched files, each with triggerSuggest to continue navigation. - filterText uses the full relative path instead of basename so typing a path prefix like "subdir/te" correctly filters to matching files. - ShortcodeCompletionProvider.setFilePathRange computes the token start by scanning backwards for delimiters and sets item.range on all File/Folder items.
Address review findings from the file-path completion changes:
- buildFilePathCompletions accepts an optional `includeFolders` flag
(default false). Only the shortcode provider passes true, so folder
items no longer leak into the YAML and element attribute providers.
- Relative paths are normalised to forward slashes via
split(path.sep).join("/") for consistent filtering on Windows.
- Directory segments are split on "/" (matching the normalised paths)
instead of the platform separator.
- completeArgument skips setting triggerSuggest on File items so that
accepting a file closes the suggest widget instead of reopening it.
Only show files at the same directory level as the typed prefix. Files in subdirectories are hidden until the user navigates into the containing folder by accepting a folder item. The shortcode provider now computes the directory prefix from the typed text and filters items: file items must be directly under the prefix directory, and folder items must be immediate children of it. This replaces the previous approach of returning all files at every depth and relying on VS Code's fuzzy matching to sort them.
The backspace listener was firing triggerSuggest for any deletion in .qmd files, causing "No suggestions." popups in plain text. Now it checks isInYamlRegion before re-triggering, so the suggest widget only reopens when the cursor is inside the YAML front-matter or a .yml file.
The shortcode parser returns `cursorContext = "argument"` for the first attribute key when no prior named attributes exist (because the `=` sign has not been reached yet). The hover provider had no handler for this context, so hovering over attribute keys showed nothing. Add `hoverArgument` that checks whether the word under the cursor is followed by `=` (delegate to attribute key hover) or is a positional argument (show the argument descriptor).
Use a `!` prefix on `sortText` across all three completion providers so extension-driven items rank before VS Code's snippet suggestions, which use alphabetic sort keys. Sorting tiers: - `!0_` required attributes/arguments - `!1_` optional attributes, shortcode names, enum/boolean values - `!2_` file-path and folder items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CompletionListwithisIncomplete: truein the shortcode completion provider when file-path items are present.tesurfacetest.txtwithout needing quotes or a./prefix.argumentandattributeValuecompletion branches, only when the result includes file-path items (CompletionItemKind.File).Test plan
.qmdfile, type{{< external te(whereexternalhas acompletion.type: fileargument andtest.txtexists). Verifytest.txtappears in completions without needing"./.npx tsc --noEmit,npx eslint src/, andnpx prettier --check "src/**/*.ts"all pass.