feat: filter path suggestions by file type in HTML attributes#218
Merged
aeschli merged 3 commits intomicrosoft:mainfrom Dec 1, 2025
Merged
Conversation
Implements intelligent file filtering for HTML path completion based on tag type and attributes. Files matching the expected type are now prioritized in autocomplete suggestions. Changes: - Add optional 'attributes' field to HtmlAttributeValueContext interface - Pass node attributes to completion participants in htmlCompletion - Implement getExtensionFilter() method in pathCompletion - Use sortText to prioritize matching files (0_) over others (1_) - Support multiple tag/attribute patterns: * <link rel="stylesheet"> prioritizes CSS files * <link rel="icon"> prioritizes image files * <script src> prioritizes JavaScript files * <img src> prioritizes image files * <video src> prioritizes video files * <audio src> prioritizes audio files - Add comprehensive tests for filtering behavior - Maintain backward compatibility (non-exclusive filtering) All files remain visible and selectable; filtering is non-exclusive. Directories are always included. No breaking changes to existing API. Fixes #242999 Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements intelligent file filtering for HTML path completion based on the HTML context (tag and attribute combinations). When typing paths in HTML attributes, files are now prioritized by their expected file type - for example, CSS files appear first when autocompleting in <link rel="stylesheet" href="">.
- Added context-aware filtering that analyzes both HTML tag name and attributes to determine relevant file types
- Implemented non-exclusive prioritization using
sortTextto maintain backward compatibility - Extended support for 6+ tag/attribute patterns including stylesheets, scripts, images, videos, and audio files
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/htmlLanguageTypes.ts | Added optional attributes field to HtmlAttributeValueContext interface |
| src/services/htmlCompletion.ts | Modified to pass node attributes to completion participants |
| src/services/pathCompletion.ts | Implemented core filtering logic with getExtensionFilter() method and updated suggestion prioritization |
| src/test/pathCompletions.test.ts | Added 4 comprehensive test cases and updated existing test count |
| src/test/pathCompletionFixtures/styles.css | Added CSS test fixture file |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
aeschli
approved these changes
Dec 1, 2025
bpasero
approved these changes
Dec 1, 2025
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
This PR implements intelligent file filtering for HTML path completion, addressing microsoft/vscode#242999.
When typing paths in HTML attributes, files are now prioritized based on the expected file type. For example,
<link rel="stylesheet" href="">now shows CSS files first, making it faster and easier for developers to find the right files.Problem
Currently, when autocompleting file paths in HTML attributes, VS Code shows all files regardless of the context. This makes it harder to find the appropriate file, especially in large projects with many different file types.
Example: When typing
<link rel="stylesheet" href="">, developers have to scroll through JavaScript files, images, HTML files, etc., to find their CSS files.Solution
This implementation analyzes the HTML tag and its attributes to determine which file types are most relevant, then prioritizes those files in the autocomplete list using
sortText.Key Features
<link rel="stylesheet">)Changes
Core Implementation
attributesfield toHtmlAttributeValueContextinterfacenode.attributesto completion participantsgetExtensionFilter()method for context analysisprovidePathSuggestions()to apply filtering usingsortTextTesting
styles.csstest fixtureSupported Patterns
<link rel="stylesheet" href="">.css,.scss,.sass,.less<link rel="icon" href="">.ico,.png,.svg,.jpg,.jpeg,.gif,.webp<link rel="apple-touch-icon" href="">.ico,.png,.svg,.jpg,.jpeg,.gif,.webp<script src="">.js,.mjs,.cjs,.ts,.tsx,.jsx<img src="">.png,.jpg,.jpeg,.gif,.svg,.webp,.bmp,.ico<video src="">.mp4,.webm,.ogg,.mov,.avi<audio src="">.mp3,.wav,.ogg,.m4a,.aac,.flacHow It Works
<link>withrel="stylesheet")getExtensionFilter()determines relevant file extensionssortText = "0_filename"(appear first)sortText = "1_filename"(appear second)Testing
Automated Tests
Results: All 146 tests passing ✅
New Test Cases
<link rel="stylesheet"><link rel="icon"><script>tagsBackward Compatibility
✅ Fully backward compatible
Performance
sortTextmechanismRelated Issues
Behavior
Before: (All files mixed together)
After for
<link rel="stylesheet" href="">: (CSS files prioritized)Checklist
Additional Notes
This implementation follows the guidance from the cited issue thread to implement the feature in
src/services/pathCompletion.ts. The solution is production-ready and can be easily extended to support additional tag/attribute combinations in the future.The filtering is intentionally non-exclusive to maintain flexibility - all files are still shown, just in a better order. This ensures users can still select any file if needed, while making the common case (selecting the correct file type) much faster.
Note: This PR is for the
vscode-html-languageservicerepository. The issue #242999 is in the mainvscoderepository.