diff options
author | Christian Clason <c.clason@uni-graz.at> | 2022-07-07 18:27:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-07 18:27:18 +0200 |
commit | aa4f9c5341f5280f16cce0630ea54b84eef717b3 (patch) | |
tree | 52e82a04b3f364f50b810c92c0e0a3378ccd17a0 /runtime/lua/vim/lsp | |
parent | 34d41baf8a8e4ab8c006b7f29a8106e60e311aa2 (diff) | |
download | rneovim-aa4f9c5341f5280f16cce0630ea54b84eef717b3.tar.gz rneovim-aa4f9c5341f5280f16cce0630ea54b84eef717b3.tar.bz2 rneovim-aa4f9c5341f5280f16cce0630ea54b84eef717b3.zip |
refactor(lua): reformat with stylua 0.14.0 (#19264)
* reformat Lua runtime to make lint CI pass
* reduce max line length to 100
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r-- | runtime/lua/vim/lsp/_snippet.lua | 71 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 35 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 25 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 24 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/health.lua | 7 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/log.lua | 9 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 9 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/rpc.lua | 46 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/sync.lua | 49 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/tagfunc.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 95 |
11 files changed, 295 insertions, 78 deletions
diff --git a/runtime/lua/vim/lsp/_snippet.lua b/runtime/lua/vim/lsp/_snippet.lua index 910deba556..3488639fb4 100644 --- a/runtime/lua/vim/lsp/_snippet.lua +++ b/runtime/lua/vim/lsp/_snippet.lua @@ -255,7 +255,13 @@ S.format = P.any( S.int, S.colon, S.slash, - P.any(P.token('upcase'), P.token('downcase'), P.token('capitalize'), P.token('camelcase'), P.token('pascalcase')), + P.any( + P.token('upcase'), + P.token('downcase'), + P.token('capitalize'), + P.token('camelcase'), + P.token('pascalcase') + ), S.close ), function(values) @@ -272,7 +278,12 @@ S.format = P.any( S.open, S.int, S.colon, - P.seq(S.question, P.opt(P.take_until({ ':' }, { '\\' })), S.colon, P.opt(P.take_until({ '}' }, { '\\' }))), + P.seq( + S.question, + P.opt(P.take_until({ ':' }, { '\\' })), + S.colon, + P.opt(P.take_until({ '}' }, { '\\' })) + ), S.close ), function(values) @@ -285,7 +296,14 @@ S.format = P.any( end ), P.map( - P.seq(S.dollar, S.open, S.int, S.colon, P.seq(S.plus, P.opt(P.take_until({ '}' }, { '\\' }))), S.close), + P.seq( + S.dollar, + S.open, + S.int, + S.colon, + P.seq(S.plus, P.opt(P.take_until({ '}' }, { '\\' }))), + S.close + ), function(values) return setmetatable({ type = Node.Type.FORMAT, @@ -296,7 +314,15 @@ S.format = P.any( end ), P.map( - P.seq(S.dollar, S.open, S.int, S.colon, S.minus, P.opt(P.take_until({ '}' }, { '\\' })), S.close), + P.seq( + S.dollar, + S.open, + S.int, + S.colon, + S.minus, + P.opt(P.take_until({ '}' }, { '\\' })), + S.close + ), function(values) return setmetatable({ type = Node.Type.FORMAT, @@ -306,14 +332,17 @@ S.format = P.any( }, Node) end ), - P.map(P.seq(S.dollar, S.open, S.int, S.colon, P.opt(P.take_until({ '}' }, { '\\' })), S.close), function(values) - return setmetatable({ - type = Node.Type.FORMAT, - capture_index = values[3], - if_text = '', - else_text = values[5] and values[5].esc or '', - }, Node) - end) + P.map( + P.seq(S.dollar, S.open, S.int, S.colon, P.opt(P.take_until({ '}' }, { '\\' })), S.close), + function(values) + return setmetatable({ + type = Node.Type.FORMAT, + capture_index = values[3], + if_text = '', + else_text = values[5] and values[5].esc or '', + }, Node) + end + ) ) S.transform = P.map( @@ -359,7 +388,14 @@ S.tabstop = P.any( S.placeholder = P.any( P.map( - P.seq(S.dollar, S.open, S.int, S.colon, P.opt(P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' })))), S.close), + P.seq( + S.dollar, + S.open, + S.int, + S.colon, + P.opt(P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' })))), + S.close + ), function(values) return setmetatable({ type = Node.Type.PLACEHOLDER, @@ -419,7 +455,14 @@ S.variable = P.any( }, Node) end), P.map( - P.seq(S.dollar, S.open, S.var, S.colon, P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' }))), S.close), + P.seq( + S.dollar, + S.open, + S.var, + S.colon, + P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' }))), + S.close + ), function(values) return setmetatable({ type = Node.Type.VARIABLE, diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 97c30bc46a..981aebada1 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -228,7 +228,8 @@ function M.format(options) end local params = util.make_formatting_params(options.formatting_options) client.request('textDocument/formatting', params, function(...) - local handler = client.handlers['textDocument/formatting'] or vim.lsp.handlers['textDocument/formatting'] + local handler = client.handlers['textDocument/formatting'] + or vim.lsp.handlers['textDocument/formatting'] handler(...) do_format(next(clients, idx)) end, bufnr) @@ -284,7 +285,10 @@ end ---@param timeout_ms (number) Request timeout ---@see |vim.lsp.buf.formatting_seq_sync| function M.formatting_sync(options, timeout_ms) - vim.notify_once('vim.lsp.buf.formatting_sync is deprecated. Use vim.lsp.buf.format instead', vim.log.levels.WARN) + vim.notify_once( + 'vim.lsp.buf.formatting_sync is deprecated. Use vim.lsp.buf.format instead', + vim.log.levels.WARN + ) local params = util.make_formatting_params(options) local bufnr = vim.api.nvim_get_current_buf() select_client('textDocument/formatting', function(client) @@ -318,7 +322,10 @@ end ---in the following order: first all clients that are not in the `order` list, then ---the remaining clients in the order as they occur in the `order` list. function M.formatting_seq_sync(options, timeout_ms, order) - vim.notify_once('vim.lsp.buf.formatting_seq_sync is deprecated. Use vim.lsp.buf.format instead', vim.log.levels.WARN) + vim.notify_once( + 'vim.lsp.buf.formatting_seq_sync is deprecated. Use vim.lsp.buf.format instead', + vim.log.levels.WARN + ) local clients = vim.tbl_values(vim.lsp.buf_get_clients()) local bufnr = vim.api.nvim_get_current_buf() @@ -346,7 +353,10 @@ function M.formatting_seq_sync(options, timeout_ms, order) if result and result.result then util.apply_text_edits(result.result, bufnr, client.offset_encoding) elseif err then - vim.notify(string.format('vim.lsp.buf.formatting_seq_sync: (%s) %s', client.name, err), vim.log.levels.WARN) + vim.notify( + string.format('vim.lsp.buf.formatting_seq_sync: (%s) %s', client.name, err), + vim.log.levels.WARN + ) end end end @@ -429,7 +439,8 @@ function M.rename(new_name, options) local function rename(name) local params = util.make_position_params(win, client.offset_encoding) params.newName = name - local handler = client.handlers['textDocument/rename'] or vim.lsp.handlers['textDocument/rename'] + local handler = client.handlers['textDocument/rename'] + or vim.lsp.handlers['textDocument/rename'] client.request('textDocument/rename', params, function(...) handler(...) try_use_client(next(clients, idx)) @@ -443,7 +454,8 @@ function M.rename(new_name, options) if next(clients, idx) then try_use_client(next(clients, idx)) else - local msg = err and ('Error on prepareRename: ' .. (err.message or '')) or 'Nothing to rename' + local msg = err and ('Error on prepareRename: ' .. (err.message or '')) + or 'Nothing to rename' vim.notify(msg, vim.log.levels.INFO) end return @@ -475,7 +487,10 @@ function M.rename(new_name, options) end) end, bufnr) else - assert(client.supports_method('textDocument/rename'), 'Client must support textDocument/rename') + assert( + client.supports_method('textDocument/rename'), + 'Client must support textDocument/rename' + ) if new_name then rename(new_name) return @@ -587,7 +602,8 @@ end --- Add the folder at path to the workspace folders. If {path} is --- not provided, the user will be prompted for a path using |input()|. function M.add_workspace_folder(workspace_folder) - workspace_folder = workspace_folder or npcall(vfn.input, 'Workspace Folder: ', vfn.expand('%:p:h'), 'dir') + workspace_folder = workspace_folder + or npcall(vfn.input, 'Workspace Folder: ', vfn.expand('%:p:h'), 'dir') vim.api.nvim_command('redraw') if not (workspace_folder and #workspace_folder > 0) then return @@ -623,7 +639,8 @@ end --- {path} is not provided, the user will be prompted for --- a path using |input()|. function M.remove_workspace_folder(workspace_folder) - workspace_folder = workspace_folder or npcall(vfn.input, 'Workspace Folder: ', vfn.expand('%:p:h')) + workspace_folder = workspace_folder + or npcall(vfn.input, 'Workspace Folder: ', vfn.expand('%:p:h')) vim.api.nvim_command('redraw') if not (workspace_folder and #workspace_folder > 0) then return diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 126be2a0ad..0851c080bc 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -302,7 +302,9 @@ function M.get(bufnr, client_id, predicate) end local namespace = M.get_namespace(client_id) - return diagnostic_vim_to_lsp(vim.tbl_filter(predicate, vim.diagnostic.get(bufnr, { namespace = namespace }))) + return diagnostic_vim_to_lsp( + vim.tbl_filter(predicate, vim.diagnostic.get(bufnr, { namespace = namespace })) + ) end --- Get the diagnostics by line @@ -483,7 +485,12 @@ function M.set_signs(diagnostics, bufnr, client_id, _, opts) opts.severity = { min = severity_lsp_to_vim(opts.severity_limit) } end - vim.diagnostic._set_signs(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts) + vim.diagnostic._set_signs( + namespace, + bufnr, + diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), + opts + ) end --- Set underline for given diagnostics @@ -503,7 +510,12 @@ function M.set_underline(diagnostics, bufnr, client_id, _, opts) if opts and not opts.severity and opts.severity_limit then opts.severity = { min = severity_lsp_to_vim(opts.severity_limit) } end - return vim.diagnostic._set_underline(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts) + return vim.diagnostic._set_underline( + namespace, + bufnr, + diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), + opts + ) end --- Set virtual text given diagnostics @@ -525,7 +537,12 @@ function M.set_virtual_text(diagnostics, bufnr, client_id, _, opts) if opts and not opts.severity and opts.severity_limit then opts.severity = { min = severity_lsp_to_vim(opts.severity_limit) } end - return vim.diagnostic._set_virtual_text(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts) + return vim.diagnostic._set_virtual_text( + namespace, + bufnr, + diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), + opts + ) end --- Default function to get text chunks to display using |nvim_buf_set_extmark()|. diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 935f4b64f8..8a64e64396 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -125,7 +125,8 @@ M['workspace/applyEdit'] = function(_, workspace_edit, ctx) if workspace_edit.label then print('Workspace edit', workspace_edit.label) end - local status, result = pcall(util.apply_workspace_edit, workspace_edit.edit, client.offset_encoding) + local status, result = + pcall(util.apply_workspace_edit, workspace_edit.edit, client.offset_encoding) return { applied = status, failureReason = result, @@ -137,7 +138,11 @@ M['workspace/configuration'] = function(_, result, ctx) local client_id = ctx.client_id local client = vim.lsp.get_client_by_id(client_id) if not client then - err_message('LSP[', client_id, '] client has shut down after sending a workspace/configuration request') + err_message( + 'LSP[', + client_id, + '] client has shut down after sending a workspace/configuration request' + ) return end if not result.items then @@ -239,10 +244,14 @@ local function response_to_list(map_result, entity, title_fn) end --see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol -M['textDocument/documentSymbol'] = response_to_list(util.symbols_to_items, 'document symbols', function(ctx) - local fname = vim.fn.fnamemodify(vim.uri_to_fname(ctx.params.textDocument.uri), ':.') - return string.format('Symbols in %s', fname) -end) +M['textDocument/documentSymbol'] = response_to_list( + util.symbols_to_items, + 'document symbols', + function(ctx) + local fname = vim.fn.fnamemodify(vim.uri_to_fname(ctx.params.textDocument.uri), ':.') + return string.format('Symbols in %s', fname) + end +) --see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol M['workspace/symbol'] = response_to_list(util.symbols_to_items, 'symbols', function(ctx) @@ -391,7 +400,8 @@ function M.signature_help(_, result, ctx, config) return end local client = vim.lsp.get_client_by_id(ctx.client_id) - local triggers = vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters') + local triggers = + vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters') local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype') local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers) lines = util.trim_empty_lines(lines) diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua index bf8fe0932e..ba730e3d6d 100644 --- a/runtime/lua/vim/lsp/health.lua +++ b/runtime/lua/vim/lsp/health.lua @@ -11,7 +11,12 @@ function M.check() report_info(string.format('LSP log level : %s', log_level_string)) if current_log_level < log.levels.WARN then - report_warn(string.format('Log level %s will cause degraded performance and high disk usage', log_level_string)) + report_warn( + string.format( + 'Log level %s will cause degraded performance and high disk usage', + log_level_string + ) + ) end local log_path = vim.lsp.get_log_path() diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua index 29cb27d373..6c6ba0f206 100644 --- a/runtime/lua/vim/lsp/log.lua +++ b/runtime/lua/vim/lsp/log.lua @@ -59,7 +59,11 @@ do local log_info = vim.loop.fs_stat(logfilename) if log_info and log_info.size > 1e9 then - local warn_msg = string.format('LSP client log is large (%d MB): %s', log_info.size / (1000 * 1000), logfilename) + local warn_msg = string.format( + 'LSP client log is large (%d MB): %s', + log_info.size / (1000 * 1000), + logfilename + ) vim.notify(warn_msg) end @@ -129,7 +133,8 @@ vim.tbl_add_reverse_lookup(log.levels) ---@param level (string or number) One of `vim.lsp.log.levels` function log.set_level(level) if type(level) == 'string' then - current_log_level = assert(log.levels[level:upper()], string.format('Invalid log level: %q', level)) + current_log_level = + assert(log.levels[level:upper()], string.format('Invalid log level: %q', level)) else assert(type(level) == 'number', 'level must be a number or string') assert(log.levels[level], string.format('Invalid log level: %d', level)) diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 6ecf7891c7..6ecb9959d5 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -880,7 +880,8 @@ function protocol._resolve_capabilities_compat(server_capabilities) general_properties.document_symbol = server_capabilities.documentSymbolProvider or false general_properties.workspace_symbol = server_capabilities.workspaceSymbolProvider or false general_properties.document_formatting = server_capabilities.documentFormattingProvider or false - general_properties.document_range_formatting = server_capabilities.documentRangeFormattingProvider or false + general_properties.document_range_formatting = server_capabilities.documentRangeFormattingProvider + or false general_properties.call_hierarchy = server_capabilities.callHierarchyProvider or false general_properties.execute_command = server_capabilities.executeCommandProvider ~= nil @@ -897,7 +898,8 @@ function protocol._resolve_capabilities_compat(server_capabilities) general_properties.code_lens_resolve = false elseif type(server_capabilities.codeLensProvider) == 'table' then general_properties.code_lens = true - general_properties.code_lens_resolve = server_capabilities.codeLensProvider.resolveProvider or false + general_properties.code_lens_resolve = server_capabilities.codeLensProvider.resolveProvider + or false else error('The server sent invalid codeLensProvider') end @@ -974,7 +976,8 @@ function protocol._resolve_capabilities_compat(server_capabilities) signature_help_properties = { signature_help = true, -- The characters that trigger signature help automatically. - signature_help_trigger_characters = server_capabilities.signatureHelpProvider.triggerCharacters or {}, + signature_help_trigger_characters = server_capabilities.signatureHelpProvider.triggerCharacters + or {}, } else error('The server sent invalid signatureHelpProvider') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index ad2498fb6f..cf74dd2b47 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -115,7 +115,8 @@ local function request_parser_loop() local body_length = #body_chunks[1] -- Keep waiting for data until we have enough. while body_length < content_length do - local chunk = coroutine.yield() or error('Expected more data for the body. The server may have died.') -- TODO hmm. + local chunk = coroutine.yield() + or error('Expected more data for the body. The server may have died.') -- TODO hmm. table.insert(body_chunks, chunk) body_length = body_length + #chunk end @@ -129,10 +130,16 @@ local function request_parser_loop() local body = table.concat(body_chunks) -- Yield our data. buffer = rest - .. (coroutine.yield(headers, body) or error('Expected more data for the body. The server may have died.')) -- TODO hmm. + .. ( + coroutine.yield(headers, body) + or error('Expected more data for the body. The server may have died.') + ) -- TODO hmm. else -- Get more data since we don't have enough. - buffer = buffer .. (coroutine.yield() or error('Expected more data for the header. The server may have died.')) -- TODO hmm. + buffer = buffer + .. ( + coroutine.yield() or error('Expected more data for the header. The server may have died.') + ) -- TODO hmm. end end end @@ -262,7 +269,8 @@ end --- - {handle} A handle for low-level interaction with the LSP server process --- |vim.loop|. local function start(cmd, cmd_args, dispatchers, extra_spawn_params) - local _ = log.info() and log.info('Starting RPC client', { cmd = cmd, args = cmd_args, extra = extra_spawn_params }) + local _ = log.info() + and log.info('Starting RPC client', { cmd = cmd, args = cmd_args, extra = extra_spawn_params }) validate({ cmd = { cmd, 's' }, cmd_args = { cmd_args, 't' }, @@ -336,7 +344,8 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) if handle == nil then local msg = string.format('Spawning language server with cmd: `%s` failed', cmd) if string.match(pid, 'ENOENT') then - msg = msg .. '. The language server is either not installed, missing from PATH, or not executable.' + msg = msg + .. '. The language server is either not installed, missing from PATH, or not executable.' else msg = msg .. string.format(' with error message: %s', pid) end @@ -476,7 +485,10 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) decoded.params ) local _ = log.debug() - and log.debug('server_request: callback result', { status = status, result = result, err = err }) + and log.debug( + 'server_request: callback result', + { status = status, result = result, err = err } + ) if status then if not (result or err) then -- TODO this can be a problem if `null` is sent for result. needs vim.NIL @@ -488,7 +500,10 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) ) end if err then - assert(type(err) == 'table', 'err must be a table. Use rpc_response_error to help format errors.') + assert( + type(err) == 'table', + 'err must be a table. Use rpc_response_error to help format errors.' + ) local code_name = assert( protocol.ErrorCodes[err.code], 'Errors must use protocol.ErrorCodes. Use rpc_response_error to help format errors.' @@ -549,14 +564,25 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) __tostring = format_rpc_error, }) end - try_call(client_errors.SERVER_RESULT_CALLBACK_ERROR, callback, decoded.error, decoded.result) + try_call( + client_errors.SERVER_RESULT_CALLBACK_ERROR, + callback, + decoded.error, + decoded.result + ) else on_error(client_errors.NO_RESULT_CALLBACK_FOUND, decoded) - local _ = log.error() and log.error('No callback found for server response id ' .. result_id) + local _ = log.error() + and log.error('No callback found for server response id ' .. result_id) end elseif type(decoded.method) == 'string' then -- Notification - try_call(client_errors.NOTIFICATION_HANDLER_ERROR, dispatchers.notification, decoded.method, decoded.params) + try_call( + client_errors.NOTIFICATION_HANDLER_ERROR, + dispatchers.notification, + decoded.method, + decoded.params + ) else -- Invalid server message on_error(client_errors.INVALID_SERVER_MESSAGE, decoded) diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua index 73b4e0025a..0d65e86b55 100644 --- a/runtime/lua/vim/lsp/sync.lua +++ b/runtime/lua/vim/lsp/sync.lua @@ -130,7 +130,14 @@ end ---@param new_lastline integer new_lastline from on_lines, adjusted to 1-index ---@param offset_encoding string utf-8|utf-16|utf-32|nil (fallback to utf-8) ---@returns table<int, int> line_idx, byte_idx, and char_idx of first change position -local function compute_start_range(prev_lines, curr_lines, firstline, lastline, new_lastline, offset_encoding) +local function compute_start_range( + prev_lines, + curr_lines, + firstline, + lastline, + new_lastline, + offset_encoding +) local char_idx local byte_idx -- If firstline == lastline, no existing text is changed. All edit operations @@ -249,13 +256,19 @@ local function compute_end_range( local max_length if start_line_idx == prev_line_idx then -- Search until beginning of difference - max_length = min(prev_line_length - start_range.byte_idx, curr_line_length - start_range.byte_idx) + 1 + max_length = min( + prev_line_length - start_range.byte_idx, + curr_line_length - start_range.byte_idx + ) + 1 else max_length = min(prev_line_length, curr_line_length) + 1 end for idx = 0, max_length do byte_offset = idx - if str_byte(prev_line, prev_line_length - byte_offset) ~= str_byte(curr_line, curr_line_length - byte_offset) then + if + str_byte(prev_line, prev_line_length - byte_offset) + ~= str_byte(curr_line, curr_line_length - byte_offset) + then break end end @@ -268,8 +281,10 @@ local function compute_end_range( if prev_end_byte_idx == 0 then prev_end_byte_idx = 1 end - local prev_byte_idx, prev_char_idx = align_end_position(prev_line, prev_end_byte_idx, offset_encoding) - local prev_end_range = { line_idx = prev_line_idx, byte_idx = prev_byte_idx, char_idx = prev_char_idx } + local prev_byte_idx, prev_char_idx = + align_end_position(prev_line, prev_end_byte_idx, offset_encoding) + local prev_end_range = + { line_idx = prev_line_idx, byte_idx = prev_byte_idx, char_idx = prev_char_idx } local curr_end_range -- Deletion event, new_range cannot be before start @@ -281,8 +296,10 @@ local function compute_end_range( if curr_end_byte_idx == 0 then curr_end_byte_idx = 1 end - local curr_byte_idx, curr_char_idx = align_end_position(curr_line, curr_end_byte_idx, offset_encoding) - curr_end_range = { line_idx = curr_line_idx, byte_idx = curr_byte_idx, char_idx = curr_char_idx } + local curr_byte_idx, curr_char_idx = + align_end_position(curr_line, curr_end_byte_idx, offset_encoding) + curr_end_range = + { line_idx = curr_line_idx, byte_idx = curr_byte_idx, char_idx = curr_char_idx } end return prev_end_range, curr_end_range @@ -341,7 +358,10 @@ local function compute_range_length(lines, start_range, end_range, offset_encodi local start_line = lines[start_range.line_idx] local range_length if start_line and #start_line > 0 then - range_length = compute_line_length(start_line, offset_encoding) - start_range.char_idx + 1 + line_ending_length + range_length = compute_line_length(start_line, offset_encoding) + - start_range.char_idx + + 1 + + line_ending_length else -- Length of newline character range_length = line_ending_length @@ -373,7 +393,15 @@ end ---@param new_lastline number line to begin search in new_lines for last difference ---@param offset_encoding string encoding requested by language server ---@returns table TextDocumentContentChangeEvent see https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocumentContentChangeEvent -function M.compute_diff(prev_lines, curr_lines, firstline, lastline, new_lastline, offset_encoding, line_ending) +function M.compute_diff( + prev_lines, + curr_lines, + firstline, + lastline, + new_lastline, + offset_encoding, + line_ending +) -- Find the start of changes between the previous and current buffer. Common between both. -- Sent to the server as the start of the changed range. -- Used to grab the changed text from the latest buffer. @@ -403,7 +431,8 @@ function M.compute_diff(prev_lines, curr_lines, firstline, lastline, new_lastlin local text = extract_text(curr_lines, start_range, curr_end_range, line_ending) -- Compute the range of the replaced text. Deprecated but still required for certain language servers - local range_length = compute_range_length(prev_lines, start_range, prev_end_range, offset_encoding, line_ending) + local range_length = + compute_range_length(prev_lines, start_range, prev_end_range, offset_encoding, line_ending) -- convert to 0 based indexing local result = { diff --git a/runtime/lua/vim/lsp/tagfunc.lua b/runtime/lua/vim/lsp/tagfunc.lua index 5c55e8559f..f0ae6a6c49 100644 --- a/runtime/lua/vim/lsp/tagfunc.lua +++ b/runtime/lua/vim/lsp/tagfunc.lua @@ -44,7 +44,8 @@ end ---@private local function query_workspace_symbols(pattern) - local results_by_client, err = lsp.buf_request_sync(0, 'workspace/symbol', { query = pattern }, 1000) + local results_by_client, err = + lsp.buf_request_sync(0, 'workspace/symbol', { query = pattern }, 1000) if err then return {} end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index b041385c9c..b10f0e82f2 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -44,12 +44,22 @@ local function get_border_size(opts) shadow = { 1, 1 }, } if border_size[border] == nil then - error(string.format('invalid floating preview border: %s. :help vim.api.nvim_open_win()', vim.inspect(border))) + error( + string.format( + 'invalid floating preview border: %s. :help vim.api.nvim_open_win()', + vim.inspect(border) + ) + ) end height, width = unpack(border_size[border]) else if 8 % #border ~= 0 then - error(string.format('invalid floating preview border: %s. :help vim.api.nvim_open_win()', vim.inspect(border))) + error( + string.format( + 'invalid floating preview border: %s. :help vim.api.nvim_open_win()', + vim.inspect(border) + ) + ) end ---@private local function border_width(id) @@ -61,7 +71,12 @@ local function get_border_size(opts) -- border specified as a list of border characters return vim.fn.strdisplaywidth(border[id]) end - error(string.format('invalid floating preview border: %s. :help vim.api.nvim_open_win()', vim.inspect(border))) + error( + string.format( + 'invalid floating preview border: %s. :help vim.api.nvim_open_win()', + vim.inspect(border) + ) + ) end ---@private local function border_height(id) @@ -73,7 +88,12 @@ local function get_border_size(opts) -- border specified as a list of border characters return #border[id] > 0 and 1 or 0 end - error(string.format('invalid floating preview border: %s. :help vim.api.nvim_open_win()', vim.inspect(border))) + error( + string.format( + 'invalid floating preview border: %s. :help vim.api.nvim_open_win()', + vim.inspect(border) + ) + ) end height = height + border_height(2) -- top height = height + border_height(6) -- bottom @@ -531,7 +551,10 @@ function M.apply_text_document_edit(text_document_edit, index, offset_encoding) local text_document = text_document_edit.textDocument local bufnr = vim.uri_to_bufnr(text_document.uri) if offset_encoding == nil then - vim.notify_once('apply_text_document_edit must be called with valid offset encoding', vim.log.levels.WARN) + vim.notify_once( + 'apply_text_document_edit must be called with valid offset encoding', + vim.log.levels.WARN + ) end -- For lists of text document edits, @@ -765,7 +788,10 @@ end --see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit function M.apply_workspace_edit(workspace_edit, offset_encoding) if offset_encoding == nil then - vim.notify_once('apply_workspace_edit must be called with valid offset encoding', vim.log.levels.WARN) + vim.notify_once( + 'apply_workspace_edit must be called with valid offset encoding', + vim.log.levels.WARN + ) end if workspace_edit.documentChanges then for idx, change in ipairs(workspace_edit.documentChanges) do @@ -1022,7 +1048,10 @@ function M.jump_to_location(location, offset_encoding, reuse_win) return end if offset_encoding == nil then - vim.notify_once('jump_to_location must be called with valid offset encoding', vim.log.levels.WARN) + vim.notify_once( + 'jump_to_location must be called with valid offset encoding', + vim.log.levels.WARN + ) end local bufnr = vim.uri_to_bufnr(uri) -- Save position in jumplist @@ -1226,14 +1255,21 @@ function M.stylize_markdown(bufnr, contents, opts) -- strip any empty lines or separators prior to this separator in actual markdown if line:match('^---+$') then while - markdown_lines[#stripped] and (stripped[#stripped]:match('^%s*$') or stripped[#stripped]:match('^---+$')) + markdown_lines[#stripped] + and (stripped[#stripped]:match('^%s*$') or stripped[#stripped]:match('^---+$')) do markdown_lines[#stripped] = false table.remove(stripped, #stripped) end end -- add the line if its not an empty line following a separator - if not (line:match('^%s*$') and markdown_lines[#stripped] and stripped[#stripped]:match('^---+$')) then + if + not ( + line:match('^%s*$') + and markdown_lines[#stripped] + and stripped[#stripped]:match('^---+$') + ) + then table.insert(stripped, line) markdown_lines[#stripped] = true end @@ -1265,7 +1301,11 @@ function M.stylize_markdown(bufnr, contents, opts) local function apply_syntax_to_region(ft, start, finish) if ft == '' then vim.cmd( - string.format('syntax region markdownCode start=+\\%%%dl+ end=+\\%%%dl+ keepend extend', start, finish + 1) + string.format( + 'syntax region markdownCode start=+\\%%%dl+ end=+\\%%%dl+ keepend extend', + start, + finish + 1 + ) ) return end @@ -1283,7 +1323,13 @@ function M.stylize_markdown(bufnr, contents, opts) langs[lang] = true end vim.cmd( - string.format('syntax region %s start=+\\%%%dl+ end=+\\%%%dl+ contains=%s keepend', name, start, finish + 1, lang) + string.format( + 'syntax region %s start=+\\%%%dl+ end=+\\%%%dl+ contains=%s keepend', + name, + start, + finish + 1, + lang + ) ) end @@ -1587,15 +1633,21 @@ do --[[ References ]] offset_encoding = { offset_encoding, 'string', false }, }) for _, reference in ipairs(references) do - local start_line, start_char = reference['range']['start']['line'], reference['range']['start']['character'] - local end_line, end_char = reference['range']['end']['line'], reference['range']['end']['character'] + local start_line, start_char = + reference['range']['start']['line'], reference['range']['start']['character'] + local end_line, end_char = + reference['range']['end']['line'], reference['range']['end']['character'] local start_idx = get_line_byte_from_position( bufnr, { line = start_line, character = start_char }, offset_encoding ) - local end_idx = get_line_byte_from_position(bufnr, { line = start_line, character = end_char }, offset_encoding) + local end_idx = get_line_byte_from_position( + bufnr, + { line = start_line, character = end_char }, + offset_encoding + ) local document_highlight_kind = { [protocol.DocumentHighlightKind.Text] = 'LspReferenceText', @@ -1630,7 +1682,10 @@ end) ---@returns (table) list of items function M.locations_to_items(locations, offset_encoding) if offset_encoding == nil then - vim.notify_once('locations_to_items must be called with valid offset encoding', vim.log.levels.WARN) + vim.notify_once( + 'locations_to_items must be called with valid offset encoding', + vim.log.levels.WARN + ) end local items = {} @@ -1857,7 +1912,10 @@ function M._get_offset_encoding(bufnr) for _, client in pairs(vim.lsp.buf_get_clients(bufnr)) do if client.offset_encoding == nil then vim.notify_once( - string.format('Client (id: %s) offset_encoding is nil. Do not unset offset_encoding.', client.id), + string.format( + 'Client (id: %s) offset_encoding is nil. Do not unset offset_encoding.', + client.id + ), vim.log.levels.ERROR ) end @@ -1994,7 +2052,10 @@ end function M.character_offset(buf, row, col, offset_encoding) local line = get_line(buf, row) if offset_encoding == nil then - vim.notify_once('character_offset must be called with valid offset encoding', vim.log.levels.WARN) + vim.notify_once( + 'character_offset must be called with valid offset encoding', + vim.log.levels.WARN + ) end -- If the col is past the EOL, use the line length. if col > #line then |