-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
Explore enabling type acquisition for web TS Server #172887
Comments
Lots of open questions about how this should behave and how we can implement it:
|
Having NPM provide a CDN like how unpkg works would be a nice solution for this (because I have this same issue in the TS playground) |
I recently re-wrote the ATA for the Playground ( microsoft/TypeScript-Website#1997 ) in what I think is a pretty good conceptual pattern:
It's not exactly like that in practice (you need the version number before you can make that API call to jsdelivr) - but that's good enough and you can read the implementation linked above for more details. The implementation of the TypeScript Playground ATA is built for third parties, so you could be a consumer of An ideal state for VS Code which would keep this entirely first-party, is that the npm registry adds two APIs like:
Or vscode creates an API which proxies these APIs to jsdelivr (they're real nice folks, I can make an intro if needed) which allows for other implementations behind the scenes in time. |
We are already watching - ping me any time if needed 😄 |
The Playground ATA re-write is now available on npm at @typescript/ata and deploying to the web as we speak. |
For #45314 This prototypes ATA for the web version of TypeScript. The logic is copied from the `@typescript/ata` project The current implementation is not complete, mainly because I don't understand how to get the d.ts files into the TS project correctly
microsoft/TypeScript#46862 Adds a draft implementation of this but I definitely need some help from the TS team to get it into a shippable state |
After discussion, we'd like to move the core auto import implementation to VS Code @orta I looked into using After thinking about this more, I am also wondering if using |
@orta @amcasey I have a basic prototype now running on the VS Code side and can use this to load global typings such as The problem I'm running into now though is telling TS that Here's how the files are currently opened after ATA has completed (I'm using the paths that TS server sees):
import * as $ from 'jquery' Then we have a list of jQuery d.ts files that VS Code has opened up with the correct content:
All of these are in-memory files so TS Server cannot read them directly. I believe we also have to keep the different scheme ( What type of API do you think we need to get typescript to understand that |
There's a similar tension in doing the full TypeScript compile in the ts-vscode playground - I wonder if a reasonable strategy lays in making the TypeScript web server smarter, and keeping some of the file content inside that. As it exists, there is no way to influence what is available to that TSServer: function createWebSystem(args: string[]) {
Debug.assert(ts.sys === undefined);
const webHost: WebHost = {
readFile: webPath => {
const request = new XMLHttpRequest();
request.open("GET", webPath, /* asynchronous */ false);
request.send();
return request.status === 200 ? request.responseText : undefined;
},
fileExists: webPath => {
const request = new XMLHttpRequest();
request.open("HEAD", webPath, /* asynchronous */ false);
request.send();
return request.status === 200;
},
writeMessage,
}; I think somewhere there needs to be a vfs map which the tsserver prioritises for
I think that might get tricky with the schema change, I think you'd need to hardcode that somehow into the TS web server code somehow (for examples it is kinda safe that all paths with |
@orta Thanks! Not sure I understand the first part though. With my current approach, on web all TS files are opened against as in-memory resources. This means that TS knows the file content but should not try to read these files from disk. Are you proposing a different approach where For the second part, who is the best point of contact to discuss this with? If needed I think we could rewrite the paths that VS Code sends to TS Server to make the project system happy, but I'd like to explore a proper solution first |
My current proposal would be a new TS Server api that let a client explicitly pass global typings files to the TypeScript Server. This could be used both to implement ATA, and also for applications like Office Scripts where you have a VS Code extension that wants to augment the global typings in JS files Some of this discussion also gets into our discussions around virtual file system support for vscode.dev One idea: could a client for example tell TS Server about a type root directory and then the server would simply treat any files opened under this directory as typings From a protocol point of view, this would look something like:
|
(sorry, been a busy few weeks) I'm not sure that you need to special case the vfs as only being typings specifically, for the playground ATA we emulated having files in If you have a generic system to put vfs files into the web tsserver's sys then you can put files into the right place and it would automatically be respected by the rest of the tsserver |
Opened microsoft/TypeScript#47600 to continue discussion of generic virtual file system support for TS Server. Using this, I believe we could implement ATA by writing the acquired typings to the correct location in the virtual file system |
is the intellisense between typescript files also in scope? like will I get intellisense for a hello function declared in a different file when I import it? |
Follow up on microsoft/TypeScript#39707
Overview
We now have TSServer running in web environments, but it is currently limited to single file intellisense. It would be nice if we could also offer some IntelliSense for third party packages that are imported in the current file.
If a user is trying out react for example, we should be able to offer IntelliSense for
React
andReactDOM
:The text was updated successfully, but these errors were encountered: