Skip to content

Auto import does not import Disposable or Emitter from VS Code's codebase #55781

Closed
microsoft/vscode
#202762

Description

@Tyriar

Related to microsoft/vscode#116375

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:

  1. Import one of the other symbols
  2. Scroll to the top of the file
  3. Find the import
  4. Change the import
  5. Go back
  6. Change the symbol I entered in step 1

Image

AsyncEmitter and EmitterOptions shows up:

https://github.com/microsoft/vscode/blob/85de2f21c63608e8bbc5c2347fe927b00c8300bf/src/vs/base/common/event.ts#L1184

https://github.com/microsoft/vscode/blob/85de2f21c63608e8bbc5c2347fe927b00c8300bf/src/vs/base/common/event.ts#L695

But not Emitter:

https://github.com/microsoft/vscode/blob/85de2f21c63608e8bbc5c2347fe927b00c8300bf/src/vs/base/common/event.ts#L897


Image

Image

DisposableStore and DisposableMap shows up:

https://github.com/microsoft/vscode/blob/85de2f21c63608e8bbc5c2347fe927b00c8300bf/src/vs/base/common/lifecycle.ts#L210

https://github.com/microsoft/vscode/blob/85de2f21c63608e8bbc5c2347fe927b00c8300bf/src/vs/base/common/lifecycle.ts#L503

But not Disposable:

Image

Activity

  1. added
    Bug
    on Aug 18, 2023
  2. meganrogge commented on Aug 24, 2023

    @meganrogge

    Similarly, Event is never automatically imported for me.

  3. bpasero commented on Sep 8, 2023

    @bpasero
  4. mjbvz commented on Sep 18, 2023

    @mjbvz
    Contributor

    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

    Screenshot 2023-09-18 at 2 20 23 PM

    I see EventBufferer gets picked up from there so the file is known but something must be filtering out Event

  5. andrewbranch commented on Sep 18, 2023

    @andrewbranch
    Member

    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.

  6. Tyriar commented on Sep 19, 2023

    @Tyriar
    ContributorAuthor

    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.

  7. bpasero commented on Sep 19, 2023

    @bpasero

    Daniel Imms (@Tyriar) I had thought this setting would do the trick? But maybe it broke?

    "typescript.preferences.autoImportFileExcludePatterns": [
        "xterm",
        "xterm-headless",
        "node-pty",
        "vscode-notebook-renderer",
        "src/vs/workbench/workbench.web.main.ts",
        "src/vs/workbench/api/common/extHostTypes.ts"
    ]
    
  8. Tyriar commented on Sep 19, 2023

    @Tyriar
    ContributorAuthor

    Benjamin Pasero (@bpasero) I don't see that in our settings.json, is that the problem?

  9. mjbvz commented on Sep 19, 2023

    @mjbvz
    Contributor

    Adding that setting seems to fix Event and Disposable. Opened microsoft/vscode#193477 to add this as a workspace setting

  10. bpasero commented on Sep 19, 2023

    @bpasero

    Matt Bierner (@mjbvz) for me this setting never fixed Event. I think it only helped for Disposable. Here is a recording of what I see:

    Recording 2023-09-19 at 20 19 31

    The issue for Event seems to be that the name duplicates the DOM Event, so no import is suggested, not even when I add generics.

  11. andrewbranch commented on Sep 19, 2023

    @andrewbranch
    Member

    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.

  12. Tyriar commented on Sep 19, 2023

    @Tyriar
    ContributorAuthor

    Matt Bierner (@mjbvz) still not working for me after pulling the settings change and restarting ts server

    image
    image

  13. mjbvz commented on Sep 19, 2023

    @mjbvz
    Contributor

    Daniel Imms (@Tyriar) It's working for me:

    Screenshot 2023-09-19 at 12 11 13 PM

    Are you on windows? Wonder if there's something happening with \ paths

  14. Tyriar commented on Sep 19, 2023

    @Tyriar
    ContributorAuthor

    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 😕

    		"src/vs/workbench/workbench.web.main.ts",
    		"src/vs/workbench/api/common/extHostTypes.ts",
    		"src\\vs\\workbench\\workbench.web.main.ts",
    		"src\\vs\\workbench\\api\\common\\extHostTypes.ts"
    
  15. andrewbranch commented on Sep 19, 2023

    @andrewbranch
    Member

    The slashes should be normalized by TS, but maybe there’s something else Windows-specific going on 🤔

  16. jasonlyu123 commented on Dec 12, 2023

    @jasonlyu123
    Contributor

    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.

  17. added
    Fix Available
    on Jan 18, 2024
  18. Tyriar commented on Jan 29, 2024

    @Tyriar
    ContributorAuthor

    Just came back from a break and noticed this was fixed, thanks so much!

  19. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFix Available

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions