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 | |
| 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')
24 files changed, 561 insertions, 179 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index f7dcc3a81b..7febad6ef6 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -739,7 +739,12 @@ function vim._cs_remote(rcid, server_addr, connect_error, args) f_tab = true elseif subcmd == 'silent' then f_silent = true - elseif subcmd == 'wait' or subcmd == 'wait-silent' or subcmd == 'tab-wait' or subcmd == 'tab-wait-silent' then + elseif + subcmd == 'wait' + or subcmd == 'wait-silent' + or subcmd == 'tab-wait' + or subcmd == 'tab-wait-silent' + then return { errmsg = 'E5600: Wait commands not yet implemented in nvim' } elseif subcmd == 'tab-silent' then f_tab = true @@ -795,7 +800,11 @@ function vim.deprecate(name, alternative, version, plugin, backtrace) local message = name .. ' is deprecated' plugin = plugin or 'Nvim' message = alternative and (message .. ', use ' .. alternative .. ' instead.') or message - message = message .. ' See :h deprecated\nThis function will be removed in ' .. plugin .. ' version ' .. version + message = message + .. ' See :h deprecated\nThis function will be removed in ' + .. plugin + .. ' version ' + .. version if vim.notify_once(message, vim.log.levels.WARN) and backtrace ~= false then vim.notify(debug.traceback('', 2):sub(2), vim.log.levels.WARN) end diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 715a7e5561..f1652718ee 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -102,9 +102,13 @@ do -- buffer option accessor if type(k) == 'string' then _setup() if win_options[k] then - error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k)) + error( + string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k) + ) elseif glb_options[k] then - error(string.format([['%s' is a global option, not a buffer option. See ":help %s"]], k, k)) + error( + string.format([['%s' is a global option, not a buffer option. See ":help %s"]], k, k) + ) end end @@ -132,9 +136,13 @@ do -- window option accessor if type(k) == 'string' then _setup() if buf_options[k] then - error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k)) + error( + string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k) + ) elseif glb_options[k] then - error(string.format([['%s' is a global option, not a window option. See ":help %s"]], k, k)) + error( + string.format([['%s' is a global option, not a window option. See ":help %s"]], k, k) + ) end end @@ -252,7 +260,12 @@ local function assert_valid_value(name, value, types) end error( - string.format("Invalid option type '%s' for '%s', should be %s", type_of_value, name, table.concat(types, ' or ')) + string.format( + "Invalid option type '%s' for '%s', should be %s", + type_of_value, + name, + table.concat(types, ' or ') + ) ) end diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index afc0a4095c..07a3c87da0 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -68,7 +68,10 @@ local all_namespaces = {} ---@private local function to_severity(severity) if type(severity) == 'string' then - return assert(M.severity[string.upper(severity)], string.format('Invalid severity: %s', severity)) + return assert( + M.severity[string.upper(severity)], + string.format('Invalid severity: %s', severity) + ) end return severity end @@ -277,7 +280,8 @@ local function set_diagnostic_cache(namespace, bufnr, diagnostics) for _, diagnostic in ipairs(diagnostics) do assert(diagnostic.lnum, 'Diagnostic line number is required') assert(diagnostic.col, 'Diagnostic column is required') - diagnostic.severity = diagnostic.severity and to_severity(diagnostic.severity) or M.severity.ERROR + diagnostic.severity = diagnostic.severity and to_severity(diagnostic.severity) + or M.severity.ERROR diagnostic.end_lnum = diagnostic.end_lnum or diagnostic.lnum diagnostic.end_col = diagnostic.end_col or diagnostic.col diagnostic.namespace = namespace @@ -322,13 +326,8 @@ local function save_extmarks(namespace, bufnr) }) diagnostic_attached_buffers[bufnr] = true end - diagnostic_cache_extmarks[bufnr][namespace] = vim.api.nvim_buf_get_extmarks( - bufnr, - namespace, - 0, - -1, - { details = true } - ) + diagnostic_cache_extmarks[bufnr][namespace] = + vim.api.nvim_buf_get_extmarks(bufnr, namespace, 0, -1, { details = true }) end local registered_autocmds = {} @@ -482,7 +481,8 @@ local function next_diagnostic(position, search_forward, bufnr, opts, namespace) bufnr = get_bufnr(bufnr) local wrap = vim.F.if_nil(opts.wrap, true) local line_count = vim.api.nvim_buf_line_count(bufnr) - local diagnostics = get_diagnostics(bufnr, vim.tbl_extend('keep', opts, { namespace = namespace }), true) + local diagnostics = + get_diagnostics(bufnr, vim.tbl_extend('keep', opts, { namespace = namespace }), true) local line_diagnostics = diagnostic_lines(diagnostics) for i = 0, line_count do local offset = i * (search_forward and 1 or -1) @@ -971,7 +971,10 @@ M.handlers.virtual_text = { if opts.virtual_text.format then diagnostics = reformat_diagnostics(opts.virtual_text.format, diagnostics) end - if opts.virtual_text.source and (opts.virtual_text.source ~= 'if_many' or count_sources(bufnr) > 1) then + if + opts.virtual_text.source + and (opts.virtual_text.source ~= 'if_many' or count_sources(bufnr) > 1) + then diagnostics = prefix_source(diagnostics) end if opts.virtual_text.severity then @@ -1279,7 +1282,9 @@ function M.open_float(opts, ...) -- LSP servers can send diagnostics with `end_col` past the length of the line local line_length = #vim.api.nvim_buf_get_lines(bufnr, lnum, lnum + 1, true)[1] diagnostics = vim.tbl_filter(function(d) - return d.lnum == lnum and math.min(d.col, line_length - 1) <= col and (d.end_col >= col or d.end_lnum > lnum) + return d.lnum == lnum + and math.min(d.col, line_length - 1) <= col + and (d.end_col >= col or d.end_lnum > lnum) end, diagnostics) end @@ -1333,9 +1338,10 @@ function M.open_float(opts, ...) diagnostics = prefix_source(diagnostics) end - local prefix_opt = if_nil(opts.prefix, (scope == 'cursor' and #diagnostics <= 1) and '' or function(_, i) - return string.format('%d. ', i) - end) + local prefix_opt = + if_nil(opts.prefix, (scope == 'cursor' and #diagnostics <= 1) and '' or function(_, i) + return string.format('%d. ', i) + end) local prefix, prefix_hl_group if prefix_opt then diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index df21fd46a1..fd47e12f07 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -176,7 +176,8 @@ local extension = { bsdl = 'bsdl', bst = 'bst', btm = function(path, bufnr) - return (vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0) and 'dosbatch' or 'btm' + return (vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0) and 'dosbatch' + or 'btm' end, bzl = 'bzl', bazel = 'bzl', @@ -2169,7 +2170,10 @@ local function sort_by_priority(t) local sorted = {} for k, v in pairs(t) do local ft = type(v) == 'table' and v[1] or v - assert(type(ft) == 'string' or type(ft) == 'function', 'Expected string or function for filetype') + assert( + type(ft) == 'string' or type(ft) == 'function', + 'Expected string or function for filetype' + ) local opts = (type(v) == 'table' and type(v[2]) == 'table') and v[2] or {} if not opts.priority then diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index fb36a502b0..8331920406 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -71,7 +71,8 @@ function M.asm_syntax(bufnr) end end -local visual_basic_content = { 'vb_name', 'begin vb%.form', 'begin vb%.mdiform', 'begin vb%.usercontrol' } +local visual_basic_content = + { 'vb_name', 'begin vb%.form', 'begin vb%.mdiform', 'begin vb%.usercontrol' } -- See frm() for Visual Basic form file detection function M.bas(bufnr) @@ -92,7 +93,11 @@ function M.bas(bufnr) for _, line in ipairs(getlines(bufnr, 1, 100)) do if findany(line:lower(), visual_basic_content) then return 'vb' - elseif line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then + elseif + line:find(fb_comment) + or matchregex(line, fb_preproc) + or matchregex(line, fb_keywords) + then return 'freebasic' elseif matchregex(line, qb64_preproc) then return 'qb64' @@ -236,7 +241,13 @@ local function cvs_diff(path, contents) elseif -- Locale input files: Formal Definitions of Cultural Conventions -- Filename must be like en_US, fr_FR@euro or en_US.UTF-8 - findany(path, { '%a%a_%a%a$', '%a%a_%a%a[%.@]', '%a%a_%a%ai18n$', '%a%a_%a%aPOSIX$', '%a%a_%a%atranslit_' }) + findany(path, { + '%a%a_%a%a$', + '%a%a_%a%a[%.@]', + '%a%a_%a%ai18n$', + '%a%a_%a%aPOSIX$', + '%a%a_%a%atranslit_', + }) then -- Only look at the first 100 lines for line_nr = 1, 100 do @@ -327,9 +338,11 @@ local function diff(contents) contents[1]:find('^%-%-%- ') and contents[2]:find('^%+%+%+ ') or contents[1]:find('^%* looking for ') and contents[2]:find('^%* comparing to ') or contents[1]:find('^%*%*%* ') and contents[2]:find('^%-%-%- ') - or contents[1]:find('^=== ') and ((contents[2]:find('^' .. string.rep('=', 66)) and contents[3]:find('^%-%-% ') and contents[4]:find( - '^%+%+%+' - )) or (contents[2]:find('^%-%-%- ') and contents[3]:find('^%+%+%+ '))) + or contents[1]:find('^=== ') and ((contents[2]:find('^' .. string.rep('=', 66)) and contents[3]:find( + '^%-%-% ' + ) and contents[4]:find('^%+%+%+')) or (contents[2]:find('^%-%-%- ') and contents[3]:find( + '^%+%+%+ ' + ))) or findany(contents[1], { '^=== removed', '^=== added', '^=== renamed', '^=== modified' }) then return 'diff' @@ -523,7 +536,8 @@ function M.idl(bufnr) end local pascal_comments = { '^%s*{', '^%s*%(%*', '^%s*//' } -local pascal_keywords = [[\c^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>]] +local pascal_keywords = + [[\c^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>]] function M.inc(bufnr) if vim.g.filetype_inc then @@ -574,9 +588,19 @@ end -- (refactor of filetype.vim since the patterns are case-insensitive) function M.log(path) path = path:lower() - if findany(path, { 'upstream%.log', 'upstream%..*%.log', '.*%.upstream%.log', 'upstream%-.*%.log' }) then + if + findany( + path, + { 'upstream%.log', 'upstream%..*%.log', '.*%.upstream%.log', 'upstream%-.*%.log' } + ) + then return 'upstreamlog' - elseif findany(path, { 'upstreaminstall%.log', 'upstreaminstall%..*%.log', '.*%.upstreaminstall%.log' }) then + elseif + findany( + path, + { 'upstreaminstall%.log', 'upstreaminstall%..*%.log', '.*%.upstreaminstall%.log' } + ) + then return 'upstreaminstalllog' elseif findany(path, { 'usserver%.log', 'usserver%..*%.log', '.*%.usserver%.log' }) then return 'usserverlog' @@ -616,7 +640,8 @@ function M.m(bufnr) -- Excluding end(for|function|if|switch|while) common to Murphi local octave_block_terminators = [[\<end\%(_try_catch\|classdef\|enumeration\|events\|methods\|parfor\|properties\)\>]] - local objc_preprocessor = [[\c^\s*#\s*\%(import\|include\|define\|if\|ifn\=def\|undef\|line\|error\|pragma\)\>]] + local objc_preprocessor = + [[\c^\s*#\s*\%(import\|include\|define\|if\|ifn\=def\|undef\|line\|error\|pragma\)\>]] -- Whether we've seen a multiline comment leader local saw_comment = false @@ -627,7 +652,11 @@ function M.m(bufnr) -- anything more definitive. saw_comment = true end - if line:find('^%s*//') or matchregex(line, [[\c^\s*@import\>]]) or matchregex(line, objc_preprocessor) then + if + line:find('^%s*//') + or matchregex(line, [[\c^\s*@import\>]]) + or matchregex(line, objc_preprocessor) + then return 'objc' end if @@ -869,7 +898,10 @@ function M.progress_cweb(bufnr) if vim.g.filetype_w then return vim.g.filetype_w else - if getlines(bufnr, 1):lower():find('^&analyze') or getlines(bufnr, 3):lower():find('^&global%-define') then + if + getlines(bufnr, 1):lower():find('^&analyze') + or getlines(bufnr, 3):lower():find('^&global%-define') + then return 'progress' else return 'cweb' @@ -914,10 +946,13 @@ end function M.psf(bufnr) local line = getlines(bufnr, 1):lower() if - findany( - line, - { '^%s*distribution%s*$', '^%s*installed_software%s*$', '^%s*root%s*$', '^%s*bundle%s*$', '^%s*product%s*$' } - ) + findany(line, { + '^%s*distribution%s*$', + '^%s*installed_software%s*$', + '^%s*root%s*$', + '^%s*bundle%s*$', + '^%s*product%s*$', + }) then return 'psf' end @@ -960,7 +995,9 @@ end function M.reg(bufnr) local line = getlines(bufnr, 1):lower() - if line:find('^regedit[0-9]*%s*$') or line:find('^windows registry editor version %d*%.%d*%s*$') then + if + line:find('^regedit[0-9]*%s*$') or line:find('^windows registry editor version %d*%.%d*%s*$') + then return 'registry' end end @@ -1033,10 +1070,15 @@ end function M.sc(bufnr) for _, line in ipairs(getlines(bufnr, 1, 25)) do if - findany( - line, - { '[A-Za-z0-9]*%s:%s[A-Za-z0-9]', 'var%s<', 'classvar%s<', '%^this.*', '|%w*|', '%+%s%w*%s{', '%*ar%s' } - ) + findany(line, { + '[A-Za-z0-9]*%s:%s[A-Za-z0-9]', + 'var%s<', + 'classvar%s<', + '%^this.*', + '|%w*|', + '%+%s%w*%s{', + '%*ar%s', + }) then return 'supercollider' end @@ -1062,10 +1104,11 @@ function M.sgml(bufnr) if lines:find('linuxdoc') then return 'smgllnx' elseif lines:find('<!DOCTYPE.*DocBook') then - return 'docbk', function(b) - vim.b[b].docbk_type = 'sgml' - vim.b[b].docbk_ver = 4 - end + return 'docbk', + function(b) + vim.b[b].docbk_type = 'sgml' + vim.b[b].docbk_ver = 4 + end else return 'sgml' end @@ -1194,7 +1237,8 @@ function M.tex(path, bufnr) if not l:find('^%s*%%%S') then -- Check the next thousand lines for a LaTeX or ConTeXt keyword. for _, line in ipairs(getlines(bufnr, i + 1, i + 1000)) do - local lpat_match, cpat_match = matchregex(line, [[\c^\s*\\\%(]] .. lpat .. [[\)\|^\s*\\\(]] .. cpat .. [[\)]]) + local lpat_match, cpat_match = + matchregex(line, [[\c^\s*\\\%(]] .. lpat .. [[\)\|^\s*\\\(]] .. cpat .. [[\)]]) if lpat_match then return 'tex' elseif cpat_match then @@ -1489,10 +1533,17 @@ local patterns_text = { -- Scheme scripts ['exec%s%+%S*scheme'] = { 'scheme', { start_lnum = 1, end_lnum = 2 } }, -- Git output - ['^\\(commit\\|tree\\|object\\) \\x\\{40,\\}\\>\\|^tag \\S\\+$'] = { 'git', { vim_regex = true } }, + ['^\\(commit\\|tree\\|object\\) \\x\\{40,\\}\\>\\|^tag \\S\\+$'] = { + 'git', + { vim_regex = true }, + }, function(lines) -- Gprof (gnu profiler) - if lines[1] == 'Flat profile:' and lines[2] == '' and lines[3]:find('^Each sample counts as .* seconds%.$') then + if + lines[1] == 'Flat profile:' + and lines[2] == '' + and lines[3]:find('^Each sample counts as .* seconds%.$') + then return 'gprof' end end, @@ -1515,7 +1566,12 @@ local function match_from_text(contents, path) if contents[1]:find('^:$') then -- Bourne-like shell scripts: sh ksh bash bash2 return M.sh(path, contents) - elseif matchregex('\n' .. table.concat(contents, '\n'), [[\n\s*emulate\s\+\%(-[LR]\s\+\)\=[ckz]\=sh\>]]) then + elseif + matchregex( + '\n' .. table.concat(contents, '\n'), + [[\n\s*emulate\s\+\%(-[LR]\s\+\)\=[ckz]\=sh\>]] + ) + then -- Z shell scripts return 'zsh' end @@ -1535,7 +1591,10 @@ local function match_from_text(contents, path) else local opts = type(v) == 'table' and v[2] or {} if opts.start_lnum and opts.end_lnum then - assert(not opts.ignore_case, 'ignore_case=true is ignored when start_lnum is also present, needs refactor') + assert( + not opts.ignore_case, + 'ignore_case=true is ignored when start_lnum is also present, needs refactor' + ) for i = opts.start_lnum, opts.end_lnum do if not contents[i] then break diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua index 6f9c48ca24..ce845eda15 100644 --- a/runtime/lua/vim/fs.lua +++ b/runtime/lua/vim/fs.lua @@ -61,7 +61,8 @@ end function M.dir(path) return function(fs) return vim.loop.fs_scandir_next(fs) - end, vim.loop.fs_scandir(M.normalize(path)) + end, + vim.loop.fs_scandir(M.normalize(path)) end --- Find files or directories in the given path. diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 36e3c2ad20..e72d45f11c 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -16,7 +16,14 @@ function M.create(higroup, hi_info, default) for k, v in pairs(hi_info) do table.insert(options, string.format('%s=%s', k, v)) end - vim.cmd(string.format([[highlight %s %s %s]], default and 'default' or '', higroup, table.concat(options, ' '))) + vim.cmd( + string.format( + [[highlight %s %s %s]], + default and 'default' or '', + higroup, + table.concat(options, ' ') + ) + ) end ---@private diff --git a/runtime/lua/vim/inspect.lua b/runtime/lua/vim/inspect.lua index c19e55fb37..0a53fb203b 100644 --- a/runtime/lua/vim/inspect.lua +++ b/runtime/lua/vim/inspect.lua @@ -80,7 +80,13 @@ for i = 0, 31 do end local function escape(str) - return (gsub(gsub(gsub(str, '\\', '\\\\'), '(%c)%f[0-9]', longControlCharEscapes), '%c', shortControlCharEscapes)) + return ( + gsub( + gsub(gsub(str, '\\', '\\\\'), '(%c)%f[0-9]', longControlCharEscapes), + '%c', + shortControlCharEscapes + ) + ) end local function isIdentifier(str) @@ -181,11 +187,13 @@ local function processRecursive(process, item, path, visited) for k, v in rawpairs(processed) do processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited) if processedKey ~= nil then - processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited) + processedCopy[processedKey] = + processRecursive(process, v, makePath(path, processedKey), visited) end end - local mt = processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited) + local mt = + processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited) if type(mt) ~= 'table' then mt = nil end diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 8bf736a2ca..75c3b63da7 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -200,7 +200,12 @@ local function validate_encoding(encoding) encoding = { encoding, 's' }, }) return valid_encodings[encoding:lower()] - or error(string.format("Invalid offset encoding %q. Must be one of: 'utf-8', 'utf-16', 'utf-32'", encoding)) + or error( + string.format( + "Invalid offset encoding %q. Must be one of: 'utf-8', 'utf-16', 'utf-32'", + encoding + ) + ) end ---@internal @@ -211,13 +216,15 @@ end ---@returns (string) the command ---@returns (list of strings) its arguments function lsp._cmd_parts(input) - vim.validate({ cmd = { - input, - function() - return vim.tbl_islist(input) - end, - 'list', - } }) + vim.validate({ + cmd = { + input, + function() + return vim.tbl_islist(input) + end, + 'list', + }, + }) local cmd = input[1] local cmd_args = {} @@ -274,7 +281,11 @@ local function validate_client_config(config) get_language_id = { config.get_language_id, 'f', true }, }) assert( - (not config.flags or not config.flags.debounce_text_changes or type(config.flags.debounce_text_changes) == 'number'), + ( + not config.flags + or not config.flags.debounce_text_changes + or type(config.flags.debounce_text_changes) == 'number' + ), 'flags.debounce_text_changes must be a number with the debounce time in milliseconds' ) @@ -474,7 +485,8 @@ do local uri = vim.uri_from_bufnr(bufnr) return function(client) if - vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change') == protocol.TextDocumentSyncKind.None + vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change') + == protocol.TextDocumentSyncKind.None then return end @@ -493,7 +505,8 @@ do if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then return end - local changes = state.use_incremental_sync and buf_state.pending_changes or { full_changes() } + local changes = state.use_incremental_sync and buf_state.pending_changes + or { full_changes() } client.notify('textDocument/didChange', { textDocument = { uri = uri, @@ -852,7 +865,8 @@ end --- the client has been initialized. function lsp.start_client(config) local cleaned_config = validate_client_config(config) - local cmd, cmd_args, offset_encoding = cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding + local cmd, cmd_args, offset_encoding = + cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding config.flags = config.flags or {} config.settings = config.settings or {} @@ -921,7 +935,8 @@ function lsp.start_client(config) ---@see |vim.lsp.rpc.client_errors| for possible errors. Use ---`vim.lsp.rpc.client_errors[code]` to get a human-friendly name. function dispatch.on_error(code, err) - local _ = log.error() and log.error(log_prefix, 'on_error', { code = lsp.client_errors[code], err = err }) + local _ = log.error() + and log.error(log_prefix, 'on_error', { code = lsp.client_errors[code], err = err }) err_message(log_prefix, ': Error ', lsp.client_errors[code], ': ', vim.inspect(err)) if config.on_error then local status, usererr = pcall(config.on_error, code, err) @@ -964,7 +979,8 @@ function lsp.start_client(config) changetracking.reset(client_id) if code ~= 0 or (signal ~= 0 and signal ~= 15) then - local msg = string.format('Client %s quit with exit code %s and signal %s', client_id, code, signal) + local msg = + string.format('Client %s quit with exit code %s and signal %s', client_id, code, signal) vim.schedule(function() vim.notify(msg, vim.log.levels.WARN) end) @@ -1082,7 +1098,8 @@ function lsp.start_client(config) -- These are the cleaned up capabilities we use for dynamically deciding -- when to send certain events to clients. - client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities") + client.server_capabilities = + assert(result.capabilities, "initialize result doesn't contain capabilities") client.server_capabilities = protocol.resolve_capabilities(client.server_capabilities) -- Deprecation wrapper: this will be removed in 0.8 @@ -1128,7 +1145,11 @@ function lsp.start_client(config) end end local _ = log.info() - and log.info(log_prefix, 'server_capabilities', { server_capabilities = client.server_capabilities }) + and log.info( + log_prefix, + 'server_capabilities', + { server_capabilities = client.server_capabilities } + ) -- Only assign after initialized. active_clients[client_id] = client @@ -1168,9 +1189,14 @@ function lsp.start_client(config) -- Ensure pending didChange notifications are sent so that the server doesn't operate on a stale state changetracking.flush(client, bufnr) bufnr = resolve_bufnr(bufnr) - local _ = log.debug() and log.debug(log_prefix, 'client.request', client_id, method, params, handler, bufnr) + local _ = log.debug() + and log.debug(log_prefix, 'client.request', client_id, method, params, handler, bufnr) local success, request_id = rpc.request(method, params, function(err, result) - handler(err, result, { method = method, client_id = client_id, bufnr = bufnr, params = params }) + handler( + err, + result, + { method = method, client_id = client_id, bufnr = bufnr, params = params } + ) end, function(request_id) client.requests[request_id] = nil nvim_command('doautocmd <nomodeline> User LspRequest') @@ -1322,15 +1348,17 @@ end --- Notify all attached clients that a buffer has changed. local text_document_did_change_handler do - text_document_did_change_handler = function(_, bufnr, changedtick, firstline, lastline, new_lastline) - -- Detach (nvim_buf_attach) via returning True to on_lines if no clients are attached - if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then - return true + text_document_did_change_handler = + function(_, bufnr, changedtick, firstline, lastline, new_lastline) + -- Detach (nvim_buf_attach) via returning True to on_lines if no clients are attached + if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then + return true + end + util.buf_versions[bufnr] = changedtick + local compute_change_and_notify = + changetracking.prepare(bufnr, firstline, lastline, new_lastline) + for_each_buffer_client(bufnr, compute_change_and_notify) end - util.buf_versions[bufnr] = changedtick - local compute_change_and_notify = changetracking.prepare(bufnr, firstline, lastline, new_lastline) - for_each_buffer_client(bufnr, compute_change_and_notify) - end end -- Buffer lifecycle handler for textDocument/didSave @@ -1369,7 +1397,8 @@ function lsp.buf_attach_client(bufnr, client_id) }) bufnr = resolve_bufnr(bufnr) if not vim.api.nvim_buf_is_loaded(bufnr) then - local _ = log.warn() and log.warn(string.format('buf_attach_client called on unloaded buffer (id: %d): ', bufnr)) + local _ = log.warn() + and log.warn(string.format('buf_attach_client called on unloaded buffer (id: %d): ', bufnr)) return false end local buffer_client_ids = all_buffer_active_clients[bufnr] @@ -1447,7 +1476,13 @@ function lsp.buf_detach_client(bufnr, client_id) local client = lsp.get_client_by_id(client_id) if not client or not client.attached_buffers[bufnr] then - vim.notify(string.format('Buffer (id: %d) is not attached to client (id: %d). Cannot detach.', client_id, bufnr)) + vim.notify( + string.format( + 'Buffer (id: %d) is not attached to client (id: %d). Cannot detach.', + client_id, + bufnr + ) + ) return end @@ -1548,10 +1583,14 @@ function lsp.get_active_clients(filter) local clients = {} - local t = filter.bufnr and (all_buffer_active_clients[resolve_bufnr(filter.bufnr)] or {}) or active_clients + local t = filter.bufnr and (all_buffer_active_clients[resolve_bufnr(filter.bufnr)] or {}) + or active_clients for client_id in pairs(t) do local client = active_clients[client_id] - if (filter.id == nil or client.id == filter.id) and (filter.name == nil or client.name == filter.name) then + if + (filter.id == nil or client.id == filter.id) + and (filter.name == nil or client.name == filter.name) + then clients[#clients + 1] = client end end @@ -1643,7 +1682,9 @@ function lsp.buf_request(bufnr, method, params, handler) end) -- if has client but no clients support the given method, notify the user - if not tbl_isempty(all_buffer_active_clients[resolve_bufnr(bufnr)] or {}) and not method_supported then + if + not tbl_isempty(all_buffer_active_clients[resolve_bufnr(bufnr)] or {}) and not method_supported + then vim.notify(lsp._unsupported_method(method), vim.log.levels.ERROR) vim.api.nvim_command('redraw') return {}, function() end @@ -1888,12 +1929,17 @@ function lsp.formatexpr(opts) }, } params.options = util.make_formatting_params().options - local client_results = vim.lsp.buf_request_sync(0, 'textDocume |