LSP spec 中关于 inlay hints 请求的字段记录在这里。其中有一个字段是 textEdits
,spec 对于其的描述是(我摘抄出来):
Optional text edits that are performed when accepting this inlay hint.
*Note* that edits are expected to change the document so that the inlay hint (or its nearest variant) is now part of the document and the inlay hint itself is now obsolete.
Depending on the client capability `inlayHint.resolveSupport` clients might resolve this property late using the resolve request.
看到这里的时候,我对 accepting 的理解出了差错,我将其误解为这里的 textEdits
会在编辑器 received 到 inlay hints 的时候应用。
不是这样的。LSP spec 在这里也许是刻意模糊描述,这样的文本最终导致了各个编辑器对于 accept 的理解和实现各不相同。
在所有人都喜欢的编辑器 VSCode 中,accept 的行为默认是通过双击 inlay hints 来应用的;在同样是所有人都喜欢的编辑器
Neovim
中,这个行为还没有被定义和实现,不过按照
Neovim
一般用户的习惯,通过鼠标双击来应用的方式也许不是那么适用。
LSP 协议本来就不应该关心编辑器(客户端)如何发出请求到 LSP 服务器:从这个角度说得通。不论他们的默认行为是什么,编辑器总是有 api 来实际做这件事(检查
Neovim
的类似 api vim.lsp.codelens.run()
)。