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

How to instrument TypeScript initialization time in a VSCode extension?

我希望在 VSCode 中检测 TypeScript 初始化性能,类似于 the TypeTrack extension mentioned in this blog post

不幸的是,我很难弄清楚如何订阅执行此检测所需的事件。

我试过的一件事是获取对 VSCode 的 TypeScript 语言功能扩展的引用:

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

不幸的是,the API it exposes is very minimal 似乎唯一的东西是 onCompletionAccepted,这对我在这里没有太大帮助。

我已浏览 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

这似乎可以用 TypeScript Language Service plugin 来完成?或者我可能需要制作自己的 TypeScript 服务客户端?我应该从哪里开始挖掘?

假设您要明确查找 TSServer 启动时间,而不是 general compiler perf which can be traced and measured from the CLI

我认为 最简单的 路线是编写一个小型跟踪语言服务插件,您可以将其嵌入到使用 typescriptServerPlugins 的 VS Code 扩展中,这意味着它将是注入到 TypeScript 服务器的所有副本中。语言服务插件应该接收与 VS Code 中的主要扩展相同的所有事件 - 因此您可以衡量他们在 post.

中提到的方式

它也应该是一个普遍有用的工具,因此您可以考虑对其进行完善,如果您对它有一些用处,可以将其发布到 public。