[英]How to properly implement CodeLens in Visual Studio Code
I'm developing a extension for Visual Studio Code and need to display a CodeLens in the editor. 我正在开发Visual Studio Code扩展,需要在编辑器中显示CodeLens。
What is the best way to implement it? 实施它的最佳方法是什么?
Should I create a CodeLens with a command in provideCodeLenses
or update it in resolveCodeLens
? 我应该在创建一个命令CodeLens
provideCodeLenses
或更新resolveCodeLens
?
It depends on how complex your code lenses are to compute. 这取决于代码透镜的计算复杂度。
If the code lenses are very simple and can always be created in a fixed amount of time, you only need to implement provideCodeLens
. 如果代码镜头非常简单并且始终可以在固定的时间内创建,则只需实现
provideCodeLens
。
If creating the code lenses may involve intensive computation or any sort of non-deterministic behavior – such as network – then provideCodeLens
should only return skeleton Code Lenses with ranges. 如果创建代码镜头可能涉及大量计算或任何不确定性行为(例如网络),那么
provideCodeLens
应该仅返回具有范围的骨架代码镜头。 You would then complete the CodeLens' command
in resolveCodeLens
, which will only be called when the CodeLens actually needs to be displayed. 然后,您将在
resolveCodeLens
完成CodeLens的command
,仅在实际需要显示CodeLens时才调用该命令。
Overall, splitting your CodeLens implementation between provideCodeLenses
and resolveCodeLens
is the safest choice. 总体而言,分裂之间的CodeLens实现
provideCodeLenses
和resolveCodeLens
是最安全的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.