mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
feat(lsp): use stricter types for methods
This change modifies gen_lsp.lua so alias types are generated for various types of lsp methods to distinguish between notifications and requests: - vim.lsp.protocol.Method.ServerToClient.Request - vim.lsp.protocol.Method.ServerToClient.Notification - vim.lsp.protocol.Method.ClientToServer.Request - vim.lsp.protocol.Method.ClientToServer.Notification These types are then used instead of `string` where appropriate.
This commit is contained in:
committed by
Lewis Russell
parent
34b4df774d
commit
d7e0d46ffa
@ -656,7 +656,7 @@ end
|
||||
--- This is a thin wrapper around {client.rpc.request} with some additional
|
||||
--- checks for capabilities and handler availability.
|
||||
---
|
||||
--- @param method string LSP method name.
|
||||
--- @param method vim.lsp.protocol.Method.ClientToServer.Request LSP method name.
|
||||
--- @param params? table LSP request params.
|
||||
--- @param handler? lsp.Handler Response |lsp-handler| for this method.
|
||||
--- @param bufnr? integer (default: 0) Buffer handle, or 0 for current.
|
||||
@ -721,7 +721,7 @@ end
|
||||
---
|
||||
--- This is a wrapper around |Client:request()|
|
||||
---
|
||||
--- @param method string LSP method name.
|
||||
--- @param method vim.lsp.protocol.Method.ClientToServer.Request LSP method name.
|
||||
--- @param params table LSP request params.
|
||||
--- @param timeout_ms integer? Maximum time in milliseconds to wait for
|
||||
--- a result. Defaults to 1000
|
||||
@ -757,7 +757,7 @@ end
|
||||
|
||||
--- Sends a notification to an LSP server.
|
||||
---
|
||||
--- @param method string LSP method name.
|
||||
--- @param method vim.lsp.protocol.Method.ClientToServer.Notification LSP method name.
|
||||
--- @param params table? LSP request params.
|
||||
--- @return boolean status indicating if the notification was successful.
|
||||
--- If it is false, then the client has shutdown.
|
||||
@ -828,7 +828,7 @@ function Client:stop(force)
|
||||
end
|
||||
|
||||
--- Get options for a method that is registered dynamically.
|
||||
--- @param method string
|
||||
--- @param method vim.lsp.protocol.Method
|
||||
function Client:_supports_registration(method)
|
||||
local capability = vim.tbl_get(self.capabilities, unpack(vim.split(method, '/')))
|
||||
return type(capability) == 'table' and capability.dynamicRegistration
|
||||
@ -901,7 +901,7 @@ function Client:_get_language_id(bufnr)
|
||||
return self.get_language_id(bufnr, vim.bo[bufnr].filetype)
|
||||
end
|
||||
|
||||
--- @param method string
|
||||
--- @param method vim.lsp.protocol.Method
|
||||
--- @param bufnr? integer
|
||||
--- @return lsp.Registration?
|
||||
function Client:_get_registration(method, bufnr)
|
||||
@ -1051,7 +1051,7 @@ end
|
||||
--- Always returns true for unknown off-spec methods.
|
||||
---
|
||||
--- Note: Some language server capabilities can be file specific.
|
||||
--- @param method string
|
||||
--- @param method vim.lsp.protocol.Method.ClientToServer
|
||||
--- @param bufnr? integer
|
||||
function Client:supports_method(method, bufnr)
|
||||
-- Deprecated form
|
||||
@ -1082,27 +1082,11 @@ function Client:supports_method(method, bufnr)
|
||||
return false
|
||||
end
|
||||
|
||||
--- Get options for a method that is registered dynamically.
|
||||
--- @param method string
|
||||
--- @param bufnr? integer
|
||||
--- @return lsp.LSPAny?
|
||||
function Client:_get_registration_options(method, bufnr)
|
||||
if not self:_supports_registration(method) then
|
||||
return
|
||||
end
|
||||
|
||||
local reg = self:_get_registration(method, bufnr)
|
||||
|
||||
if reg then
|
||||
return reg.registerOptions
|
||||
end
|
||||
end
|
||||
|
||||
--- @private
|
||||
--- Handles a notification sent by an LSP server by invoking the
|
||||
--- corresponding handler.
|
||||
---
|
||||
--- @param method string LSP method name
|
||||
--- @param method vim.lsp.protocol.Method.ServerToClient.Notification LSP method name
|
||||
--- @param params table The parameters for that method.
|
||||
function Client:_notification(method, params)
|
||||
log.trace('notification', method, params)
|
||||
|
Reference in New Issue
Block a user