Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Package Acquisition and Full Project Loads for TypeScript on Web #182791

Closed
DanielRosenwasser opened this issue May 17, 2023 · 4 comments · Fixed by #212370
Closed

Automatic Package Acquisition and Full Project Loads for TypeScript on Web #182791

DanielRosenwasser opened this issue May 17, 2023 · 4 comments · Fixed by #212370
Assignees
Labels
feature-request Request for new features or functionality typescript Typescript support issues verified Verification succeeded web Issues related to running VSCode in the web

Comments

@DanielRosenwasser
Copy link
Member

TypeScript in VS Code has already been able to support workloads across TypeScript and JavaScript projects in web scenarios, such as on https://vscode.dev and https://github.dev. Unfortunately, it suffers from two problems:

  1. It only supports a "partial semantic" mode, and only operates on open files.
  2. It cannot provide rich navigation and authoring based on external libraries, due to a lack of either automatic type acquisition or in-browser package management.

Over the past months, @sandersn, @zkat, and others have experimented with enabling these experiences on the web through a few separate efforts, and we think VS Code in the browser should be able to adopt them in a near-term iteration.

Full Project Loads

Editing or exploring TypeScript and JavaScript projects is decent today; however, cross-file navigation, auto-completion, and more are extremely limited from not having the full project graph available. Without files from the same program or configuration files, we can't give anything close to the experience we provide outside of the browser.

Currently, there are means to experimentally enable a full project load by using a custom server host in the browser. This is powered by @vscode/sync-api-client. In https://vscode.dev, the TypeScript extension should be able to leverage this custom host when it creates a custom tsserver instance.

Automatic Package Acquisition

Even when we load the full program graph in TypeScript, we'll still be missing the declaration files from external libraries, which are a huge part of the editing experience. This is a familiar problem - when TypeScript started supporting JavaScript projects, managing declaration files was a process specific to TypeScript projects. That's why TypeScript supports a process called "automatic type acquisition". When TSServer is started, it can be given the path to a "typings installer" process, and in certain cases, when TypeScript's project system encounters an unresolved import, it will send a message to that typings installer process. For files that should appear in an unresolved package like foo, declaration files from @types/foo are downloaded to a cache and projects then have the option to use these declaration files when a path fails to resolve.

