简体   繁体   中英

How to instrument TypeScript initialization time in a VSCode extension?

I am looking to instrument TypeScript initialization performance in VSCode, similar to the TypeTrack extension mentioned in this blog post .

Unfortunately, I'm having a hard time figuring out exactly how to subscribe to the events I need to do this instrumentation.

One thing I've tried is to get a reference to VSCode's TypeScript language features extension:

vscode.extensions.getExtension('vscode.typescript-language-features');

Unfortunately, the API it exposes is very minimal and the only thing it seems to have is onCompletionAccepted , which is not too helpful for me here.

I've looked through VSCode's API events but none of them seem to quite be what I'm looking for. I think these are the events that I need (projectLoadingStart and projectLoadingFinish), which tsserver emits internally , but I don't know how to listen to them. And here I can see vscode.typescript-language-features using these events to update its loading indicator .

It seems like maybe this could be done with a TypeScript Language Service plugin ? Or maybe I need to make my own TypeScript service client? Where should I start digging?

Assuming you're explicitly looking for the TSServer boot times, and not general compiler perf which can be traced and measured from the CLI .

I think the simplest route would to write a small tracing language service plugin with which you embed inside a VS Code extension which uses typescriptServerPlugins which means it will be injected into all copies of the TypeScript Server. The language service plugin should receive all the same events as the main extension in VS Code - so you can measure the way they mention in that post.

It should be a generically useful tool too, so you could consider polishing it up and putting it out to the public if you get some use from it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM