Add TS Server option to exclude files from auto-imports#49578
Merged
andrewbranch merged 5 commits intomicrosoft:mainfrom Jun 17, 2022
Merged
Add TS Server option to exclude files from auto-imports#49578andrewbranch merged 5 commits intomicrosoft:mainfrom
andrewbranch merged 5 commits intomicrosoft:mainfrom
Conversation
amcasey
approved these changes
Jun 16, 2022
|
There might be some demand for file-level excludes: see date-fns/date-fns#3113 which could be alleviated by excluding |
5 tasks
|
It would be cool to include option for |
5 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #35395
Adds a TS Server option (to be specified in
.vscode/settings.json) calledautoImportFileExcludePatterns. The format is identical to tsconfig.jsonexcludespecs, except I plan to do the following normalization on the VS Code side before sending to TS Server:*will be prefixed with/, e.g."**/node_modules/aws-sdk"will become"/**/node_modules/aws-sdk""node_modules/aws-sdk") will be prefixed with/**/to match any directory prefix.It’s also worth noting how this setting affects ambient modules and module augmentations (
autoImportFileExcludePatterns3.tsin the tests). While the input to this setting refers to files, I’ve chosen to limit the granularity at which we filter to be per-module, not per-export. That means if more than one file declares an ambient module"foo", you can’t exclude the exports declared in just one of those files. We end up callinggetMergedSymbolon these modules before looking at their individual exports, so we see all the exports from many files lumped together. (Keep in mind this setting does not exclude anything from your program, so excluded files in this setting still contribute to overall program knowledge.) If you wanted that kind of granularity, we’d have to look at the declarations of each export and evaluate the regexes against those rather than just doing it at the file level. With the right memoization, that might be possible, but I’d prefer to wait and see if there’s demand for it. As it is, to exclude an ambient module, the exclude patterns have to match every file that declares it, and its exports are either all included or all excluded.