You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto import does not import Disposable or Emitter from VS Code's codebase #55781
This issue has been around for years, I think I've mentioned it in DMs but not sure if there's an issue. Regardless, here's a detailed description of it. I'm assuming this is an upstream issue but please keep this issue open to track as it's a papercut.
This does impact my productivity; instead of auto import just working like it's supposed to, I instead have to:
Andrew Branch (@andrewbranch) Any ideas why Event would be found from a bunch of files in our codebase but not the main definition we typically want: vs/base/common/event
I see EventBufferer gets picked up from there so the file is known but something must be filtering out Event
It’s because the Event declared at vs/base/common/event.ts is re-exported via vs/workbench/workbench.web.main.ts. Completions only shows you a single location for each exported symbol, and the most-reexported one is assumed to be the “most public.” This is designed to avoid duplicates from cascading barrel files. Suppose Dropdown is subsequently re-exported by the following files:
/foo/shared/components/dropdown/Dropdown.ts
/foo/shared/components/dropdown/index.ts
/foo/shared/components/index.ts
/foo/shared/index.ts
/foo/index.ts
We only show a completion for the last one because it had the longest chain. Note that at this point in the filtering, we don’t know what the module specifier is going to be yet, but this often (but not always) results in us picking a file that will generate a shorter module specifier than the others.
This heuristic is becoming increasingly suspect. Many users are beginning to realize that barrel files are terrible for tree-shaking their apps and will try to go out of their way to avoid importing from one in their dependencies, but TS always prioritizes it. But it doesn’t seem like there’s a universally better heursitic for choosing a location, and the alternative is exploding the size of the completions list with lots of duplicates. Including all symbol export locations or switching to another heuristic that operates on the final module specifier (as opposed to the file name or position in the re-export chain) would increase the number of items we have to generate a module specifier for, which is a relatively expensive operation within completions.
Andrew Branch (@andrewbranch) any recommendation for how we can solve this on our end? I don't think we ever want to import these functions from workbench.web.main.ts while working in the core repo as that's just the public API for embedders like vscode.dev.
Quick fixes are only requested when there’s an error, and there’s no error because of the DOM type. The issue described in the OP is for auto-imports via completions, not fixes. This was discussed at #28739.
I don’t think we ever explored triggering the codefix on incorrect generics. We could also look into triggering this as a refactor, not a codefix.
Matt Bierner (@mjbvz) yes I'm on Windows. I thought I saw it working just now after changing the separator but it's broken again. Using this doesn't seem to work 😕
The Windows problem should be related to the drive letter. The src/vs/workbench/workbench.web.main.ts pattern is normalized to /**/src/vs/workbench/workbench.web.main.ts in the client, and the regex pattern for that is /^((\/.+?)?\/src\/vs\/workbench\/workbench\.web\.main\.ts)($|\/)/i which doesn't match the drive letter in the start c:/path/to/vscode/src/vs/workbench/workbench.web.main.ts.
#56415 also uses Windows, so it should be related.
Activity
meganrogge commentedon Aug 24, 2023
Similarly,
Eventis never automatically imported for me.bpasero commentedon Sep 8, 2023
Previously at microsoft/vscode#116417
mjbvz commentedon Sep 18, 2023
Andrew Branch (@andrewbranch) Any ideas why
Eventwould be found from a bunch of files in our codebase but not the main definition we typically want:vs/base/common/eventI see
EventBufferergets picked up from there so the file is known but something must be filtering outEventandrewbranch commentedon Sep 18, 2023
It’s because the
Eventdeclared atvs/base/common/event.tsis re-exported viavs/workbench/workbench.web.main.ts. Completions only shows you a single location for each exported symbol, and the most-reexported one is assumed to be the “most public.” This is designed to avoid duplicates from cascading barrel files. SupposeDropdownis subsequently re-exported by the following files:/foo/shared/components/dropdown/Dropdown.ts/foo/shared/components/dropdown/index.ts/foo/shared/components/index.ts/foo/shared/index.ts/foo/index.tsWe only show a completion for the last one because it had the longest chain. Note that at this point in the filtering, we don’t know what the module specifier is going to be yet, but this often (but not always) results in us picking a file that will generate a shorter module specifier than the others.
This heuristic is becoming increasingly suspect. Many users are beginning to realize that barrel files are terrible for tree-shaking their apps and will try to go out of their way to avoid importing from one in their dependencies, but TS always prioritizes it. But it doesn’t seem like there’s a universally better heursitic for choosing a location, and the alternative is exploding the size of the completions list with lots of duplicates. Including all symbol export locations or switching to another heuristic that operates on the final module specifier (as opposed to the file name or position in the re-export chain) would increase the number of items we have to generate a module specifier for, which is a relatively expensive operation within completions.
Tyriar commentedon Sep 19, 2023
Andrew Branch (@andrewbranch) any recommendation for how we can solve this on our end? I don't think we ever want to import these functions from workbench.web.main.ts while working in the core repo as that's just the public API for embedders like vscode.dev.
bpasero commentedon Sep 19, 2023
Daniel Imms (@Tyriar) I had thought this setting would do the trick? But maybe it broke?
Tyriar commentedon Sep 19, 2023
Benjamin Pasero (@bpasero) I don't see that in our settings.json, is that the problem?
Add typescript.preferences.autoImportFileExcludePatterns to repo
mjbvz commentedon Sep 19, 2023
Adding that setting seems to fix
EventandDisposable. Opened microsoft/vscode#193477 to add this as a workspace settingAdd typescript.preferences.autoImportFileExcludePatterns to repo (#19…
bpasero commentedon Sep 19, 2023
Matt Bierner (@mjbvz) for me this setting never fixed
Event. I think it only helped forDisposable. Here is a recording of what I see:The issue for
Eventseems to be that the name duplicates the DOMEvent, so no import is suggested, not even when I add generics.andrewbranch commentedon Sep 19, 2023
Quick fixes are only requested when there’s an error, and there’s no error because of the DOM type. The issue described in the OP is for auto-imports via completions, not fixes. This was discussed at #28739.
I don’t think we ever explored triggering the codefix on incorrect generics. We could also look into triggering this as a refactor, not a codefix.
Tyriar commentedon Sep 19, 2023
Matt Bierner (@mjbvz) still not working for me after pulling the settings change and restarting ts server
mjbvz commentedon Sep 19, 2023
Daniel Imms (@Tyriar) It's working for me:
Are you on windows? Wonder if there's something happening with
\pathsTyriar commentedon Sep 19, 2023
Matt Bierner (@mjbvz) yes I'm on Windows. I thought I saw it working just now after changing the separator but it's broken again. Using this doesn't seem to work 😕
andrewbranch commentedon Sep 19, 2023
The slashes should be normalized by TS, but maybe there’s something else Windows-specific going on 🤔
jasonlyu123 commentedon Dec 12, 2023
The Windows problem should be related to the drive letter. The
src/vs/workbench/workbench.web.main.tspattern is normalized to/**/src/vs/workbench/workbench.web.main.tsin the client, and the regex pattern for that is/^((\/.+?)?\/src\/vs\/workbench\/workbench\.web\.main\.ts)($|\/)/iwhich doesn't match the drive letter in the startc:/path/to/vscode/src/vs/workbench/workbench.web.main.ts.#56415 also uses Windows, so it should be related.
Tyriar commentedon Jan 29, 2024
Just came back from a break and noticed this was fixed, thanks so much!