-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Prototype TS Compile on Save #32103
Prototype TS Compile on Save #32103
Conversation
Rough initial prototype of enabling compileOnSave for TypeScript
When I last looked into this I wanted to implement build On Save which might be different than what you now try to do with compile on save. Compile on save emits all necessary JS files after one file changes. But it doesn't allow you to get all TS errors when a project opens (like we do in VS Code with npm run watch). Problems I saw / addressed:
For sure more if I continue thinking about it. In general I believe that having something like a builder can only be implemented inside the TSServer in an efficient way. |
@mjbvz @dbaeumer With microsoft/TypeScript#17669 we will have implementation in builder to be able to give diagnostics/cache them based on the changes. It would be possible to give the error list as well as the emit file list through that. With https://github.com/Microsoft/TypeScript/pull/17269/files#diff-efa731ca7c6279501f903db87403d2beR627 I already have todo that I need to address before merging about the event we send so that event handler receives the event about change in project structure to be able to update the error checks.
Apart from this I think these are the few things you would need:
Also you could use geterrForProject (to get errors for complete project instead of just specific file https://github.com/Microsoft/TypeScript/blob/master/src/server/session.ts#L1598) or keep the same implementation and request errors for specific files. And was there reason to get semantic diagnostics before the syntactic errors? |
@sheetalkamat thanks for the update. When I implemented the builder inside the tsserver I tried to use geterrForProject however this didn't scale well for large projects. When I tried this with a VS Code workspace it took minutes for the call to complete. This is why I implemented the builder state. With that I was able to open a project and reconstruct the error state in ~10 seconds for VS Code. This code still exists here: https://github.com/Microsoft/TypeScript/tree/dbaeumer/9125. Vlad took parts of the code and moved it into the current builder of the tsserver. But may be we can reuse more of it. For example here is the state handling https://github.com/Microsoft/TypeScript/blob/dbaeumer/9125/src/server/builder.ts#L1400 |
@mjbvz can you check if microsoft/TypeScript#17820 seems like what you could use to rely on us to notify the changes to project? Currently i replaced this for the internal context event which was sent when file was deleted and it would update the error checks for all the open files. Instead I am now scheduling error checks for the files that are open but have changed since last update event (host should get semanticDiag and syntaxDiag events for those files) Also i created new event: "projectChanged" where you can get the list of files to emit and changed files. The filesToEmit are the files on which you want to call compileOnSaveEmitFile and that would be sufficient to have the correct result. It also has this changedFiles, in case you prefer scheduling those diagnostic checks. Note that this event occurs when there is delay in the project structure update (eg. if the closed file/config file changes/there are changes applied to already open files) |
@sheetalkamat Thanks. So with this API, we'd only have to listen to |
@mjbvz Yes. You wont also have to watch any of the closed script infos or config file. Note that we still rely on editor providing reload/edits for the open script infos. |
@mjbvz should we close this or is it still something you are working on? |
Closing due to lack of activity. We can reopen if this is incorrect. |
Initial prototype enabling compileOnSave for TypeScript in VSCode
TODO:
compileOnSave
from project config file. Possibly could benefit from Expose ContextEvent in TS Server Protocol TypeScript#17659node_modules
files are sometimes included inaffectedFileList
@dbaeumer Can you please remind me what the main concerns were for enabling compileOnSave?
// cc @sheetalkamat