Nvim :help 页面,从 生成 于 源代码, 使用 tree-sitter-vimdoc 解析器。
vim.lsp 用于构建增强的 LSP 工具。-- Create an event handler for the FileType autocommand
vim.api.nvim_create_autocmd('FileType', {
-- This handler will fire when the buffer's 'filetype' is "python"
pattern = 'python',
callback = function(args)
vim.lsp.start({
name = 'my-server-name',
cmd = {'name-of-language-server-executable', '--option', 'arg1', 'arg2'},
-- Set the "root directory" to the parent directory of the file in the
-- current buffer (`args.buf`) that contains either a "setup.py" or a
-- "pyproject.toml" file. Files that share a root directory will reuse
-- the connection to the same LSP server.
root_dir = vim.fs.root(args.buf, {'setup.py', 'pyproject.toml'}),
})
end,
})
:checkhealth lsp4. (可选)配置按键映射和自动命令来使用 LSP 功能。 lsp-configCTRL-S 在 Insert 模式下被映射到 vim.lsp.buf.signature_help()vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
-- Unset 'formatexpr'
vim.bo[args.buf].formatexpr = nil
-- Unset 'omnifunc'
vim.bo[args.buf].omnifunc = nil
-- Unmap K
vim.keymap.del('n', 'K', { buffer = args.buf })
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.supports_method('textDocument/implementation') then
-- Create a keymap for vim.lsp.buf.implementation
end
if client.supports_method('textDocument/completion') then
-- Enable auto-completion
vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true})
end
if client.supports_method('textDocument/formatting') then
-- Format the current buffer on save
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = args.buf,
callback = function()
vim.lsp.buf.format({bufnr = args.buf, id = client.id})
end,
})
end
end,
})
:lua =vim.lsp.get_clients()[1].server_capabilities默认提供的全部功能列表可以在 lsp-buf 中找到。:lua vim.lsp.stop_client(vim.lsp.get_clients())
:edit:verbose set omnifunc?async 参数,并将其值设置为 false。例如代码格式化" Auto-format *.rs (rust) files prior to saving them
" (async = false is the default for format)
autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
vim.lsp.buf_… 函数对附加到给定缓冲区的所有 LSP 客户端执行操作。 lsp-buf:lua vim.print(vim.tbl_keys(vim.lsp.handlers))
'callHierarchy/incomingCalls'
'callHierarchy/outgoingCalls'
'textDocument/codeAction'
'textDocument/completion'
'textDocument/declaration'
'textDocument/definition'
'textDocument/diagnostic'
'textDocument/documentHighlight'
'textDocument/documentSymbol'
'textDocument/formatting'
'textDocument/hover'
'textDocument/implementation'
'textDocument/inlayHint'
'textDocument/prepareTypeHierarchy'
'textDocument/publishDiagnostics'
'textDocument/rangeFormatting'
'textDocument/rangesFormatting'
'textDocument/references'
'textDocument/rename'
'textDocument/semanticTokens/full'
'textDocument/semanticTokens/full/delta'
'textDocument/signatureHelp'
'textDocument/typeDefinition*'
'typeHierarchy/subtypes'
'typeHierarchy/supertypes'
'window/logMessage'
'window/showMessage'
'window/showDocument'
'window/showMessageRequest'
'workspace/applyEdit'
'workspace/configuration'
'workspace/executeCommand'
'workspace/inlayHint/refresh'
'workspace/symbol'
'workspace/workspaceFolders'
function(err, result, ctx)
{err} (table|nil) 错误信息字典,或如果请求完成则为 nil。{ctx} (table) 与处理程序关联的调用状态表,包含以下键{bufnr} (Buffer) 缓冲区句柄。{params} (table|nil) 请求参数表。result, err,其中 err 形状类似于 RPC 错误{ code, message, data? }
vim.lsp.handlers 是一个全局表,它包含 lsp-method 名称到 lsp-handlers 的默认映射。vim.lsp.handlers['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler
vim.lsp.start {
..., -- Other configuration omitted.
handlers = {
['textDocument/publishDiagnostics'] = my_custom_server_definition
},
}
vim.lsp.buf_request_all(
0,
'textDocument/publishDiagnostics',
my_request_params,
my_handler
)
vim.lsp.protocol 定义了 LSP 规范规定的常量,以及用于创建与协议相关的对象的辅助函数。 https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.mdvim.lsp.protocol.ErrorCodes 允许通过编号或名称进行反向查找vim.lsp.protocol.TextDocumentSyncKind.Full == 1
vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
type,例如“function”或“variable”,以及 0 个或多个 modifier,例如“readonly”或“deprecated”。 标准类型和修饰符在此处描述: https://msdocs.cn/language-server-protocol/specification/#textDocument_semanticTokens LSP 服务器也可以使用非规范类型和修饰符。@lsp.type.<type>.<ft> 用于类型@lsp.mod.<mod>.<ft> 用于每个修饰符@lsp.typemod.<type>.<mod>.<ft> 用于每个修饰符 使用 :Inspect 查看特定令牌的高亮。 使用 :hi 或 nvim_set_hl() 更改语义高亮的外观hi @lsp.type.function guifg=Yellow " function names are yellow
hi @lsp.type.variable.lua guifg=Green " variables in lua are green
hi @lsp.mod.deprecated gui=strikethrough " deprecated is crossed out
hi @lsp.typemod.function.async guifg=Blue " async functions are blue
.semantic_tokens 是 @lsp.type.* 高亮的优先级。 @lsp.mod.* 和 @lsp.typemod.* 高亮分别具有高 1 和 2 的优先级。-- Hide semantic highlights for functions
vim.api.nvim_set_hl(0, '@lsp.type.function', {})
-- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end
vim.api.nvim_create_autocmd('LspDetach', {
callback = function(args)
-- Get the detaching client
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- Remove the autocommand to format the buffer on save, if it exists
if client.supports_method('textDocument/formatting') then
vim.api.nvim_clear_autocmds({
event = 'BufWritePre',
buffer = args.buf,
})
end
end,
})
vim.api.nvim_create_autocmd('LspNotify', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local method = args.data.method
local params = args.data.params
-- do something with the notification
if method == 'textDocument/...' then
update_buffer(bufnr)
end
end,
})
progress 环形缓冲区轮询通知,或者使用 vim.lsp.status() 获取汇总消息。pattern 设置为 kind(begin、report 或 end 之一)。client_id 和 params 属性的 data 表。 params 将包含服务器发送的请求参数(请参阅 lsp.ProgressParams)。autocmd LspProgress * redrawstatus
pending、complete 或 cancel 之一,并作为传递给回调函数的“data”表上的 {type} 发送。{type} == pending),以及 LSP 服务器响应时触发 ({type} == complete)。 如果使用 client.cancel_request(request_id) 请求取消,则此事件将触发,其中 {type} == cancel。{requests} 以了解有关 {request} 值的详细信息。 如果请求类型是 complete,则请求将在调用事件的回调后立即从客户端的挂起请求表中删除。 例如vim.api.nvim_create_autocmd('LspRequest', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local request_id = args.data.request_id
local request = args.data.request
if request.type == 'pending' then
-- do something with pending requests
track_pending(client_id, bufnr, request_id, request)
elseif request.type == 'cancel' then
-- do something with pending cancel requests
track_canceling(client_id, bufnr, request_id, request)
elseif request.type == 'complete' then
-- do something with finished requests. this pending
-- request entry is about to be removed since it is complete
track_finish(client_id, bufnr, request_id, request)
end
end,
})
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token
if token.type == 'variable' and not token.modifiers.readonly then
vim.lsp.semantic_tokens.highlight_token(
token, args.buf, args.data.client_id, 'MyMutableVariableHighlight'
)
end
end,
})
{bufnr}, {client_id}) vim.lsp.buf_attach_client()textDocument/did… 通知,这些通知对于跟踪任何语言服务器的缓冲区是必需的。{bufnr} (integer) 缓冲区句柄,或当前缓冲区的 0{client_id} (integer) 客户端 IDboolean) 成功 如果客户端成功附加,则为 true; 否则为 false{bufnr}, {client_id}) vim.lsp.buf_detach_client(){bufnr} (integer) 缓冲区句柄,或当前缓冲区的 0{client_id} (integer) 客户端 ID{bufnr} (integer) 缓冲区句柄,或当前缓冲区的 0{client_id} (integer) 客户端 ID{bufnr} (integer?) 缓冲区的编号{method} (string) 请求方法的名称{params} (any) 要发送到服务器的参数boolean) 成功 如果任何客户端返回 true,则为 true; 否则为 false{bufnr}, {method}, {params}, {handler}) 向附加到缓冲区的每个活动客户端发送异步请求,并使用组合结果执行 handler 回调。{bufnr} (integer) 缓冲区句柄,或当前缓冲区的 0。{method} (string) LSP 方法名称{params} (table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?) 要发送到服务器的参数。 也可以作为返回参数表的函数传递,用于参数特定于客户端的情况。{handler} (function) 所有请求完成后调用的处理程序。 服务器结果作为 client_id:result 映射传递。function) 取消 取消所有请求的函数。{bufnr}, {method}, {params}, {timeout_ms}) 向所有服务器发送请求,并等待所有服务器的响应。{timeout_ms}。{bufnr} (integer) 缓冲区句柄,或当前缓冲区的 0。{method} (string) LSP 方法名称{params} (table?) 要发送到服务器的参数{timeout_ms} (integer?, 默认值:1000) 最多等待结果的毫秒数。table<integer, {error: lsp.ResponseError?, result: any}>?) 结果 client_id:request_result 的映射。 (string?) err 在超时、取消或错误时,err 是一个描述失败原因的字符串,result 为 nil。{client_id} (integer)boolean) 已停止 如果客户端已停止,则为 true; 否则为 false。workspace/executeCommand 执行。Command: 命令标题:字符串 命令:字符串 参数?:any[]ctxvim.lsp.start({
name = 'my-server-name',
cmd = {'name-of-language-server-executable'},
root_dir = vim.fs.root(0, {'pyproject.toml', 'setup.py'}),
})
vim.lsp.stop_client(vim.lsp.get_clients())
{stop} (fun(force?: boolean)) 停止一个客户端,可以选择是否强制停止。默认情况下,它只会要求服务器关闭,不会强制关闭。如果你请求停止一个之前已经收到关闭请求的客户端,它会自动升级并强制关闭。{on_attach} (fun(bufnr: integer)) 如果客户端的配置中定义了 on_attach 函数,则运行该函数。这对于缓冲区本地设置很有用。{supports_method} (fun(method: string, opts?: {bufnr: integer?}): boolean) 检查客户端是否支持给定的方法。对于未知的非规范方法始终返回 true。{opts} 是一个可选的 {bufnr?: integer} 表格。一些语言服务器功能可能是特定于文件的。{is_stopped} (fun(): boolean) 检查客户端是否已停止。返回:如果客户端已完全停止则为 true。{exec_cmd} (fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)) 执行一个 lsp 命令,可以通过客户端命令函数(如果可用)或通过 workspace/executeCommand(如果服务器支持)执行{pending} (table<lsp.ProgressToken,lsp.LSPAny>){cmd} (string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient) 启动语言服务器的命令字符串数组(在 jobstart() 中的处理方式相同,必须是绝对路径或在 $PATH 中,shell 构造(如“~”)不会扩展),或者用于创建 RPC 客户端的函数。函数接收一个 dispatchers 表格,并返回一个具有成员函数 request、notify、is_closing 和 terminate 的表格。请参阅 vim.lsp.rpc.request()、vim.lsp.rpc.notify()。对于 TCP,有一个内置的 RPC 客户端工厂:vim.lsp.rpc.connect(){cmd_cwd} (string, 默认:cwd) 启动 cmd 进程的目录。与 root_dir 无关。{cmd_env} (table) 传递给 LSP 进程启动时的环境标志。必须使用表格指定。非字符串值将被强制转换为字符串。示例{ PORT = 8080; HOST = "0.0.0.0"; }
{detached} (boolean, 默认:true) 将服务器进程守护化,使其在与 Nvim 分开的进程组中运行。Nvim 将在退出时关闭进程,但是如果 Nvim 无法干净地退出,这可能会留下孤立的服务器进程。{workspace_folders} (lsp.WorkspaceFolder[]) 传递给语言服务器的工作区文件夹列表。为了向后兼容,rootUri 和 rootPath 将从此列表中的第一个工作区文件夹派生。请参阅 LSP 规范中的 workspaceFolders。{capabilities} (lsp.ClientCapabilities) 覆盖由 vim.lsp.protocol.make_client_capabilities() 定义的默认功能的映射,在初始化时传递给语言服务器。提示:使用 make_client_capabilities() 并修改其结果。{commands} (table<string,fun(command: lsp.Command, ctx: table)>) 将客户端命令的字符串映射到用户定义函数的表格。传递给 start_client 的命令优先于全局命令注册表。每个键必须是唯一的命令名称,值是一个函数,如果任何 LSP 操作(代码操作、代码透镜等)触发该命令,则调用该函数。{init_options} (table) 在初始化请求中作为 initializationOptions 传递的值。请参阅 LSP 规范中的 initialize。{name} (string, 默认:client-id) 日志消息中的名称。{get_language_id} (fun(bufnr: integer, filetype: string): string) 语言 ID 作为字符串。默认值为文件类型。{offset_encoding} ('utf-8'|'utf-16'|'utf-32') LSP 服务器期望的编码。客户端不会验证其是否正确。{on_error} (fun(code: integer, err: string)) 当客户端操作抛出错误时调用的回调。code 是一个描述错误的数字。其他参数可能会根据错误类型传递。请参阅 vim.lsp.rpc.client_errors 以获取可能的错误。使用 vim.lsp.rpc.client_errors[code] 获取人类友好的名称。{before_init} (fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)) 在 LSP“初始化”阶段之前调用的回调,其中 params 包含发送到服务器的参数,config 是传递给 vim.lsp.start_client() 的配置。你可以使用它在发送参数之前修改参数。{on_init} (elem_or_list<fun(client: vim.lsp.Client, initialize_result: lsp.InitializeResult)>) 在 LSP“初始化”之后调用的回调,其中 result 是一个包含 capabilities 和服务器可能发送的任何其他内容的表格。例如,clangd 会发送 initialize_result.offsetEncoding(如果向其发送了 capabilities.offsetEncoding)。你只能在此处修改 client.offset_encoding,然后才能发送任何通知。{on_exit} (elem_or_list<fun(code: integer, signal: integer, client_id: integer)>) 在客户端退出时调用的回调。{on_attach} (elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>) 当客户端附加到缓冲区时调用的回调。{trace} ('off'|'messages'|'verbose', 默认: "off") 直接传递到初始化请求中的语言服务器。无效/空值将{root_dir} (string) 语言服务器将根据其在初始化时确定 workspaceFolders、rootUri 和 rootPath 的目录。{command}, {context}, {handler}) Client:exec_cmd(){command} (lsp.Command){context} ({bufnr?: integer}?){handler} (lsp.Handler?) 仅在服务器命令时调用{on_list} (fun(t: vim.lsp.LocationOpts.OnList)) 替换默认处理程序的列表处理程序。对于任何非空结果都会调用。此表格可与 setqflist() 或 setloclist() 一起使用。例如local function on_list(options)
vim.fn.setqflist({}, ' ', options)
vim.cmd.cfirst()
end
vim.lsp.buf.definition({ on_list = on_list })
vim.lsp.buf.references(nil, { on_list = on_list })
vim.lsp.buf.definition({ loclist = true })
vim.lsp.buf.references(nil, { loclist = true })
{loclist} (boolean){reuse_win} (boolean) 如果缓冲区已经打开,则跳转到现有窗口。{title} (string) 列表的标题。{silent} (boolean){silent} (boolean){workspace_folder}) 将路径处的文件夹添加到工作区文件夹。如果未提供 {path},则将使用 input() 提示用户输入路径。{workspace_folder} (string?){context} (lsp.CodeActionContext) 对应于 LSP 规范中的 CodeActionContext{diagnostics} (table) LSP Diagnostic[]。如果没有提供,则从当前位置推断。{only} (table) 用于过滤代码操作的 LSP CodeActionKind 列表。大多数语言服务器支持诸如 refactor 或 quickfix 之类的值。{triggerKind} (integer) 请求代码操作的原因。{filter} (fun(x: lsp.CodeAction|lsp.Command):boolean) 接受 CodeAction 并返回布尔值的谓词。{apply} (boolean) 当设置为 true 且只有一个剩余操作(在过滤后)时,该操作将在没有用户查询的情况下应用。{range} ({start: integer[], end: integer[]}) 请求代码操作的范围。如果处于可视模式,则默认为活动选择。表格必须包含具有 {row,col} 元组的 start 和 end 键,使用标记式索引。请参阅 api-indexingCursorHold)触发,例如autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
{formatting_options} (table) 可用于指定 FormattingOptions。某些未指定的选项将自动从当前 Nvim 选项派生。请参阅 https://msdocs.cn/language-server-protocol/specification/#formattingOptions{timeout_ms} (integer, 默认: 1000) 以毫秒为单位的格式化请求阻塞时间。如果 async=true,则无效。{bufnr} (integer, 默认:当前缓冲区) 将格式化限制为附加到给定缓冲区的客户端。{filter} (fun(client: vim.lsp.Client): boolean?) 用于过滤客户端的谓词。接收客户端作为参数,必须返回布尔值。与谓词匹配的客户端将被包括在内。示例-- Never request typescript-language-server for formatting
vim.lsp.buf.format {
filter = function(client) return client.name ~= "tsserver" end
}
{async} (boolean, 默认:false) 如果为 true,则该方法不会阻塞。在异步格式化时编辑缓冲区会导致意外更改。{id} (integer) 将格式化限制为与该字段匹配的 ID (client.id) 的客户端。{name} (string) 将格式化限制为与该字段匹配的名称 (client.name) 的客户端。{range} ({start:[integer,integer],end:[integer, integer]}|{start:[integer,integer],end:[integer,integer]}[], 默认:可视模式下的当前选择,其他模式下为 nil,格式化整个缓冲区) 要格式化的范围。表格必须包含 start 和 end 键,其中 {row,col} 元组使用 (1,0) 索引。也可以是包含 start 和 end 键的表格列表,如上所述,在这种情况下,需要 textDocument/rangesFormatting 支持。{config}) vim.lsp.buf.hover(){workspace_folder}) 从工作区文件夹中删除路径处的文件夹。如果未提供 {path},将使用 input() 提示用户输入路径。{workspace_folder} (string?){opts} (table?) 额外的选项{filter} (fun(client: vim.lsp.Client): boolean?) 用于过滤客户端的谓词。接收一个客户端作为参数,必须返回一个布尔值。与谓词匹配的客户端将被包含。{name} (string) 将用于重命名的客户端限制为 client.name 与该字段匹配的客户端。{bufnr} (integer) (默认:当前缓冲区){kind}) vim.lsp.buf.typehierarchy(){kind} ("subtypes"|"supertypes"){query} 过滤;如果从调用中省略了参数,则会提示用户在命令行中输入字符串。空字符串表示不进行过滤。{diagnostics} (vim.Diagnostic[])lsp.Diagnostic[]){client_id}, {is_pull}) 获取与 LSP 客户端 vim.diagnostic 关联的诊断命名空间,用于诊断{client_id} (integer) LSP 客户端的 ID{is_pull} (boolean?) 命名空间是用于拉取还是推送客户端。默认为推送{_}, {result}, {ctx}) 方法 "textDocument/diagnostic" 的 lsp-handler{result} (lsp.DocumentDiagnosticReport){ctx} (lsp.HandlerContext){_}, {result}, {ctx}) 方法 "textDocument/publishDiagnostics" 的 lsp-handler{result} (lsp.PublishDiagnosticsParams){ctx} (lsp.HandlerContext){client_id} (integer?) 按 client_id 过滤。如果为 nil,则为所有客户端{bufnr} (integer?) 按缓冲区过滤。如果为 nil,则为所有缓冲区,如果为 0,则为当前缓冲区{lenses} (lsp.CodeLens[]?) 要显示的透镜{bufnr} (integer){client_id} (integer){bufnr} (integer) 缓冲区号。0 可以用于当前缓冲区。lsp.CodeLens[]){err}, {result}, {ctx}) vim.lsp.codelens.on_codelens()textDocument/codeLens 的 lsp-handler{err} (lsp.ResponseError?){result} (lsp.CodeLens[]){ctx} (lsp.HandlerContext)autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh({ bufnr = 0 })
{opts} (table?) 可选字段{bufnr} (integer?) 按缓冲区过滤。如果为 nil,则为所有缓冲区,如果为 0,则为当前缓冲区{lenses} (lsp.CodeLens[]?) 要存储的透镜{bufnr} (integer){client_id} (integer){autotrigger} (boolean) 默认:false 当为真时,完成将根据服务器的 triggerCharacters 自动触发。{enable} (boolean) 为真则启用,为假则禁用{client_id} (integer) 客户端 ID{bufnr} (integer) 缓冲区句柄,或 0 表示当前缓冲区is_enabled() 的反值。vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
{enable} (boolean?) true/nil 表示启用,false 表示禁用{bufnr} (integer?) 缓冲区号,或 0 表示当前缓冲区,或 nil 表示所有。local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer
local client = vim.lsp.get_client_by_id(hint.client_id)
local resp = client.request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0)
local resolved_hint = assert(resp and resp.result, resp.err)
vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding)
location = resolved_hint.label[1].location
client.request('textDocument/hover', {
textDocument = { uri = location.uri },
position = location.range.start,
})
table[]) 包含以下字段的对象列表{bufnr} (integer){client_id} (integer){inlay_hint} (lsp.InlayHint)boolean){bufnr} (integer?) 按缓冲区过滤。如果为 nil,则为所有缓冲区,如果为 0,则为当前缓冲区{bufnr}, {row}, {col}) 返回给定位置的语义令牌。如果在没有参数的情况下调用,则返回光标下的令牌。{bufnr} (integer?) 缓冲区号(0 表示当前缓冲区,默认){row} (integer?) 位置行(默认光标位置){col} (integer?) 位置列(默认光标位置)table?) 位置处的令牌列表。每个令牌都具有以下字段{token}, {bufnr}, {client_id}, {hl_group}, {opts}) 突出显示语义令牌。{bufnr} (integer) 要突出显示的缓冲区,或 0 表示当前缓冲区{hl_group} (string) 突出显示组名称{opts} (table?) 可选参数{priority} (integer, 默认值:vim.hl.priorities.semantic_tokens + 3) 应用的 extmark 的优先级。{bufnr}, {client_id}, {opts}) vim.lsp.semantic_tokens.start()on_attach 回调中从 {server_capabilities} 中删除 semanticTokensProvider 表。client.server_capabilities.semanticTokensProvider = nil
{bufnr} (integer) 缓冲区编号,或 0 表示当前缓冲区start() 的一部分中设置的,因此您只需要此函数来手动断开语义标记引擎,而无需完全将 LSP 客户端从缓冲区分离。{height} (integer) 浮动窗口的高度{width} (integer) 浮动窗口的宽度{wrap} (boolean, 默认值:true) 换行长行{wrap_at} (integer) 在启用换行时,计算高度时要换行的字符{max_width} (integer) 浮动窗口的最大宽度{max_height} (integer) 浮动窗口的最大高度{focus_id} (string) 如果打开具有此 ID 的弹出窗口,则将其聚焦{close_events} (table) 关闭浮动窗口的事件列表{focusable} (boolean, 默认值:true) 使浮动窗口可聚焦。{focus} (boolean, 默认值:true) 如果为 true,并且如果 {focusable} 也为 true,则聚焦具有相同 {focus_id} 的现有浮动窗口{offset_x} (integer) 要添加到 col 的偏移量{offset_y} (integer) 要添加到 row 的偏移量{border} (string|(string|[string,string])[]) 覆盖 border{zindex} (integer) 覆盖 zindex,默认为 50{title} (string){title_pos} ('left'|'center'|'right'){relative} ('mouse'|'cursor') (默认值:'cursor'){anchor_bias} ('auto'|'above'|'below', 默认值:'auto') - "auto": 根据光标哪一侧有更多行来放置窗口{text_document_edit}, {index}, {offset_encoding}) 应用 TextDocumentEdit,它是一系列对单个文档的更改。{text_document_edit} (lsp.TextDocumentEdit){index} (integer?) 编辑的可选索引,如果来自编辑列表(或者为 nil,如果不在列表中){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?){text_edits}, {bufnr}, {offset_encoding}) 将一系列文本编辑应用于缓冲区。{text_edits} (lsp.TextEdit[]){bufnr} (integer) 缓冲区 ID{offset_encoding} ('utf-8'|'utf-16'|'utf-32'){workspace_edit}, {offset_encoding}) 应用 WorkspaceEdit。{workspace_edit} (lsp.WorkspaceEdit){offset_encoding} ('utf-8'|'utf-16'|'utf-32') (必需){bufnr} (integer?) 缓冲区 ID{bufnr}, {references}, {offset_encoding}) 显示特定缓冲区的文档突出显示列表。{bufnr} (integer) 缓冲区 ID{references} (lsp.DocumentHighlight[]) 要突出显示的对象{offset_encoding} ('utf-8'|'utf-16'|'utf-32'){buf}, {row}, {col}, {offset_encoding}) 返回特定缓冲区中位置的 UTF-32 和 UTF-16 偏移量。{buf} (integer) 缓冲区编号(0 表示当前){row} (integer) 0 索引行{col} (integer) 行中 0 索引的字节偏移量{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) 默认为 buf 的第一个客户端的 offset_encodinginteger) offset_encoding 索引,表示缓冲区 {buf} 中行 {row} 列 {col} 中的字符{input}, {contents}) 将 MarkedString | MarkedString[] | MarkupContent 中的任何内容转换为包含有效 markdown 的行列表。对于填充 textDocument/hover 的悬停窗口、解析 textDocument/signatureHelp 的结果以及可能的其他内容很有用。MarkupContent 类型并且其 kind 为 plaintext,则返回相应的值,不会进行进一步修改。{input} (lsp.MarkedString|lsp.MarkedString[]|lsp.MarkupContent){contents} (string[]?) 要使用转换后的行扩展的字符串列表。默认为 {}。string[]) 使用转换后的 markdown 行进行扩展。{signature_help}, {ft}, {triggers}) 将 textDocument/signatureHelp 响应转换为 markdown 行。{signature_help} (lsp.SignatureHelp) textDocument/SignatureHelp 的响应{ft} (string?) 将用作标签 markdown 代码块的 lang 的文件类型{triggers} (string[]?) 来自 lsp 服务器的触发字符列表。用于更好地确定参数偏移量string[]?) 转换后的 markdown 行。 (Range4?) 活动参数的突出显示范围{bufnr} (integer?) 缓冲区句柄,默认为当前缓冲区integer) 缩进大小{locations}, {offset_encoding}) 返回具有正确计算的字节位置且按排序顺序排列的项,以便在快速修复和位置列表中显示。user_data 字段将包含它计算所基于的原始 Location 或 LocationLink。{locations} (lsp.Location[]|lsp.LocationLink[]){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) 默认为缓冲区的第一个客户端{width}, {height}, {opts}) 创建一个包含浮动窗口的合理默认选项的表。该表可以传递给 nvim_open_win().{width} (integer) 窗口宽度(以字符单元格为单位){height} (integer) 窗口高度(以字符单元格为单位)table) 选项{options}) 为当前缓冲区和光标位置创建 DocumentFormattingParams 对象。{options} (lsp.FormattingOptions?) 包含有效的 FormattingOptions 条目lsp.DocumentFormattingParams) 对象{start_pos}, {end_pos}, {bufnr}, {offset_encoding}) 使用当前缓冲区中的给定范围,创建一个类似于 vim.lsp.util.make_range_params() 的对象。{start_pos} ([integer,integer]?) {row,col} 标记索引位置。默认为最后一个视觉选择的开头。{end_pos} ([integer,integer]?) {row,col} 标记索引位置。默认为最后一个视觉选择的结尾。{bufnr} (integer?) 缓冲区句柄或 0 表示当前缓冲区,默认为当前缓冲区{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) 默认为 bufnr 的第一个客户端的 offset_encodingtable) { textDocument = { uri = current_file_uri }, range = { start = start_position, end = end_position } }{window}, {offset_encoding}) 为当前缓冲区和光标位置创建 TextDocumentPositionParams 对象。{window} (integer?) 窗口句柄或 0 表示当前窗口,默认为当前窗口{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) 默认为 window 的缓冲区的第一个客户端的 offset_encodinglsp.TextDocumentPositionParams){window}, {offset_encoding}) 使用当前缓冲区中的当前位置,创建一个可以作为构建块用于多个 LSP 请求的对象,例如 textDocument/codeAction、textDocument/colorPresentation、textDocument/rangeFormatting。{window} (integer?) 窗口句柄或 0 表示当前窗口,默认为当前窗口{offset_encoding} ("utf-8"|"utf-16"|"utf-32"?) 默认为 window 的缓冲区的第一个客户端的 offset_encodingtable) { textDocument = { uri = current_file_uri }, range = { start = current_position, end = current_position } }{bufnr}) 为当前缓冲区创建一个 TextDocumentIdentifier 对象。{bufnr} (integer?) 缓冲区句柄,默认为当前缓冲区lsp.TextDocumentIdentifier){added} (lsp.WorkspaceFolder[]){removed} (lsp.WorkspaceFolder[])lsp.WorkspaceFoldersChangeEvent){contents} (table) 要在窗口中显示的行{syntax} (string) 为打开的缓冲区设置的语法{opts} (vim.lsp.util.open_floating_preview.Opts?) 带有可选字段(额外的键将在传递给 nvim_open_win() 之前使用 vim.lsp.util.make_floating_popup_options() 进行过滤)。参见 vim.lsp.util.open_floating_preview.Opts。integer) 新创建的浮动窗口的 bufnr (integer) 新创建的浮动窗口预览窗口的 winid{location} (lsp.Location|lsp.LocationLink)integer?) 浮动窗口的缓冲区 ID (integer?) 浮动窗口的窗口 IDopts 请求覆盖;或者{old_fname} (string){new_fname} (string){opts} (table?) 选项{overwrite} (boolean){ignoreIfExists} (boolean){location} (lsp.Location|lsp.LocationLink){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?){reuse_win} (boolean) 如果缓冲区已经打开,则跳转到现有窗口。{focus} (boolean) 是否在可能的情况下将焦点/跳转到位置。 (默认:true)boolean) true 如果成功{bufnr}, {contents}, {opts}) 通过剥离代码块并将它们转换为突出显示的代码,将 Markdown 转换为语法突出显示的区域。 默认情况下,这将在这些代码块区域之后插入一个空行分隔符以提高可读性。open_floating_preview。{bufnr} (integer){contents} (string[]) 要在窗口中显示的行{opts} (table?) 带有可选字段table) 剥离的内容{symbols} (lsp.DocumentSymbol[]|lsp.SymbolInformation[]){bufnr} (integer?)string) 日志文件名integer) 当前日志级别{handle} (function) 要应用于日志记录参数的函数,传递 vim.inspect 以进行多行格式化{level} (string|integer) vim.lsp.log.levels 中的一个{level} (integer) 日志级别bool) 如果会记录,则为 true,否则为 false{request} (fun(method: string, params: table?, callback: fun(err: lsp.ResponseError?, result: any), notify_reply_callback: fun(message_id: integer)?):boolean,integer?) 参见 vim.lsp.rpc.request(){is_closing} (fun(): boolean){terminate} (fun()){host_or_path}, {port}) vim.lsp.rpc.connect(){host_or_path} (string) 要连接到的主机或管道/域套接字的路径{port} (integer?) 要连接到的 TCP 端口。 如果不存在,第一个参数必须是管道fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient){err} (table) 错误对象string) error_message 格式化的错误消息{method} (string) 调用的 LSP 方法{params} (table?) 调用 LSP 方法的参数boolean) true 如果通知可以发送,false 如果不能{method}, {params}, {callback}, {notify_reply_callback}) 向 LSP 服务器发送请求,并在响应时运行 {callback}。{method} (string) 调用的 LSP 方法{params} (table?) 调用 LSP 方法的参数{callback} (fun(err: lsp.ResponseError?, result: any)) 要调用的回调{notify_reply_callback} (fun(message_id: integer)?) 在请求不再挂起时要调用的回调boolean) success true 如果请求可以发送,false 如果不能 (integer?) 如果请求可以发送,则为 message_id,否则为 nil{code}, {message}, {data}) 创建一个 RPC 响应表 error,以便将其发送到 LSP 响应。{code} (integer) 定义的 RPC 错误代码,参见 vim.lsp.protocol.ErrorCodes{message} (string?) 要发送到服务器的任意消息{data} (any?) 要发送到服务器的任意数据lsp.ResponseError)vim.lsp.protocol.ErrorCodes{cmd}, {dispatchers}, {extra_spawn_params}) vim.lsp.rpc.start() 启动一个 LSP 服务器进程,并创建一个 LSP RPC 客户端对象来与它交互。 与生成的进程的通信通过 stdio 进行。 对于通过 TCP 进行的通信,请手动生成一个进程并使用 vim.lsp.rpc.connect(){cmd} (string[]) 启动 LSP 服务器的命令。{dispatchers} (table?) 用于 LSP 消息类型的调度程序。{notification} (fun(method: string, params: table)){server_request} (fun(method: string, params: table): any?, lsp.ResponseError?){on_exit} (fun(code: integer, signal: integer)){on_error} (fun(code: integer, err: any)){extra_spawn_params} (table?) LSP 服务器进程的额外上下文。{cwd} (string) LSP 服务器进程的工作目录{detached} (boolean) 将 LSP 服务器进程与当前进程分离vim.lsp.rpc.PublicClient) 客户端 RPC 对象,具有以下方法notify() vim.lsp.rpc.notify()request() vim.lsp.rpc.request()is_closing() 返回一个布尔值,指示 RPC 是否正在关闭。terminate() 终止 RPC 客户端。 参见 vim.lsp.rpc.PublicClient。lsp.ClientCapabilities){server_capabilities}) 创建一个规范化的对象,该对象描述了 LSP 服务器的功能。{server_capabilities} (table) 服务器支持的功能表lsp.ServerCapabilities?) 规范化的功能表