[英]How can I automatically trigger the rename flow after extracting into a variable (LSP)?
I'm implementing IDE support for a language using Language Server Protocol.我正在使用语言服务器协议实现对一种语言的 IDE 支持。
I want to trigger a rename after extracting a variable into the current scope. That is, I've implemented steps 1 to 2 of the current flow and want to know how to implement 3 and 4我想在提取一个变量到当前scope后触发重命名。也就是说,我已经实现了当前流程的步骤1到2,想知道如何实现3和4
When the user selects an expression a yellow lightbulb shows up.当用户选择一个表达式时,会出现一个黄色灯泡。 Example: z = 3 + /*selection-start*/5000/*selection-end*/
示例: z = 3 + /*selection-start*/5000/*selection-end*/
When the user selects "extract into variable" then a new variable called "placeholder" is created in the current scope and the original expression is assigned to it.当用户选择“提取到变量”时,将在当前 scope 中创建一个名为“占位符”的新变量,并将原始表达式分配给它。 Example: placeholder = 5000; z = 3 + placeholder
示例: placeholder = 5000; z = 3 + placeholder
placeholder = 5000; z = 3 + placeholder
The first instance of placeholder
is highlighted and the text box for renaming pops up. placeholder
的第一个实例高亮显示,并弹出重命名文本框。 When the user types "the_new_name" and presses Return
then the text is: the_new_name = 5000; z = 3 + the_new_name
当用户键入“the_new_name”并按下Return
时,文本为: the_new_name = 5000; z = 3 + the_new_name
the_new_name = 5000; z = 3 + the_new_name
Is it possible to implement this flow with LSP?是否可以使用 LSP 实现此流程? If so, how?如果是这样,如何? I checked the LSP spec and it sounds like I'm looking for a Command
, but I didn't see a built-in Command
for renaming我检查了 LSP 规范,听起来我正在寻找一个Command
,但我没有看到用于重命名的内置Command
TypeScript's language server has the behavior I'm trying to replicate (implemented around here ), but TypeScript doesn't implement language server protocol, so peeking at its source didn't help me. TypeScript 的语言服务器具有我试图复制的行为(在这里实现),但是 TypeScript 没有实现语言服务器协议,所以查看它的源代码对我没有帮助。 The screenshots above are from the TypeScript plugin built into VSCode以上截图来自VSCode内置的TypeScript插件
It seems as if editors must call for this rename themselves.似乎编辑们必须要求自己重新命名。 Servers can send a list of edits as a result of a code action request, however they cannot request input from the user at this time: https://github.com/microsoft/language-server-protocol/issues/1641服务器可以根据代码操作请求发送编辑列表,但是此时它们无法请求用户输入: https://github.com/microsoft/language-server-protocol/issues/1641
LSP does not support this flow, but it can be done with a custom command. LSP 不支持此流程,但可以使用自定义命令完成。 Here's one technique:这是一种技术:
WorkspaceEdit
s, like "${0: placeholder}".在WorkspaceEdit
中包含片段文本,例如“${0: placeholder}”。 Snippet syntax is documented here .片段语法在此处记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.