feat: filter path suggestions by file type in HTML attributes #218
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.