Implement autoImportFileExcludePatterns parameter for filtering auto-import suggestions #2
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.
Overview
This PR implements the
autoImportFileExcludePatterns
parameter in the Go port of TypeScript, allowing users to exclude specific files or directories from auto-import suggestions. This feature was already declared in theUserPreferences
struct but not fully implemented with the necessary gating logic.Changes
Core Implementation
The implementation adds filtering logic based on glob patterns that follows the TypeScript source code closely:
getIsExcludedPatterns()
: Converts user-provided glob patterns (e.g.,/project/node_modules/**/*
) into compiled regular expressions using the existingvfs
utilitiesgetIsExcluded()
: Creates a filter function that checks if source files match any exclusion patterngetIsFileExcluded()
: Public helper function for checking file exclusions, matching the TypeScript APIIntegration Points
Updated the module enumeration pipeline to respect exclusion patterns:
forEachExternalModuleToImportFrom()
: Now acceptsuseCaseSensitiveFileNames
parameter and creates exclusion patterns from user preferencesforEachExternalModule()
: Filters source files and ambient module declarations based on exclusion patternsautoimportsexportinfo.go
: Updated call sites to pass the case-sensitive file names flag from the language service hostUsage Example
With these preferences, auto-import suggestions will exclude any files matching the specified patterns, keeping the completion list focused on relevant project files.
Testing
Added comprehensive test coverage in
autoImportFileExcludePatterns_test.go
:All existing tests continue to pass, confirming backward compatibility.
Bug Fix
Also fixed an unrelated import cycle issue in
findallreferences.go
that was preventing compilation.Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.