Skip to content

fix: keep file-path completions alive in shortcodes during typing#265

Merged
mcanouil merged 9 commits intomainfrom
fix/shortcode-file-path-completion
Feb 16, 2026
Merged

fix: keep file-path completions alive in shortcodes during typing#265
mcanouil merged 9 commits intomainfrom
fix/shortcode-file-path-completion

Conversation

@mcanouil
Copy link
Copy Markdown
Owner

Summary

  • Return CompletionList with isIncomplete: true in the shortcode completion provider when file-path items are present.
  • This tells VS Code to re-query the provider as the user types, so bare words like te surface test.txt without needing quotes or a ./ prefix.
  • Applied to both argument and attributeValue completion branches, only when the result includes file-path items (CompletionItemKind.File).

Test plan

  • In a .qmd file, type {{< external te (where external has a completion.type: file argument and test.txt exists). Verify test.txt appears in completions without needing "./.
  • Verify non-file completions (enum values, attribute keys) are unaffected and still returned as plain arrays.
  • npx tsc --noEmit, npx eslint src/, and npx prettier --check "src/**/*.ts" all pass.

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.
@mcanouil mcanouil added the Type: Bug 🐛 Issues related to bugs, errors, or mistakes label Feb 16, 2026
@mcanouil mcanouil self-assigned this Feb 16, 2026
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
@mcanouil mcanouil merged commit d170748 into main Feb 16, 2026
7 checks passed
@mcanouil mcanouil deleted the fix/shortcode-file-path-completion branch February 16, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug 🐛 Issues related to bugs, errors, or mistakes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant