diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 67f1602f07..be6712ea62 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -3045,12 +3045,6 @@ make_client_capabilities() Return: ~ (`lsp.ClientCapabilities`) -Methods *vim.lsp.protocol.Methods* - LSP method names. - - See also: ~ - • https://microsoft.github.io/language-server-protocol/specification/#metaModel - *vim.lsp.protocol.resolve_capabilities()* resolve_capabilities({server_capabilities}) Creates a normalized object describing LSP server capabilities. diff --git a/runtime/doc/news-0.10.txt b/runtime/doc/news-0.10.txt index 7951bbeaaa..e666b1b5cb 100644 --- a/runtime/doc/news-0.10.txt +++ b/runtime/doc/news-0.10.txt @@ -228,7 +228,7 @@ The following new features were added. mappings are applied. • LSP: - • LSP method names are available in |vim.lsp.protocol.Methods|. + • LSP method names are available in `vim.lsp.protocol.Methods`. • Implemented LSP inlay hints: |lsp-inlay_hint| https://microsoft.github.io/language-server-protocol/specification/#textDocument_inlayHint • Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()| diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index f922bc8074..3165bf74e9 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -28,7 +28,6 @@ local lsp = vim._defer_require('vim.lsp', { local log = lsp.log local protocol = lsp.protocol -local ms = protocol.Methods local util = lsp.util local changetracking = lsp._changetracking @@ -37,10 +36,10 @@ local changetracking = lsp._changetracking lsp.rpc_response_error = lsp.rpc.rpc_response_error lsp._resolve_to_request = { - [ms.codeAction_resolve] = ms.textDocument_codeAction, - [ms.codeLens_resolve] = ms.textDocument_codeLens, - [ms.documentLink_resolve] = ms.textDocument_documentLink, - [ms.inlayHint_resolve] = ms.textDocument_inlayHint, + ['codeAction/resolve'] = 'textDocument/codeAction', + ['codeLens/resolve'] = 'textDocument/codeLens', + ['documentLink/resolve'] = 'textDocument/documentLink', + ['inlayHint/resolve'] = 'textDocument/inlayHint', } -- TODO improve handling of scratch buffers with LSP attached. @@ -764,17 +763,17 @@ end ---@param bufnr integer function lsp._set_defaults(client, bufnr) if - client:supports_method(ms.textDocument_definition) and is_empty_or_default(bufnr, 'tagfunc') + client:supports_method('textDocument/definition') and is_empty_or_default(bufnr, 'tagfunc') then vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc' end if - client:supports_method(ms.textDocument_completion) and is_empty_or_default(bufnr, 'omnifunc') + client:supports_method('textDocument/completion') and is_empty_or_default(bufnr, 'omnifunc') then vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc' end if - client:supports_method(ms.textDocument_rangeFormatting) + client:supports_method('textDocument/rangeFormatting') and is_empty_or_default(bufnr, 'formatprg') and is_empty_or_default(bufnr, 'formatexpr') then @@ -782,7 +781,7 @@ function lsp._set_defaults(client, bufnr) end vim._with({ buf = bufnr }, function() if - client:supports_method(ms.textDocument_hover) + client:supports_method('textDocument/hover') and is_empty_or_default(bufnr, 'keywordprg') and vim.fn.maparg('K', 'n', false, false) == '' then @@ -791,7 +790,7 @@ function lsp._set_defaults(client, bufnr) end, { buffer = bufnr, desc = 'vim.lsp.buf.hover()' }) end end) - if client:supports_method(ms.textDocument_diagnostic) then + if client:supports_method('textDocument/diagnostic') then lsp.diagnostic._enable(bufnr) end end @@ -818,12 +817,12 @@ local function text_document_did_save_handler(bufnr) local name = api.nvim_buf_get_name(bufnr) local old_name = changetracking._get_and_set_name(client, bufnr, name) if old_name and name ~= old_name then - client:notify(ms.textDocument_didClose, { + client:notify('textDocument/didClose', { textDocument = { uri = vim.uri_from_fname(old_name), }, }) - client:notify(ms.textDocument_didOpen, { + client:notify('textDocument/didOpen', { textDocument = { version = 0, uri = uri, @@ -839,7 +838,7 @@ local function text_document_did_save_handler(bufnr) if type(save_capability) == 'table' and save_capability.includeText then included_text = text(bufnr) end - client:notify(ms.textDocument_didSave, { + client:notify('textDocument/didSave', { textDocument = { uri = uri, }, @@ -874,12 +873,12 @@ local function buf_attach(bufnr) }, reason = protocol.TextDocumentSaveReason.Manual, ---@type integer } - if client:supports_method(ms.textDocument_willSave) then - client:notify(ms.textDocument_willSave, params) + if client:supports_method('textDocument/willSave') then + client:notify('textDocument/willSave', params) end - if client:supports_method(ms.textDocument_willSaveWaitUntil) then + if client:supports_method('textDocument/willSaveWaitUntil') then local result, err = - client:request_sync(ms.textDocument_willSaveWaitUntil, params, 1000, ctx.buf) + client:request_sync('textDocument/willSaveWaitUntil', params, 1000, ctx.buf) if result and result.result then util.apply_text_edits(result.result, ctx.buf, client.offset_encoding) elseif err then @@ -913,8 +912,8 @@ local function buf_attach(bufnr) local params = { textDocument = { uri = uri } } for _, client in ipairs(clients) do changetracking.reset_buf(client, bufnr) - if client:supports_method(ms.textDocument_didClose) then - client:notify(ms.textDocument_didClose, params) + if client:supports_method('textDocument/didClose') then + client:notify('textDocument/didClose', params) end end for _, client in ipairs(clients) do @@ -1371,7 +1370,7 @@ function lsp.formatexpr(opts) end local bufnr = api.nvim_get_current_buf() for _, client in pairs(lsp.get_clients({ bufnr = bufnr })) do - if client:supports_method(ms.textDocument_rangeFormatting) then + if client:supports_method('textDocument/rangeFormatting') then local params = util.make_formatting_params() local end_line = vim.fn.getline(end_lnum) --[[@as string]] local end_col = vim.str_utfindex(end_line, client.offset_encoding) @@ -1387,7 +1386,7 @@ function lsp.formatexpr(opts) }, } local response = - client:request_sync(ms.textDocument_rangeFormatting, params, timeout_ms, bufnr) + client:request_sync('textDocument/rangeFormatting', params, timeout_ms, bufnr) if response and response.result then util.apply_text_edits(response.result, bufnr, client.offset_encoding) return 0 diff --git a/runtime/lua/vim/lsp/_changetracking.lua b/runtime/lua/vim/lsp/_changetracking.lua index 87ac69bf61..4df023cf77 100644 --- a/runtime/lua/vim/lsp/_changetracking.lua +++ b/runtime/lua/vim/lsp/_changetracking.lua @@ -274,7 +274,7 @@ local function send_changes(bufnr, sync_kind, state, buf_state) local uri = vim.uri_from_bufnr(bufnr) for _, client in pairs(state.clients) do if not client:is_stopped() and vim.lsp.buf_is_attached(bufnr, client.id) then - client:notify(protocol.Methods.textDocument_didChange, { + client:notify('textDocument/didChange', { textDocument = { uri = uri, version = util.buf_versions[bufnr], diff --git a/runtime/lua/vim/lsp/_folding_range.lua b/runtime/lua/vim/lsp/_folding_range.lua index ebe386d4b3..7efc93f5a6 100644 --- a/runtime/lua/vim/lsp/_folding_range.lua +++ b/runtime/lua/vim/lsp/_folding_range.lua @@ -1,6 +1,5 @@ local util = require('vim.lsp.util') local log = require('vim.lsp.log') -local ms = require('vim.lsp.protocol').Methods local api = vim.api ---@type table @@ -37,7 +36,7 @@ local Capability = require('vim.lsp._capability') ---@field row_text table local State = { name = 'folding_range', - method = ms.textDocument_foldingRange, + method = 'textDocument/foldingRange', active = {}, } State.__index = State @@ -165,19 +164,19 @@ function State:refresh(client) local params = { textDocument = util.make_text_document_params(self.bufnr) } if client then - client:request(ms.textDocument_foldingRange, params, function(...) + client:request('textDocument/foldingRange', params, function(...) self:handler(...) end, self.bufnr) return end if - not next(vim.lsp.get_clients({ bufnr = self.bufnr, method = ms.textDocument_foldingRange })) + not next(vim.lsp.get_clients({ bufnr = self.bufnr, method = 'textDocument/foldingRange' })) then return end - vim.lsp.buf_request_all(self.bufnr, ms.textDocument_foldingRange, params, function(...) + vim.lsp.buf_request_all(self.bufnr, 'textDocument/foldingRange', params, function(...) self:multi_handler(...) end) end @@ -235,10 +234,10 @@ function State:new(bufnr) callback = function(args) local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) if - client:supports_method(ms.textDocument_foldingRange, bufnr) + client:supports_method('textDocument/foldingRange', bufnr) and ( - args.data.method == ms.textDocument_didChange - or args.data.method == ms.textDocument_didOpen + args.data.method == 'textDocument/didChange' + or args.data.method == 'textDocument/didOpen' ) then self:refresh(client) @@ -311,12 +310,12 @@ function M.foldclose(kind, winid) return end - if not next(vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_foldingRange })) then + if not next(vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/foldingRange' })) then return end ---@type lsp.FoldingRangeParams local params = { textDocument = util.make_text_document_params(bufnr) } - vim.lsp.buf_request_all(bufnr, ms.textDocument_foldingRange, params, function(...) + vim.lsp.buf_request_all(bufnr, 'textDocument/foldingRange', params, function(...) state:multi_handler(...) -- Ensure this buffer stays as the current buffer after the async request if api.nvim_win_get_buf(winid) == bufnr then diff --git a/runtime/lua/vim/lsp/_tagfunc.lua b/runtime/lua/vim/lsp/_tagfunc.lua index 159b95a33d..f1eb6a3fdb 100644 --- a/runtime/lua/vim/lsp/_tagfunc.lua +++ b/runtime/lua/vim/lsp/_tagfunc.lua @@ -1,7 +1,6 @@ local lsp = vim.lsp local api = vim.api local util = lsp.util -local ms = lsp.protocol.Methods ---@param name string ---@param range lsp.Range @@ -33,13 +32,9 @@ local function query_definition(pattern) table.insert(results, mk_tag_item(pattern, range, uri, position_encoding)) end - local request_results, _ = lsp.buf_request_sync( - bufnr, - ms.textDocument_definition, - function(client) - return util.make_position_params(win, client.offset_encoding) - end - ) + local request_results, _ = lsp.buf_request_sync(bufnr, 'textDocument/definition', function(client) + return util.make_position_params(win, client.offset_encoding) + end) for client_id, res in pairs(request_results or {}) do local client = assert(lsp.get_client_by_id(client_id)) @@ -69,7 +64,7 @@ end ---@return table[] local function query_workspace_symbols(pattern) local results_by_client, err = - lsp.buf_request_sync(0, ms.workspace_symbol, { query = pattern }, 1000) + lsp.buf_request_sync(0, 'workspace/symbol', { query = pattern }, 1000) if err then return {} end diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index 4711b3cc9b..ddfb5969c6 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -2,7 +2,6 @@ local bit = require('bit') local glob = vim.glob local watch = vim._watch local protocol = require('vim.lsp.protocol') -local ms = protocol.Methods local lpeg = vim.lpeg local M = {} @@ -116,7 +115,7 @@ function M.register(reg, client_id) local params = { changes = change_queues[client_id], } - client:notify(ms.workspace_didChangeWatchedFiles, params) + client:notify('workspace/didChangeWatchedFiles', params) queue_timers[client_id] = nil change_queues[client_id] = nil change_cache[client_id] = nil diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index cc93004512..e520b7d7c1 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -6,7 +6,6 @@ local lsp = vim.lsp local validate = vim.validate local util = require('vim.lsp.util') local npcall = vim.F.npcall -local ms = require('vim.lsp.protocol').Methods local M = {} @@ -50,9 +49,9 @@ function M.hover(config) validate('config', config, 'table', true) config = config or {} - config.focus_id = ms.textDocument_hover + config.focus_id = 'textDocument/hover' - lsp.buf_request_all(0, ms.textDocument_hover, client_positional_params(), function(results, ctx) + lsp.buf_request_all(0, 'textDocument/hover', client_positional_params(), function(results, ctx) local bufnr = assert(ctx.bufnr) if api.nvim_get_current_buf() ~= bufnr then -- Ignore result since buffer changed. This happens for slow language servers. @@ -306,21 +305,21 @@ end --- @param opts? vim.lsp.LocationOpts function M.declaration(opts) validate('opts', opts, 'table', true) - get_locations(ms.textDocument_declaration, opts) + get_locations('textDocument/declaration', opts) end --- Jumps to the definition of the symbol under the cursor. --- @param opts? vim.lsp.LocationOpts function M.definition(opts) validate('opts', opts, 'table', true) - get_locations(ms.textDocument_definition, opts) + get_locations('textDocument/definition', opts) end --- Jumps to the definition of the type of the symbol under the cursor. --- @param opts? vim.lsp.LocationOpts function M.type_definition(opts) validate('opts', opts, 'table', true) - get_locations(ms.textDocument_typeDefinition, opts) + get_locations('textDocument/typeDefinition', opts) end --- Lists all the implementations for the symbol under the cursor in the @@ -328,7 +327,7 @@ end --- @param opts? vim.lsp.LocationOpts function M.implementation(opts) validate('opts', opts, 'table', true) - get_locations(ms.textDocument_implementation, opts) + get_locations('textDocument/implementation', opts) end --- @param results table @@ -383,7 +382,7 @@ local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help') function M.signature_help(config) validate('config', config, 'table', true) - local method = ms.textDocument_signatureHelp + local method = 'textDocument/signatureHelp' config = config and vim.deepcopy(config) or {} config.focus_id = method @@ -488,7 +487,7 @@ function M.completion(context) vim.deprecate('vim.lsp.buf.completion', 'vim.lsp.completion.trigger', '0.12') return lsp.buf_request( 0, - ms.textDocument_completion, + 'textDocument/completion', client_positional_params({ context = context, }) @@ -592,13 +591,13 @@ function M.format(opts) end local passed_multiple_ranges = (range and #range ~= 0 and type(range[1]) == 'table') - local method ---@type vim.lsp.protocol.Method.ClientToServer + local method ---@type vim.lsp.protocol.Method.ClientToServer.Request if passed_multiple_ranges then - method = ms.textDocument_rangesFormatting + method = 'textDocument/rangesFormatting' elseif range then - method = ms.textDocument_rangeFormatting + method = 'textDocument/rangeFormatting' else - method = ms.textDocument_formatting + method = 'textDocument/formatting' end local clients = lsp.get_clients({ @@ -695,7 +694,7 @@ function M.rename(new_name, opts) bufnr = bufnr, name = opts.name, -- Clients must at least support rename, prepareRename is optional - method = ms.textDocument_rename, + method = 'textDocument/rename', }) if opts.filter then clients = vim.tbl_filter(opts.filter, clients) @@ -734,17 +733,16 @@ function M.rename(new_name, opts) local function rename(name) local params = util.make_position_params(win, client.offset_encoding) --[[@as lsp.RenameParams]] params.newName = name - local handler = client.handlers[ms.textDocument_rename] - or lsp.handlers[ms.textDocument_rename] - client:request(ms.textDocument_rename, params, function(...) + local handler = client.handlers['textDocument/rename'] or lsp.handlers['textDocument/rename'] + client:request('textDocument/rename', params, function(...) handler(...) try_use_client(next(clients, idx)) end, bufnr) end - if client:supports_method(ms.textDocument_prepareRename) then + if client:supports_method('textDocument/prepareRename') then local params = util.make_position_params(win, client.offset_encoding) - client:request(ms.textDocument_prepareRename, params, function(err, result) + client:request('textDocument/prepareRename', params, function(err, result) if err or result == nil then if next(clients, idx) then try_use_client(next(clients, idx)) @@ -783,7 +781,7 @@ function M.rename(new_name, opts) end, bufnr) else assert( - client:supports_method(ms.textDocument_rename), + client:supports_method('textDocument/rename'), 'Client must support textDocument/rename' ) if new_name then @@ -820,7 +818,7 @@ function M.references(context, opts) local win = api.nvim_get_current_win() opts = opts or {} - lsp.buf_request_all(bufnr, ms.textDocument_references, function(client) + lsp.buf_request_all(bufnr, 'textDocument/references', function(client) local params = util.make_position_params(win, client.offset_encoding) ---@diagnostic disable-next-line: inject-field params.context = context or { includeDeclaration = true } @@ -842,7 +840,7 @@ function M.references(context, opts) title = title, items = all_items, context = { - method = ms.textDocument_references, + method = 'textDocument/references', bufnr = bufnr, }, } @@ -866,7 +864,7 @@ function M.document_symbol(opts) validate('opts', opts, 'table', true) opts = vim.tbl_deep_extend('keep', opts or {}, { loclist = true }) local params = { textDocument = util.make_text_document_params() } - request_with_opts(ms.textDocument_documentSymbol, params, opts) + request_with_opts('textDocument/documentSymbol', params, opts) end --- @param client_id integer @@ -902,18 +900,18 @@ end --- @type table local hierarchy_methods = { - [ms.typeHierarchy_subtypes] = 'type', - [ms.typeHierarchy_supertypes] = 'type', - [ms.callHierarchy_incomingCalls] = 'call', - [ms.callHierarchy_outgoingCalls] = 'call', + ['typeHierarchy/subtypes'] = 'type', + ['typeHierarchy/supertypes'] = 'type', + ['callHierarchy/incomingCalls'] = 'call', + ['callHierarchy/outgoingCalls'] = 'call', } --- @param method vim.lsp.buf.HierarchyMethod local function hierarchy(method) local kind = hierarchy_methods[method] - local prepare_method = kind == 'type' and ms.textDocument_prepareTypeHierarchy - or ms.textDocument_prepareCallHierarchy + local prepare_method = kind == 'type' and 'textDocument/prepareTypeHierarchy' + or 'textDocument/prepareCallHierarchy' local bufnr = api.nvim_get_current_buf() local clients = lsp.get_clients({ bufnr = bufnr, method = prepare_method }) @@ -965,14 +963,14 @@ end --- |quickfix| window. If the symbol can resolve to multiple --- items, the user can pick one in the |inputlist()|. function M.incoming_calls() - hierarchy(ms.callHierarchy_incomingCalls) + hierarchy('callHierarchy/incomingCalls') end --- Lists all the items that are called by the symbol under the --- cursor in the |quickfix| window. If the symbol can resolve to --- multiple items, the user can pick one in the |inputlist()|. function M.outgoing_calls() - hierarchy(ms.callHierarchy_outgoingCalls) + hierarchy('callHierarchy/outgoingCalls') end --- Lists all the subtypes or supertypes of the symbol under the @@ -984,7 +982,7 @@ function M.typehierarchy(kind) return v == 'subtypes' or v == 'supertypes' end) - local method = kind == 'subtypes' and ms.typeHierarchy_subtypes or ms.typeHierarchy_supertypes + local method = kind == 'subtypes' and 'typeHierarchy/subtypes' or 'typeHierarchy/supertypes' hierarchy(method) end @@ -1059,7 +1057,7 @@ function M.workspace_symbol(query, opts) return end local params = { query = query } - request_with_opts(ms.workspace_symbol, params, opts) + request_with_opts('workspace/symbol', params, opts) end --- @class vim.lsp.WorkspaceDiagnosticsOpts @@ -1093,7 +1091,7 @@ end --- |hl-LspReferenceRead| --- |hl-LspReferenceWrite| function M.document_highlight() - lsp.buf_request(0, ms.textDocument_documentHighlight, client_positional_params()) + lsp.buf_request(0, 'textDocument/documentHighlight', client_positional_params()) end --- Removes document highlights from current buffer. @@ -1239,8 +1237,8 @@ local function on_code_action_results(results, opts) return end - if not (action.edit and action.command) and client:supports_method(ms.codeAction_resolve) then - client:request(ms.codeAction_resolve, action, function(err, resolved_action) + if not (action.edit and action.command) and client:supports_method('codeAction/resolve') then + client:request('codeAction/resolve', action, function(err, resolved_action) if err then -- If resolve fails, try to apply the edit/command from the original code action. if action.edit or action.command then @@ -1310,13 +1308,13 @@ function M.code_action(opts) local mode = api.nvim_get_mode().mode local bufnr = api.nvim_get_current_buf() local win = api.nvim_get_current_win() - local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_codeAction }) + local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/codeAction' }) if not next(clients) then - vim.notify(lsp._unsupported_method(ms.textDocument_codeAction), vim.log.levels.WARN) + vim.notify(lsp._unsupported_method('textDocument/codeAction'), vim.log.levels.WARN) return end - lsp.buf_request_all(bufnr, ms.textDocument_codeAction, function(client) + lsp.buf_request_all(bufnr, 'textDocument/codeAction', function(client) ---@type lsp.CodeActionParams local params @@ -1371,7 +1369,7 @@ function M.execute_command(command_params) arguments = command_params.arguments, workDoneToken = command_params.workDoneToken, } - lsp.buf_request(0, ms.workspace_executeCommand, command_params) + lsp.buf_request(0, 'workspace/executeCommand', command_params) end ---@type { index: integer, ranges: lsp.Range[] }? @@ -1418,7 +1416,7 @@ function M.selection_range(direction) return end - local method = ms.textDocument_selectionRange + local method = 'textDocument/selectionRange' local client = lsp.get_clients({ method = method, bufnr = 0 })[1] if not client then vim.notify(lsp._unsupported_method(method), vim.log.levels.WARN) diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index 3ca1de6b4e..79d5008e4c 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -2,7 +2,6 @@ local uv = vim.uv local api = vim.api local lsp = vim.lsp local log = lsp.log -local ms = lsp.protocol.Methods local changetracking = lsp._changetracking local validate = vim.validate @@ -578,7 +577,7 @@ function Client:initialize() self.server_info = result.serverInfo if next(self.settings) then - self:notify(ms.workspace_didChangeConfiguration, { settings = self.settings }) + self:notify('workspace/didChangeConfiguration', { settings = self.settings }) end -- If server is being restarted, make sure to re-attach to any previously attached buffers. @@ -604,21 +603,21 @@ end -- Server capabilities for methods that support static registration. local static_registration_capabilities = { - [ms.textDocument_prepareCallHierarchy] = 'callHierarchyProvider', - [ms.textDocument_documentColor] = 'colorProvider', - [ms.textDocument_declaration] = 'declarationProvider', - [ms.textDocument_diagnostic] = 'diagnosticProvider', - [ms.textDocument_foldingRange] = 'foldingRangeProvider', - [ms.textDocument_implementation] = 'implementationProvider', - [ms.textDocument_inlayHint] = 'inlayHintProvider', - [ms.textDocument_inlineCompletion] = 'inlineCompletionProvider', - [ms.textDocument_inlineValue] = 'inlineValueProvider', - [ms.textDocument_linkedEditingRange] = 'linkedEditingRangeProvider', - [ms.textDocument_moniker] = 'monikerProvider', - [ms.textDocument_selectionRange] = 'selectionRangeProvider', - [ms.textDocument_semanticTokens_full] = 'semanticTokensProvider', - [ms.textDocument_typeDefinition] = 'typeDefinitionProvider', - [ms.textDocument_prepareTypeHierarchy] = 'typeHierarchyProvider', + ['textDocument/prepareCallHierarchy'] = 'callHierarchyProvider', + ['textDocument/documentColor'] = 'colorProvider', + ['textDocument/declaration'] = 'declarationProvider', + ['textDocument/diagnostic'] = 'diagnosticProvider', + ['textDocument/foldingRange'] = 'foldingRangeProvider', + ['textDocument/implementation'] = 'implementationProvider', + ['textDocument/inlayHint'] = 'inlayHintProvider', + ['textDocument/inlineCompletion'] = 'inlineCompletionProvider', + ['textDocument/inlineValue'] = 'inlineValueProvider', + ['textDocument/linkedEditingRange'] = 'linkedEditingRangeProvider', + ['textDocument/moniker'] = 'monikerProvider', + ['textDocument/selectionRange'] = 'selectionRangeProvider', + ['textDocument_semanticTokens/full'] = 'semanticTokensProvider', + ['textDocument/typeDefinition'] = 'typeDefinitionProvider', + ['textDocument/prepareTypeHierarchy'] = 'typeHierarchyProvider', } --- @private @@ -628,6 +627,7 @@ function Client:_process_static_registrations() for method, capability in pairs(static_registration_capabilities) do if vim.tbl_get(self.server_capabilities, capability, 'id') + --- @cast method vim.lsp.protocol.Method and self:_supports_registration(method) then static_registrations[#static_registrations + 1] = { @@ -827,7 +827,7 @@ end --- @return boolean status indicating if the notification was successful. --- If it is false, then the client has shutdown. function Client:notify(method, params) - if method ~= ms.textDocument_didChange then + if method ~= 'textDocument/didChange' then changetracking.flush(self) end @@ -856,7 +856,7 @@ end --- @see |Client:notify()| function Client:cancel_request(id) self:_process_request(id, 'cancel') - return self.rpc.notify(ms.dollar_cancelRequest, { id = id }) + return self.rpc.notify('$/cancelRequest', { id = id }) end --- Stops a client, optionally with force. @@ -882,9 +882,9 @@ function Client:stop(force) end -- Sending a signal after a process has exited is acceptable. - rpc.request(ms.shutdown, nil, function(err, _) + rpc.request('shutdown', nil, function(err, _) if err == nil then - rpc.notify(ms.exit) + rpc.notify('exit') else -- If there was an error in the shutdown request, then term to be safe. rpc.terminate() @@ -923,7 +923,7 @@ function Client:_register(registrations) for _, reg in ipairs(registrations) do local method = reg.method - if method == ms.workspace_didChangeWatchedFiles then + if method == 'workspace/didChangeWatchedFiles' then lsp._watchfiles.register(reg, self.id) elseif not self:_supports_registration(method) then unsupported[#unsupported + 1] = method @@ -957,7 +957,7 @@ end function Client:_unregister(unregistrations) self:_unregister_dynamic(unregistrations) for _, unreg in ipairs(unregistrations) do - if unreg.method == ms.workspace_didChangeWatchedFiles then + if unreg.method == 'workspace/didChangeWatchedFiles' then lsp._watchfiles.unregister(unreg, self.id) end end @@ -1045,7 +1045,7 @@ function Client:exec_cmd(command, context, handler) command = cmdname, arguments = command.arguments, } - self:request(ms.workspace_executeCommand, params, handler, context.bufnr) + self:request('workspace/executeCommand', params, handler, context.bufnr) end --- Default handler for the 'textDocument/didOpen' LSP notification. @@ -1053,14 +1053,14 @@ end --- @param bufnr integer Number of the buffer, or 0 for current function Client:_text_document_did_open_handler(bufnr) changetracking.init(self, bufnr) - if not self:supports_method(ms.textDocument_didOpen) then + if not self:supports_method('textDocument/didOpen') then return end if not api.nvim_buf_is_loaded(bufnr) then return end - self:notify(ms.textDocument_didOpen, { + self:notify('textDocument/didOpen', { textDocument = { version = lsp.util.buf_versions[bufnr], uri = vim.uri_from_bufnr(bufnr), @@ -1250,10 +1250,10 @@ function Client:_on_detach(bufnr) changetracking.reset_buf(self, bufnr) - if self:supports_method(ms.textDocument_didClose) then + if self:supports_method('textDocument/didClose') then local uri = vim.uri_from_bufnr(bufnr) local params = { textDocument = { uri = uri } } - self:notify(ms.textDocument_didClose, params) + self:notify('textDocument/didClose', params) end self.attached_buffers[bufnr] = nil @@ -1340,7 +1340,7 @@ function Client:_add_workspace_folder(dir) local wf = assert(lsp._get_workspace_folders(dir)) - self:notify(ms.workspace_didChangeWorkspaceFolders, { + self:notify('workspace/didChangeWorkspaceFolders', { event = { added = wf, removed = {} }, }) @@ -1355,7 +1355,7 @@ end function Client:_remove_workspace_folder(dir) local wf = assert(lsp._get_workspace_folders(dir)) - self:notify(ms.workspace_didChangeWorkspaceFolders, { + self:notify('workspace/didChangeWorkspaceFolders', { event = { added = {}, removed = wf }, }) diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua index d04a49e086..8ca7871917 100644 --- a/runtime/lua/vim/lsp/codelens.lua +++ b/runtime/lua/vim/lsp/codelens.lua @@ -1,6 +1,5 @@ local util = require('vim.lsp.util') local log = require('vim.lsp.log') -local ms = require('vim.lsp.protocol').Methods local api = vim.api local M = {} @@ -49,7 +48,7 @@ local function execute_lens(lens, bufnr, client_id) local client = vim.lsp.get_client_by_id(client_id) assert(client, 'Client is required to execute lens, client_id=' .. client_id) client:exec_cmd(lens.command, { bufnr = bufnr }, function(...) - vim.lsp.handlers[ms.workspace_executeCommand](...) + vim.lsp.handlers['workspace/executeCommand'](...) M.refresh() end) end @@ -276,7 +275,7 @@ local function resolve_lenses(lenses, bufnr, client_id, callback) display_line_countdown() else assert(client) - client:request(ms.codeLens_resolve, lens, function(_, result) + client:request('codeLens/resolve', lens, function(_, result) if api.nvim_buf_is_loaded(bufnr) and result and result.command then lens.command = result.command end @@ -340,7 +339,7 @@ function M.refresh(opts) local request_ids = vim.lsp.buf_request( buf, - ms.textDocument_codeLens, + 'textDocument/codeLens', params, M.on_codelens, function() end diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua index 42fe470f14..01f36cfc9f 100644 --- a/runtime/lua/vim/lsp/completion.lua +++ b/runtime/lua/vim/lsp/completion.lua @@ -36,7 +36,6 @@ local M = {} local api = vim.api local lsp = vim.lsp local protocol = lsp.protocol -local ms = protocol.Methods local rtt_ms = 50.0 local ns_to_ms = 0.000001 @@ -448,7 +447,7 @@ local function request(clients, bufnr, win, ctx, callback) local params = lsp.util.make_position_params(win, client.offset_encoding) --- @cast params lsp.CompletionParams params.context = ctx - local ok, request_id = client:request(ms.textDocument_completion, params, function(err, result) + local ok, request_id = client:request('textDocument/completion', params, function(err, result) responses[client_id] = { err = err, result = result } remaining_requests = remaining_requests - 1 if remaining_requests == 0 then @@ -660,7 +659,7 @@ local function on_complete_done() local changedtick = vim.b[bufnr].changedtick --- @param result lsp.CompletionItem - client:request(ms.completionItem_resolve, completion_item, function(err, result) + client:request('completionItem/resolve', completion_item, function(err, result) if changedtick ~= vim.b[bufnr].changedtick then return end @@ -870,7 +869,7 @@ function M._omnifunc(findstart, base) lsp.log.debug('omnifunc.findstart', { findstart = findstart, base = base }) assert(base) -- silence luals local bufnr = api.nvim_get_current_buf() - local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_completion }) + local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/completion' }) local remaining = #clients if remaining == 0 then return findstart == 1 and -1 or {} diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 285dfed17e..a1a9a5bb77 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -5,7 +5,6 @@ local lsp = vim.lsp local protocol = lsp.protocol -local ms = protocol.Methods local util = lsp.util local api = vim.api @@ -363,7 +362,7 @@ local function refresh(bufnr, client_id, only_visible) return end - local method = ms.textDocument_diagnostic + local method = 'textDocument/diagnostic' local clients = lsp.get_clients({ bufnr = bufnr, method = method, id = client_id }) local bufstate = bufstates[bufnr] @@ -403,8 +402,8 @@ function M._enable(bufnr) buffer = bufnr, callback = function(opts) if - opts.data.method ~= ms.textDocument_didChange - and opts.data.method ~= ms.textDocument_didOpen + opts.data.method ~= 'textDocument/didChange' + and opts.data.method ~= 'textDocument/didOpen' then return end @@ -430,7 +429,7 @@ function M._enable(bufnr) api.nvim_create_autocmd('LspDetach', { buffer = bufnr, callback = function(args) - local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_diagnostic }) + local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/diagnostic' }) if not vim.iter(clients):any(function(c) @@ -469,7 +468,7 @@ end --- Request workspace-wide diagnostics. --- @param opts vim.lsp.WorkspaceDiagnosticsOpts function M._workspace_diagnostics(opts) - local clients = lsp.get_clients({ method = ms.workspace_diagnostic, id = opts.client_id }) + local clients = lsp.get_clients({ method = 'workspace/diagnostic', id = opts.client_id }) --- @param error lsp.ResponseError? --- @param result lsp.WorkspaceDiagnosticReport @@ -480,7 +479,7 @@ function M._workspace_diagnostics(opts) if error ~= nil and error.code == protocol.ErrorCodes.ServerCancelled then if error.data == nil or error.data.retriggerRequest ~= false then local client = assert(lsp.get_client_by_id(ctx.client_id)) - client:request(ms.workspace_diagnostic, ctx.params, handler) + client:request('workspace/diagnostic', ctx.params, handler) end return end @@ -511,7 +510,7 @@ function M._workspace_diagnostics(opts) previousResultIds = previous_result_ids(client.id), } - client:request(ms.workspace_diagnostic, params, handler) + client:request('workspace/diagnostic', params, handler) end end diff --git a/runtime/lua/vim/lsp/document_color.lua b/runtime/lua/vim/lsp/document_color.lua index d83ac719f8..f9f613ed43 100644 --- a/runtime/lua/vim/lsp/document_color.lua +++ b/runtime/lua/vim/lsp/document_color.lua @@ -4,7 +4,6 @@ local api = vim.api local lsp = vim.lsp local util = lsp.util -local ms = lsp.protocol.Methods local Range = vim.treesitter._range local document_color_ns = api.nvim_create_namespace('nvim.lsp.document_color') @@ -223,7 +222,7 @@ local function buf_enable(bufnr) local method = args.data.method --- @type string if - (method == ms.textDocument_didChange or method == ms.textDocument_didOpen) + (method == 'textDocument/didChange' or method == 'textDocument/didOpen') and assert(bufstates[args.buf]).enabled then M._buf_refresh(args.buf, args.data.client_id) @@ -236,7 +235,7 @@ local function buf_enable(bufnr) group = document_color_augroup, desc = 'Disable document_color if all supporting clients detach', callback = function(args) - local clients = lsp.get_clients({ bufnr = args.buf, method = ms.textDocument_documentColor }) + local clients = lsp.get_clients({ bufnr = args.buf, method = 'textDocument/documentColor' }) if not vim.iter(clients):any(function(c) @@ -259,12 +258,12 @@ function M._buf_refresh(bufnr, client_id) ipairs(lsp.get_clients({ bufnr = bufnr, id = client_id, - method = ms.textDocument_documentColor, + method = 'textDocument/documentColor', })) do ---@type lsp.DocumentColorParams local params = { textDocument = util.make_text_document_params(bufnr) } - client:request(ms.textDocument_documentColor, params, on_document_color) + client:request('textDocument/documentColor', params, on_document_color) end end @@ -416,7 +415,7 @@ function M.color_presentation() } --- @param result lsp.ColorPresentation[] - client:request(ms.textDocument_colorPresentation, params, function(err, result, ctx) + client:request('textDocument/colorPresentation', params, function(err, result, ctx) if err then lsp.log.error('color_presentation', err) return diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index c45e8e1ea2..d6a612b9f6 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -1,6 +1,5 @@ local log = require('vim.lsp.log') local protocol = require('vim.lsp.protocol') -local ms = protocol.Methods local util = require('vim.lsp.util') local api = vim.api local completion = require('vim.lsp.completion') @@ -45,7 +44,7 @@ local function show_message_notification(params, ctx) end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand -RCS[ms.workspace_executeCommand] = function(_, _, _) +RCS['workspace/executeCommand'] = function(_, _, _) -- Error handling is done implicitly by wrapping all handlers; see end of this file end @@ -53,7 +52,7 @@ end ---@param params lsp.ProgressParams ---@param ctx lsp.HandlerContext ---@diagnostic disable-next-line:no-unknown -RSC[ms.dollar_progress] = function(_, params, ctx) +RSC['$/progress'] = function(_, params, ctx) local client = vim.lsp.get_client_by_id(ctx.client_id) if not client then err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update') @@ -89,7 +88,7 @@ end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create ---@param params lsp.WorkDoneProgressCreateParams ---@param ctx lsp.HandlerContext -RSC[ms.window_workDoneProgress_create] = function(_, params, ctx) +RSC['window/workDoneProgress/create'] = function(_, params, ctx) local client = vim.lsp.get_client_by_id(ctx.client_id) if not client then err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update') @@ -101,7 +100,7 @@ end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest ---@param params lsp.ShowMessageRequestParams -RSC[ms.window_showMessageRequest] = function(_, params, ctx) +RSC['window/showMessageRequest'] = function(_, params, ctx) if next(params.actions or {}) then local co, is_main = coroutine.running() if co and not is_main then @@ -143,14 +142,14 @@ end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability --- @param params lsp.RegistrationParams -RSC[ms.client_registerCapability] = function(_, params, ctx) +RSC['client/registerCapability'] = function(_, params, ctx) local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) client:_register(params.registrations) for bufnr in pairs(client.attached_buffers) do vim.lsp._set_defaults(client, bufnr) end for _, reg in ipairs(params.registrations) do - if reg.method == ms.textDocument_documentColor then + if reg.method == 'textDocument/documentColor' then for bufnr in pairs(client.attached_buffers) do if vim.lsp.document_color.is_enabled(bufnr) then vim.lsp.document_color._buf_refresh(bufnr, client.id) @@ -163,7 +162,7 @@ end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_unregisterCapability --- @param params lsp.UnregistrationParams -RSC[ms.client_unregisterCapability] = function(_, params, ctx) +RSC['client/unregisterCapability'] = function(_, params, ctx) local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) client:_unregister(params.unregisterations) return vim.NIL @@ -171,7 +170,7 @@ end -- TODO(lewis6991): Do we need to notify other servers? --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit -RSC[ms.workspace_applyEdit] = function(_, params, ctx) +RSC['workspace/applyEdit'] = function(_, params, ctx) assert( params, 'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification' @@ -198,7 +197,7 @@ end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration --- @param params lsp.ConfigurationParams -RSC[ms.workspace_configuration] = function(_, params, ctx) +RSC['workspace/configuration'] = function(_, params, ctx) local client = vim.lsp.get_client_by_id(ctx.client_id) if not client then err_message( @@ -230,7 +229,7 @@ RSC[ms.workspace_configuration] = function(_, params, ctx) end --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_workspaceFolders -RSC[ms.workspace_workspaceFolders] = function(_, _, ctx) +RSC['workspace/workspaceFolders'] = function(_, _, ctx) local client = vim.lsp.get_client_by_id(ctx.client_id) if not client then err_message('LSP[id=', ctx.client_id, '] client has shut down after sending the message') @@ -239,22 +238,22 @@ RSC[ms.workspace_workspaceFolders] = function(_, _, ctx) return client.workspace_folders or vim.NIL end -NSC[ms.textDocument_publishDiagnostics] = function(...) +NSC['textDocument/publishDiagnostics'] = function(...) return vim.lsp.diagnostic.on_publish_diagnostics(...) end --- @private -RCS[ms.textDocument_diagnostic] = function(...) +RCS['textDocument/diagnostic'] = function(...) return vim.lsp.diagnostic.on_diagnostic(...) end --- @private -RCS[ms.textDocument_codeLens] = function(...) +RCS['textDocument/codeLens'] = function(...) return vim.lsp.codelens.on_codelens(...) end --- @private -RCS[ms.textDocument_inlayHint] = function(...) +RCS['textDocument/inlayHint'] = function(...) return vim.lsp.inlay_hint.on_inlayhint(...) end @@ -294,7 +293,7 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol -RCS[ms.textDocument_documentSymbol] = response_to_list( +RCS['textDocument/documentSymbol'] = response_to_list( util.symbols_to_items, 'document symbols', function(ctx) @@ -305,13 +304,13 @@ RCS[ms.textDocument_documentSymbol] = response_to_list( --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol -RCS[ms.workspace_symbol] = response_to_list(util.symbols_to_items, 'symbols', function(ctx) +RCS['workspace/symbol'] = response_to_list(util.symbols_to_items, 'symbols', function(ctx) return string.format("Symbols matching '%s'", ctx.params.query) end) --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename -RCS[ms.textDocument_rename] = function(_, result, ctx) +RCS['textDocument/rename'] = function(_, result, ctx) if not result then vim.notify("Language server couldn't provide rename result", vim.log.levels.INFO) return @@ -322,7 +321,7 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting -RCS[ms.textDocument_rangeFormatting] = function(_, result, ctx) +RCS['textDocument/rangeFormatting'] = function(_, result, ctx) if not result then return end @@ -332,7 +331,7 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting -RCS[ms.textDocument_formatting] = function(_, result, ctx) +RCS['textDocument/formatting'] = function(_, result, ctx) if not result then return end @@ -342,7 +341,7 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion -RCS[ms.textDocument_completion] = function(_, result, _) +RCS['textDocument/completion'] = function(_, result, _) if vim.tbl_isempty(result or {}) then return end @@ -412,7 +411,7 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover --- @diagnostic disable-next-line: deprecated -RCS[ms.textDocument_hover] = M.hover +RCS['textDocument/hover'] = M.hover local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help') @@ -481,11 +480,11 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp --- @diagnostic disable-next-line:deprecated -RCS[ms.textDocument_signatureHelp] = M.signature_help +RCS['textDocument/signatureHelp'] = M.signature_help --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight -RCS[ms.textDocument_documentHighlight] = function(_, result, ctx) +RCS['textDocument/documentHighlight'] = function(_, result, ctx) if not result then return end @@ -528,11 +527,11 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_incomingCalls -RCS[ms.callHierarchy_incomingCalls] = make_call_hierarchy_handler('from') +RCS['callHierarchy/incomingCalls'] = make_call_hierarchy_handler('from') --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_outgoingCalls -RCS[ms.callHierarchy_outgoingCalls] = make_call_hierarchy_handler('to') +RCS['callHierarchy/outgoingCalls'] = make_call_hierarchy_handler('to') --- Displays type hierarchy in the quickfix window. local function make_type_hierarchy_handler() @@ -569,11 +568,11 @@ end --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_incomingCalls -RCS[ms.typeHierarchy_subtypes] = make_type_hierarchy_handler() +RCS['typeHierarchy/subtypes'] = make_type_hierarchy_handler() --- @deprecated remove in 0.13 --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_outgoingCalls -RCS[ms.typeHierarchy_supertypes] = make_type_hierarchy_handler() +RCS['typeHierarchy/supertypes'] = make_type_hierarchy_handler() --- @see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_logMessage --- @param params lsp.LogMessageParams @@ -607,7 +606,7 @@ end --- @private --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showDocument --- @param params lsp.ShowDocumentParams -RSC[ms.window_showDocument] = function(_, params, ctx) +RSC['window/showDocument'] = function(_, params, ctx) local uri = params.uri if params.external then @@ -649,12 +648,12 @@ RSC[ms.window_showDocument] = function(_, params, ctx) end ---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_inlayHint_refresh -RSC[ms.workspace_inlayHint_refresh] = function(err, result, ctx) +RSC['workspace_inlayHint/refresh'] = function(err, result, ctx) return vim.lsp.inlay_hint.on_refresh(err, result, ctx) end ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#semanticTokens_refreshRequest -RSC[ms.workspace_semanticTokens_refresh] = function(err, result, ctx) +RSC['workspace_semanticTokens/refresh'] = function(err, result, ctx) return vim.lsp.semantic_tokens._refresh(err, result, ctx) end diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua index 29f3e7c6a4..34a6dd59ab 100644 --- a/runtime/lua/vim/lsp/health.lua +++ b/runtime/lua/vim/lsp/health.lua @@ -126,7 +126,7 @@ local function check_watcher() 'dynamicRegistration' ) local has_dynamic_capability = - client.dynamic_capabilities:get(vim.lsp.protocol.Methods.workspace_didChangeWatchedFiles) + client.dynamic_capabilities:get('workspace/didChangeWatchedFiles') return has_capability == nil or has_dynamic_capability == nil or client.workspace_folders == nil diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua index a5d58b349e..867055128e 100644 --- a/runtime/lua/vim/lsp/inlay_hint.lua +++ b/runtime/lua/vim/lsp/inlay_hint.lua @@ -1,6 +1,5 @@ local util = require('vim.lsp.util') local log = require('vim.lsp.log') -local ms = require('vim.lsp.protocol').Methods local api = vim.api local M = {} @@ -96,10 +95,10 @@ local function refresh(bufnr, client_id) ipairs(vim.lsp.get_clients({ bufnr = bufnr, id = client_id, - method = ms.textDocument_inlayHint, + method = 'textDocument/inlayHint', })) do - client:request(ms.textDocument_inlayHint, { + client:request('textDocument/inlayHint', { textDocument = util.make_text_document_params(bufnr), range = util._make_line_range_params( bufnr, @@ -190,7 +189,7 @@ function M.get(filter) local clients = vim.lsp.get_clients({ bufnr = bufnr, - method = ms.textDocument_inlayHint, + method = 'textDocument/inlayHint', }) if #clients == 0 then return {} @@ -270,8 +269,8 @@ api.nvim_create_autocmd('LspNotify', { local bufnr = args.buf if - args.data.method ~= ms.textDocument_didChange - and args.data.method ~= ms.textDocument_didOpen + args.data.method ~= 'textDocument/didChange' + and args.data.method ~= 'textDocument/didOpen' then return end @@ -306,7 +305,7 @@ api.nvim_create_autocmd('LspDetach', { callback = function(args) ---@type integer local bufnr = args.buf - local clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_inlayHint }) + local clients = vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/inlayHint' }) if not vim.iter(clients):any(function(c) return c.id ~= args.data.client_id diff --git a/runtime/lua/vim/lsp/inline_completion.lua b/runtime/lua/vim/lsp/inline_completion.lua index 0e22f082ad..c067ca6d08 100644 --- a/runtime/lua/vim/lsp/inline_completion.lua +++ b/runtime/lua/vim/lsp/inline_completion.lua @@ -33,7 +33,6 @@ local util = require('vim.lsp.util') local log = require('vim.lsp.log') local protocol = require('vim.lsp.protocol') -local ms = require('vim.lsp.protocol').Methods local grammar = require('vim.lsp._snippet_grammar') local api = vim.api @@ -61,7 +60,7 @@ local namespace = api.nvim_create_namespace('nvim.lsp.inline_completion') ---@field client_state table local Completor = { name = 'inline_completion', - method = ms.textDocument_inlineCompletion, + method = 'textDocument/inlineCompletion', active = {}, } Completor.__index = Completor @@ -283,7 +282,7 @@ function Completor:request(kind) position = util.make_position_params(0, client.offset_encoding).position, context = context, } - client:request(ms.textDocument_inlineCompletion, params, function(...) + client:request('textDocument/inlineCompletion', params, function(...) self:handler(...) end) end @@ -318,7 +317,7 @@ end function Completor:abort() util._cancel_requests({ bufnr = self.bufnr, - method = ms.textDocument_inlineCompletion, + method = 'textDocument/inlineCompletion', type = 'pending', }) self:reset_timer() diff --git a/runtime/lua/vim/lsp/linked_editing_range.lua b/runtime/lua/vim/lsp/linked_editing_range.lua index 1146ddd4ee..b4070454de 100644 --- a/runtime/lua/vim/lsp/linked_editing_range.lua +++ b/runtime/lua/vim/lsp/linked_editing_range.lua @@ -10,7 +10,7 @@ local util = require('vim.lsp.util') local log = require('vim.lsp.log') local lsp = vim.lsp -local method = require('vim.lsp.protocol').Methods.textDocument_linkedEditingRange +local method = 'textDocument/linkedEditingRange' local Range = require('vim.treesitter._range') local api = vim.api local M = {} diff --git a/runtime/lua/vim/lsp/on_type_formatting.lua b/runtime/lua/vim/lsp/on_type_formatting.lua index 217c4ea8ef..02f64f4145 100644 --- a/runtime/lua/vim/lsp/on_type_formatting.lua +++ b/runtime/lua/vim/lsp/on_type_formatting.lua @@ -1,7 +1,7 @@ local api = vim.api local lsp = vim.lsp local util = lsp.util -local method = lsp.protocol.Methods.textDocument_onTypeFormatting +local method = 'textDocument/onTypeFormatting' local schedule = vim.schedule local current_buf = api.nvim_get_current_buf diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 3d70d8b98c..2a45e20cbc 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -789,6 +789,7 @@ end --- | vim.lsp.protocol.Method.ServerToClient -- Generated by gen_lsp.lua, keep at end of file. +--- @deprecated Use `vim.lsp.protocol.Method` instead. --- @enum vim.lsp.protocol.Methods --- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel --- LSP method names. diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 9859bb3f99..3bd703785a 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -1,6 +1,5 @@ local api = vim.api local bit = require('bit') -local ms = require('vim.lsp.protocol').Methods local util = require('vim.lsp.util') local Range = require('vim.treesitter._range') local uv = vim.uv @@ -43,7 +42,7 @@ local M = {} ---@field client_state table local STHighlighter = { name = 'semantic_tokens', - method = ms.textDocument_semanticTokens_full, + method = 'textDocument/semanticTokens/full', active = {}, } STHighlighter.__index = STHighlighter @@ -255,12 +254,13 @@ function STHighlighter:send_request() local hasEditProvider = type(spec) == 'table' and spec.delta local params = { textDocument = util.make_text_document_params(self.bufnr) } - local method = ms.textDocument_semanticTokens_full + local method = 'textDocument/semanticTokens/full' if hasEditProvider and current_result.result_id then method = method .. '/delta' params.previousResultId = current_result.result_id end + ---@cast method vim.lsp.protocol.Method.ClientToServer.Request ---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta local success, request_id = client:request(method, params, function(err, response, ctx) -- look client up again using ctx.client_id instead of using a captured diff --git a/src/gen/gen_lsp.lua b/src/gen/gen_lsp.lua index 23dd59d842..39a3588051 100755 --- a/src/gen/gen_lsp.lua +++ b/src/gen/gen_lsp.lua @@ -179,6 +179,7 @@ local function write_to_vim_protocol(protocol) '--- | vim.lsp.protocol.Method.ServerToClient', '', '-- Generated by gen_lsp.lua, keep at end of file.', + '--- @deprecated', '--- @enum vim.lsp.protocol.Methods', '--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel', '--- LSP method names.', diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index b946caa142..f26f088010 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -211,7 +211,7 @@ describe('vim.lsp.diagnostic', function() diagnosticProvider = {}, }, handlers = { - [vim.lsp.protocol.Methods.textDocument_diagnostic] = function(_, params) + ['textDocument/diagnostic'] = function(_, params) _G.params = params _G.requests = _G.requests + 1 end, @@ -421,7 +421,7 @@ describe('vim.lsp.diagnostic', function() data = {}, message = '', }, {}, { - method = vim.lsp.protocol.Methods.textDocument_diagnostic, + method = 'textDocument/diagnostic', client_id = client_id, bufnr = diagnostic_bufnr, }) @@ -438,7 +438,7 @@ describe('vim.lsp.diagnostic', function() data = { retriggerRequest = true }, message = '', }, {}, { - method = vim.lsp.protocol.Methods.textDocument_diagnostic, + method = 'textDocument/diagnostic', client_id = client_id, bufnr = diagnostic_bufnr, }) @@ -455,7 +455,7 @@ describe('vim.lsp.diagnostic', function() data = { retriggerRequest = false }, message = '', }, {}, { - method = vim.lsp.protocol.Methods.textDocument_diagnostic, + method = 'textDocument/diagnostic', client_id = client_id, bufnr = diagnostic_bufnr, }) @@ -477,7 +477,7 @@ describe('vim.lsp.diagnostic', function() _G.make_error('Pull Diagnostic', 4, 4, 4, 4), }, }, { - method = vim.lsp.protocol.Methods.textDocument_diagnostic, + method = 'textDocument/diagnostic', params = { textDocument = { uri = fake_uri }, }, @@ -487,7 +487,7 @@ describe('vim.lsp.diagnostic', function() vim.api.nvim_exec_autocmds('LspNotify', { buffer = diagnostic_bufnr, data = { - method = vim.lsp.protocol.Methods.textDocument_didChange, + method = 'textDocument/didChange', client_id = client_id, }, }) @@ -503,7 +503,7 @@ describe('vim.lsp.diagnostic', function() kind = 'unchanged', resultId = 'squidward', }, { - method = vim.lsp.protocol.Methods.textDocument_diagnostic, + method = 'textDocument/diagnostic', params = { textDocument = { uri = fake_uri }, }, @@ -513,7 +513,7 @@ describe('vim.lsp.diagnostic', function() vim.api.nvim_exec_autocmds('LspNotify', { buffer = diagnostic_bufnr, data = { - method = vim.lsp.protocol.Methods.textDocument_didChange, + method = 'textDocument/didChange', client_id = client_id, }, }) @@ -560,7 +560,7 @@ describe('vim.lsp.diagnostic', function() vim.api.nvim_exec_autocmds('LspNotify', { buffer = second_buf, data = { - method = vim.lsp.protocol.Methods.textDocument_didChange, + method = 'textDocument/didChange', client_id = client_id, }, })