This is close to what a user needs for a TypeScript-in-the-web experience, except that

  1. ATA is usually never triggered for a TypeScript project (unless a user enables it (don't do this))
  2. ATA doesn't cover installing any @types packages
  3. ATA works via best-effort, and just grabs the latest version

What we want is something closer to what one might call "automatic package acquisition" that can fetch the actual package in the most accurate way.

We've made some more of our APIs public in the TSServer library. Over at zkat#1, we have a proof-of-concept doing exactly this using

  1. a custom typingsInstaller.js that can be run on the web
  2. an npm dependency evaluator/downloader that we can run in web contexts

This combo works pretty well in our cursory experimentation! Still, there's some more polish that will need to go into this.

Current Next Steps

As you can see from the checklist over at zkat#1, there's still a bit of work to be done.

  1. We need to decide on whether the current proof of concept is sufficient, or if it can serve as an inspiration for whatever is the "right" implementation.
  2. We should identify a (reasonable) target date for when we'd like to get this work rolled out by so that we can work backwards and figure out what to correct and prioritize.
  3. There are several TODOs in the PR, that are either bugs or possibly-missing features. If we choose the path of a new implementation, they may be "automatically"; but regardless, we should make sure they are tested. Of those, there's a rough way to divide remaining tasks work based on affinity/expertise:
    • vscode.dev mechanics
      • Decide on a caching mechanism (e.g. localStorage)
      • Support installation for private registries via CORS configuration
    • Typings Installer and TSServer mechanics
      • Investigate package.json File Watching issues
      • Investigate Go-to-Source-Definition issues
      • Investigate First ATA Events Being Blocked on File Close
@sandersn
Copy link
Member

Here's a draft PR based on @zkat's work: #182801

I wrote up a short overview of the changes with pointers into the code.

@mjbvz mjbvz added this to the June 2023 milestone May 18, 2023
@mjbvz mjbvz added the feature-request Request for new features or functionality label May 25, 2023
@mjbvz mjbvz modified the milestones: June 2023, July 2023 Jun 22, 2023
@mjbvz mjbvz modified the milestones: July 2023, August 2023 Jul 18, 2023
@mjbvz mjbvz modified the milestones: August 2023, September 2023 Aug 29, 2023
@mjbvz mjbvz modified the milestones: September 2023, October 2023 Sep 26, 2023
@mjbvz mjbvz modified the milestones: October 2023, November 2023 Oct 24, 2023
@mjbvz mjbvz modified the milestones: November 2023, December 2023 Nov 21, 2023
@mjbvz mjbvz added typescript Typescript support issues web Issues related to running VSCode in the web labels Dec 14, 2023
@mjbvz mjbvz modified the milestones: December / January 2024, February 2024 Jan 22, 2024
@mjbvz mjbvz modified the milestones: February 2024, March 2024 Feb 21, 2024
@Abdallatif
Copy link

Not sure if this is the best place to report the bug but I'm going to post here since this is a work-in-progress. I'm trying to setup vscode on the web with typescript support using https://github.com/CodinGame/monaco-vscode-api. My app has private npm packages (node_modules) that are already mounted in the vscode filesystem tree. I found that typescript server ignores my node_modules directory and always tries to download the package from npm.

I was able to fix the issue by disabling this behavior by commenting this line. You can find more details about this issue here.

Do you think it makes sense for AutoInstallerFs to be initialized from the filesystem node_modules folder and maybe check the filesystem before trying to download the package from a registry.

@mjbvz mjbvz modified the milestones: March 2024, April 2024 Mar 25, 2024
@mjbvz mjbvz removed this from the April 2024 milestone Apr 22, 2024
mjbvz added a commit that referenced this issue May 9, 2024
* Enable web type acquisition by default for js/ts

Fixes #182791
Fixes #172887

* Cleanup
@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels May 9, 2024
@mjbvz mjbvz modified the milestones: May 2024, June 2024 May 24, 2024
@benibenj benibenj added insiders-released Patch has been released in VS Code Insiders and removed insiders-released Patch has been released in VS Code Insiders labels May 28, 2024
@mjbvz mjbvz reopened this May 28, 2024
@vscodenpa vscodenpa removed the insiders-released Patch has been released in VS Code Insiders label May 28, 2024
@mjbvz mjbvz modified the milestones: June 2024, July 2024 Jun 24, 2024
@mjbvz mjbvz modified the milestones: July 2024, August 2024 Jul 24, 2024
mjbvz added a commit to mjbvz/vscode that referenced this issue Aug 2, 2024
For microsoft#182791

With this change, we now make a single call to the package manager per root instead of per package. This simplifies the code and should be better for perf

Still seeing a bunch of errors in the console but TS typing is working ok. Needs more exploration for ATA
mjbvz added a commit that referenced this issue Aug 2, 2024
Try to fix ata perf issues on web

For #182791

With this change, we now make a single call to the package manager per root instead of per package. This simplifies the code and should be better for perf

Still seeing a bunch of errors in the console but TS typing is working ok. Needs more exploration for ATA
mjbvz added a commit to mjbvz/vscode that referenced this issue Aug 23, 2024
For microsoft#182791

Enabling for further testing
@mjbvz mjbvz modified the milestones: August 2024, September 2024 Aug 26, 2024
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 20, 2024

Should be working. Have run into a few edge cases but overall seems to be working well

@mjbvz mjbvz closed this as completed Sep 20, 2024
@mjbvz mjbvz added the verified Verification succeeded label Sep 23, 2024
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 23, 2024

Marking as verified because we actually went through testing last iteration: #226653

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality typescript Typescript support issues verified Verification succeeded web Issues related to running VSCode in the web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants