如何获取 neovim LSP 中的所有接口(或任何令牌)?

Tom*_*ski 5 lua neovim language-server-protocol

我试图从给定的缓冲区获取所有接口。为此,我想获取所有令牌并过滤掉除接口之外的所有内容。但是,当我尝试致电 LSP 时:我没有得到任何回复。

local bufnr = vim.api.nvim_get_current_buf()
local params = vim.lsp.util.make_text_document_params()
local result = vim.lsp.buf_request_sync(bufnr, "textDocument/documentSymbol", params, 2000)
print(vim.inspect(result))
Run Code Online (Sandbox Code Playgroud)

我得到的只是一张空地图。我显然错过了一些明显的东西,但我不知道是什么。

{
  [2] = {
    result = {}
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 1

您正在使用的语言服务器可能没有实现您正在寻找的方法。您可以尝试其他LSP并进行比较。请参阅 Neovim文档
中的注释,

lsp-method
方法是 LSP 规范定义的请求和通知的名称。这些 LSP 请求/通知是默认定义的:

callHierarchy/incomingCalls
callHierarchy/outgoingCalls
textDocument/codeAction
textDocument/completion
textDocument/declaration*
textDocument/definition
textDocument/documentHighlight
textDocument/documentSymbol
textDocument/formatting
textDocument/hover
textDocument/implementation*
textDocument/publishDiagnostics
textDocument/rangeFormatting
textDocument/references
textDocument/rename
textDocument/signatureHelp
textDocument/typeDefinition*
window/logMessage
window/showMessage
window/showDocument
window/showMessageRequest
workspace/applyEdit
workspace/symbol
Run Code Online (Sandbox Code Playgroud)

注意:这些有时不是由服务器实现的。

另外,请确保您的 LSP 配置正确,以防万一。