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

标签 typescript visual-studio-code vscode-extensions

我希望在 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但它们似乎都不是我正在寻找的。我想 these are the events that I need (projectLoadingStart and projectLoadingFinish), which tsserver emits internally ,但我不知道怎么听他们的。和 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 扩展中。这意味着它将被注入(inject)到 TypeScript 服务器的所有副本中。语言服务插件应该接收与 VS Code 中的主要扩展相同的所有事件 - 因此您可以衡量他们在该帖子中提到的方式。
它也应该是一个通用的有用工具,因此您可以考虑对其进行改进并在您从中得到一些使用时将其发布给公众。

关于typescript - 如何在 VSCode 扩展中检测 TypeScript 初始化时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67539071/

相关文章:

javascript - 在 typescript 中,返回 void 函数的函数的返回类型是什么?

mysql - 安全多公司协会

visual-studio-code - 如何在 Visual Studio 代码中使用 Autohotkey 热字符串?

visual-studio-code - 在 VSCode WebView 扩展中允许弹出窗口的解决方法

flutter - 如何在 Visual Studio Code 中录制屏幕?

javascript - vscode 扩展在函数外使用变量

html - 在 CSS 网格布局中使用 *ngFor 在一列中不希望显示所有内容

javascript - 如何在 Nest.js 中注入(inject)普通服务/提供者

flutter - 如何在 vscode 上输入时禁用提示

python - VS Code python 扩展最近开始提示 Win10 上的路径错误