简体   繁体   English

如何在 VSCode 扩展中检测 TypeScript 初始化时间?

[英]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 .我希望在 VSCode 中检测 TypeScript 初始化性能,类似于本文中提到的 TypeTrack 扩展

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 的 TypeScript 语言功能扩展:

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.不幸的是, 它暴露的 API 非常少,它似乎唯一的东西就是onCompletionAccepted ,这对我来说并没有太大帮助。

I've looked through VSCode's API events but none of them seem to quite be what I'm looking for.我查看了VSCode 的 API 事件,但它们似乎都不是我想要的。 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.我认为这些是我需要的事件(projectLoadingStart 和 projectLoadingFinish),它们是 tsserver 在内部发出的,但我不知道如何收听它们。 And here I can see vscode.typescript-language-features using these events to update its loading indicator . 在这里我可以看到 vscode.typescript-language-features 使用这些事件来更新它的加载指示器

It seems like maybe this could be done with a TypeScript Language Service plugin ?似乎这可以通过TypeScript 语言服务插件来完成? Or maybe I need to make my own TypeScript service client?或者也许我需要制作自己的 TypeScript 服务客户端? 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 .假设您正在明确查找 TSServer 启动时间,而不是可以从 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.我认为最简单的方法是编写一个小型跟踪语言服务插件,将其嵌入到使用typescriptServerPlugins的 VS Code 扩展中,这意味着它将被注入到 TypeScript 服务器的所有副本中。 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.语言服务插件应该接收与 VS Code 中的主要扩展相同的所有事件 - 因此您可以衡量他们在该帖子中提到的方式。

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.它也应该是一个普遍有用的工具,所以如果你从中得到一些用处,你可以考虑对其进行改进并将其发布给公众。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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