neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit c10e36fc016cb265026a772571ce0a405df2ab71
parent a33284c2c068a9204330bc941e274b1f5bd9f5c6
Author: Christian Clason <c.clason@uni-graz.at>
Date:   Tue, 26 Aug 2025 15:31:16 +0200

refactor(lua): consistent use of local aliases

Diffstat:
Mruntime/lua/man.lua | 6+++---
Mruntime/lua/vim/_comment.lua | 2+-
Mruntime/lua/vim/diagnostic.lua | 18+++++++++---------
Mruntime/lua/vim/fs.lua | 8++++----
Mruntime/lua/vim/hl.lua | 8++++----
Mruntime/lua/vim/loader.lua | 2+-
Mruntime/lua/vim/lsp.lua | 2+-
Mruntime/lua/vim/lsp/_changetracking.lua | 2+-
Mruntime/lua/vim/lsp/_folding_range.lua | 2+-
Mruntime/lua/vim/lsp/buf.lua | 6+++---
Mruntime/lua/vim/lsp/client.lua | 16++++++++--------
Mruntime/lua/vim/lsp/completion.lua | 2+-
Mruntime/lua/vim/lsp/diagnostic.lua | 2+-
Mruntime/lua/vim/lsp/document_color.lua | 2+-
Mruntime/lua/vim/lsp/inlay_hint.lua | 2+-
Mruntime/lua/vim/lsp/inline_completion.lua | 2+-
Mruntime/lua/vim/lsp/log.lua | 8++++----
Mruntime/lua/vim/lsp/rpc.lua | 4++--
Mruntime/lua/vim/lsp/semantic_tokens.lua | 2+-
Mruntime/lua/vim/lsp/sync.lua | 2+-
Mruntime/lua/vim/lsp/util.lua | 4++--
Mruntime/lua/vim/pack.lua | 2+-
Mruntime/lua/vim/treesitter/dev.lua | 4++--
Mruntime/lua/vim/treesitter/health.lua | 2+-
Mruntime/lua/vim/treesitter/language.lua | 2+-
Msrc/gen/gen_api_dispatch.lua | 2+-
Msrc/gen/gen_vimdoc.lua | 4++--
27 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua @@ -8,7 +8,7 @@ local M = {} --- @param env? table<string,string|number> --- @return string local function system(cmd, silent, env) - if vim.fn.executable(cmd[1]) == 0 then + if fn.executable(cmd[1]) == 0 then error(string.format('executable not found: "%s"', cmd[1]), 0) end @@ -651,10 +651,10 @@ function M.init_pager() -- Raw manpage into (:Man!) overlooks `match('man://')` condition, -- so if the buffer already exists, create new with a non existing name. - if vim.fn.bufexists(man_bufname) == 1 then + if fn.bufexists(man_bufname) == 1 then local new_bufname = man_bufname for i = 1, 100 do - if vim.fn.bufexists(new_bufname) == 0 then + if fn.bufexists(new_bufname) == 0 then break end new_bufname = ('%s?new=%s'):format(man_bufname, i) diff --git a/runtime/lua/vim/_comment.lua b/runtime/lua/vim/_comment.lua @@ -148,7 +148,7 @@ end ---@return fun(line: string): string local function make_comment_function(parts, indent) local prefix, nonindent_start, suffix = indent .. parts.left, indent:len() + 1, parts.right - local blank_comment = indent .. vim.trim(parts.left) .. vim.trim(parts.right) + local blank_comment = indent .. vim.trim(parts.left) .. vim.trim(suffix) return function(line) if is_blank(line) then diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua @@ -1229,7 +1229,7 @@ function M.config(opts, namespace) if float_opts then float_opts = type(float_opts) == 'table' and float_opts or {} - opts.jump.on_jump = function(_, bufnr) + jump_opts.on_jump = function(_, bufnr) M.open_float(vim.tbl_extend('keep', float_opts, { bufnr = bufnr, scope = 'cursor', @@ -1697,7 +1697,7 @@ M.handlers.underline = { bufnr = vim._resolve_bufnr(bufnr) opts = opts or {} - if not vim.api.nvim_buf_is_loaded(bufnr) then + if not api.nvim_buf_is_loaded(bufnr) then return end @@ -1724,7 +1724,7 @@ M.handlers.underline = { end local lines = - vim.api.nvim_buf_get_lines(diagnostic.bufnr, diagnostic.lnum, diagnostic.lnum + 1, true) + api.nvim_buf_get_lines(diagnostic.bufnr, diagnostic.lnum, diagnostic.lnum + 1, true) vim.hl.range( bufnr, @@ -1795,7 +1795,7 @@ M.handlers.virtual_text = { bufnr = vim._resolve_bufnr(bufnr) opts = opts or {} - if not vim.api.nvim_buf_is_loaded(bufnr) then + if not api.nvim_buf_is_loaded(bufnr) then return end @@ -2491,7 +2491,7 @@ function M.open_float(opts, ...) local location = info.location local file_name = vim.fs.basename(vim.uri_to_fname(location.uri)) local info_suffix = ': ' .. info.message - related_info_locations[#lines + 1] = info.location + related_info_locations[#lines + 1] = location lines[#lines + 1] = string.format( '%s%s:%s:%s%s', default_pre, @@ -2881,11 +2881,11 @@ function M.status(bufnr) return result_str end -vim.api.nvim_create_autocmd('DiagnosticChanged', { - group = vim.api.nvim_create_augroup('nvim.diagnostic.status', {}), +api.nvim_create_autocmd('DiagnosticChanged', { + group = api.nvim_create_augroup('nvim.diagnostic.status', {}), callback = function(ev) - if vim.api.nvim_buf_is_loaded(ev.buf) then - vim.api.nvim__redraw({ buf = ev.buf, statusline = true }) + if api.nvim_buf_is_loaded(ev.buf) then + api.nvim__redraw({ buf = ev.buf, statusline = true }) end end, desc = 'diagnostics component for the statusline', diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua @@ -190,9 +190,9 @@ function M.dir(path, opts) if opts.depth and level < opts.depth - and (t == 'directory' or (t == 'link' and opts.follow and (vim.uv.fs_stat( - M.joinpath(path, f) - ) or {}).type == 'directory')) + and (t == 'directory' or (t == 'link' and opts.follow and ( + uv.fs_stat(M.joinpath(path, f)) or {} + ).type == 'directory')) and (not opts.skip or opts.skip(f) ~= false) then dirs[#dirs + 1] = { f, level + 1 } @@ -369,7 +369,7 @@ function M.find(names, opts) if type_ == 'directory' - or (type_ == 'link' and opts.follow and (vim.uv.fs_stat(f) or {}).type == 'directory') + or (type_ == 'link' and opts.follow and (uv.fs_stat(f) or {}).type == 'directory') then dirs[#dirs + 1] = f end diff --git a/runtime/lua/vim/hl.lua b/runtime/lua/vim/hl.lua @@ -72,7 +72,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts) 0, } - local buf_line_count = vim.api.nvim_buf_line_count(bufnr) + local buf_line_count = api.nvim_buf_line_count(bufnr) pos1[2] = math.min(pos1[2], buf_line_count) pos2[2] = math.min(pos2[2], buf_line_count) @@ -182,8 +182,8 @@ function M.on_yank(opts) local higroup = opts.higroup or 'IncSearch' - local bufnr = vim.api.nvim_get_current_buf() - local winid = vim.api.nvim_get_current_win() + local bufnr = api.nvim_get_current_buf() + local winid = api.nvim_get_current_win() if yank_timer and not yank_timer:is_closing() then yank_timer:close() @@ -191,7 +191,7 @@ function M.on_yank(opts) yank_hl_clear() end - vim.api.nvim__ns_set(yank_ns, { wins = { winid } }) + api.nvim__ns_set(yank_ns, { wins = { winid } }) yank_timer, yank_hl_clear = M.range(bufnr, yank_ns, higroup, "'[", "']", { regtype = event.regtype, inclusive = true, diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua @@ -458,7 +458,7 @@ end --- @return F local function track(stat, f) return function(...) - local start = vim.uv.hrtime() + local start = uv.hrtime() local r = { f(...) } stats[stat] = stats[stat] or { total = 0, time = 0 } stats[stat].total = stats[stat].total + 1 diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua @@ -1376,7 +1376,7 @@ function lsp.formatexpr(opts) local response = client:request_sync(ms.textDocument_rangeFormatting, params, timeout_ms, bufnr) if response and response.result then - lsp.util.apply_text_edits(response.result, bufnr, client.offset_encoding) + util.apply_text_edits(response.result, bufnr, client.offset_encoding) return 0 end end diff --git a/runtime/lua/vim/lsp/_changetracking.lua b/runtime/lua/vim/lsp/_changetracking.lua @@ -104,7 +104,7 @@ local function incremental_changes(state, encoding, bufnr, firstline, lastline, local line_ending = vim.lsp._buf_get_line_ending(bufnr) local incremental_change = sync.compute_diff( - state.lines, + prev_lines, curr_lines, firstline, lastline, diff --git a/runtime/lua/vim/lsp/_folding_range.lua b/runtime/lua/vim/lsp/_folding_range.lua @@ -249,7 +249,7 @@ function State:new(bufnr) group = self.augroup, pattern = 'foldexpr', callback = function() - if vim.v.option_type == 'global' or vim.api.nvim_get_current_buf() == bufnr then + if vim.v.option_type == 'global' or api.nvim_get_current_buf() == bufnr then vim.lsp._capability.enable('folding_range', false, { bufnr = bufnr }) end end, diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua @@ -443,7 +443,7 @@ function M.signature_help(config) local buf, win = util.open_floating_preview(lines, 'markdown', config) if hl then - vim.api.nvim_buf_clear_namespace(buf, sig_help_ns, 0, -1) + api.nvim_buf_clear_namespace(buf, sig_help_ns, 0, -1) vim.hl.range( buf, sig_help_ns, @@ -1072,7 +1072,7 @@ end --- @param opts? vim.lsp.WorkspaceDiagnosticsOpts --- @see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_dagnostics function M.workspace_diagnostics(opts) - vim.validate('opts', opts, 'table', true) + validate('opts', opts, 'table', true) lsp.diagnostic._workspace_diagnostics(opts or {}) end @@ -1435,7 +1435,7 @@ function M.selection_range(direction) lsp.buf_request( 0, - ms.textDocument_selectionRange, + method, params, ---@param response lsp.SelectionRange[]? function(err, response) diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua @@ -871,7 +871,7 @@ function Client:stop(force) self._is_stopping = true local rpc = self.rpc - vim.lsp._watchfiles.cancel(self.id) + lsp._watchfiles.cancel(self.id) if force or not self.initialized or self._graceful_shutdown_failed then rpc.terminate() @@ -921,7 +921,7 @@ function Client:_register(registrations) for _, reg in ipairs(registrations) do local method = reg.method if method == ms.workspace_didChangeWatchedFiles then - vim.lsp._watchfiles.register(reg, self.id) + lsp._watchfiles.register(reg, self.id) elseif not self:_supports_registration(method) then unsupported[#unsupported + 1] = method end @@ -955,7 +955,7 @@ function Client:_unregister(unregistrations) self:_unregister_dynamic(unregistrations) for _, unreg in ipairs(unregistrations) do if unreg.method == ms.workspace_didChangeWatchedFiles then - vim.lsp._watchfiles.unregister(unreg, self.id) + lsp._watchfiles.unregister(unreg, self.id) end end end @@ -1096,10 +1096,10 @@ function Client:on_attach(bufnr) -- on_attach and LspAttach callbacks the ability to schedule wrap the -- opt-out (deleting the semanticTokensProvider from capabilities) vim.schedule(function() - for _, Capability in pairs(vim.lsp._capability.all) do + for _, Capability in pairs(lsp._capability.all) do if self:supports_method(Capability.method) - and vim.lsp._capability.is_enabled(Capability.name, { + and lsp._capability.is_enabled(Capability.name, { bufnr = bufnr, client_id = self.id, }) @@ -1220,10 +1220,10 @@ function Client:_on_detach(bufnr) }) end - for _, Capability in pairs(vim.lsp._capability.all) do + for _, Capability in pairs(lsp._capability.all) do if self:supports_method(Capability.method) - and vim.lsp._capability.is_enabled(Capability.name, { + and lsp._capability.is_enabled(Capability.name, { bufnr = bufnr, client_id = self.id, }) @@ -1266,7 +1266,7 @@ local function reset_defaults(bufnr) end vim._with({ buf = bufnr }, function() local keymap = vim.fn.maparg('K', 'n', false, true) - if keymap and keymap.callback == vim.lsp.buf.hover and keymap.buffer == 1 then + if keymap and keymap.callback == lsp.buf.hover and keymap.buffer == 1 then vim.keymap.del('n', 'K', { buffer = bufnr }) end end) diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua @@ -864,7 +864,7 @@ end --- - findstart=0: column where the completion starts, or -2 or -3 --- - findstart=1: list of matches (actually just calls |complete()|) function M._omnifunc(findstart, base) - vim.lsp.log.debug('omnifunc.findstart', { findstart = findstart, base = 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 }) diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua @@ -498,7 +498,7 @@ function M._workspace_diagnostics(opts) local function handler(error, result, ctx) -- Check for retrigger requests on cancellation errors. -- Unless `retriggerRequest` is explicitly disabled, try again. - if error ~= nil and error.code == lsp.protocol.ErrorCodes.ServerCancelled then + 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) diff --git a/runtime/lua/vim/lsp/document_color.lua b/runtime/lua/vim/lsp/document_color.lua @@ -450,7 +450,7 @@ function M.color_presentation() end vim.list_extend(text_edits, choice.additionalTextEdits or {}) - lsp.util.apply_text_edits(text_edits, bufnr, client.offset_encoding) + util.apply_text_edits(text_edits, bufnr, client.offset_encoding) end) end) end diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua @@ -177,7 +177,7 @@ function M.get(filter) --- @param buf integer vim.tbl_map(function(buf) vim.list_extend(hints, M.get(vim.tbl_extend('keep', { bufnr = buf }, filter))) - end, vim.api.nvim_list_bufs()) + end, api.nvim_list_bufs()) return hints else bufnr = vim._resolve_bufnr(bufnr) diff --git a/runtime/lua/vim/lsp/inline_completion.lua b/runtime/lua/vim/lsp/inline_completion.lua @@ -304,7 +304,7 @@ function Completor:apply() range.end_.col, lines ) - local pos = current.range.start:to_cursor() + local pos = range.start:to_cursor() api.nvim_win_set_cursor(vim.fn.bufwinid(self.bufnr), { pos[1] + #lines - 1, (#lines == 1 and pos[2] or 0) + #lines[#lines], diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua @@ -225,13 +225,13 @@ end ---@param message_type lsp.MessageType function log._from_lsp_level(message_type) if message_type == protocol.MessageType.Error then - return vim.log.levels.ERROR + return log_levels.ERROR elseif message_type == protocol.MessageType.Warning then - return vim.log.levels.WARN + return log_levels.WARN elseif message_type == protocol.MessageType.Info or message_type == protocol.MessageType.Log then - return vim.log.levels.INFO + return log_levels.INFO else - return vim.log.levels.DEBUG + return log_levels.DEBUG end end diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua @@ -526,11 +526,11 @@ local function merge_dispatchers(dispatchers) ---@type vim.lsp.rpc.Dispatchers local merged = { notification = ( - dispatchers.notification and vim.schedule_wrap(dispatchers.notification) + dispatchers.notification and schedule_wrap(dispatchers.notification) or default_dispatchers.notification ), on_error = ( - dispatchers.on_error and vim.schedule_wrap(dispatchers.on_error) + dispatchers.on_error and schedule_wrap(dispatchers.on_error) or default_dispatchers.on_error ), on_exit = dispatchers.on_exit or default_dispatchers.on_exit, diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -368,7 +368,7 @@ end --- @param hl_group string --- @param priority integer local function set_mark(bufnr, ns, token, hl_group, priority) - vim.api.nvim_buf_set_extmark(bufnr, ns, token.line, token.start_col, { + api.nvim_buf_set_extmark(bufnr, ns, token.line, token.start_col, { hl_group = hl_group, end_line = token.end_line, end_col = token.end_col, diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua @@ -159,7 +159,7 @@ local function compute_start_range( else byte_idx = start_byte_idx + str_utf_start(prev_line, start_byte_idx) --- Convert to 0 based for input, and from 0 based for output - char_idx = vim.str_utfindex(prev_line, position_encoding, byte_idx - 1) + 1 + char_idx = str_utfindex(prev_line, position_encoding, byte_idx - 1) + 1 end -- Return the start difference (shared for new and prev lines) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua @@ -595,7 +595,7 @@ function M.rename(old_fname, new_fname, opts) opts = opts or {} local skip = not opts.overwrite or opts.ignoreIfExists - local old_fname_full = vim.uv.fs_realpath(vim.fs.normalize(old_fname, { expand_env = false })) + local old_fname_full = uv.fs_realpath(vim.fs.normalize(old_fname, { expand_env = false })) if not old_fname_full then vim.notify('Invalid path: ' .. old_fname, vim.log.levels.ERROR) return @@ -869,7 +869,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers active_offset = { offset - 1, offset + #parameter_label - 1 } break end - offset = offset + #param.label + 1 + offset = offset + #plabel + 1 end end if parameter.documentation then diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua @@ -365,7 +365,7 @@ local function trigger_event(p, event_name, kind) spec.version = spec.version or (uv.fs_stat(p.path) and git_get_default_branch(p.path)) local data = { kind = kind, spec = spec, path = p.path } - vim.api.nvim_exec_autocmds(event_name, { pattern = p.path, data = data }) + api.nvim_exec_autocmds(event_name, { pattern = p.path, data = data }) end --- @param title string diff --git a/runtime/lua/vim/treesitter/dev.lua b/runtime/lua/vim/treesitter/dev.lua @@ -343,7 +343,7 @@ function M.inspect_tree(opts) local win = api.nvim_get_current_win() local treeview, err = TSTreeView:new(buf, opts.lang) if err and err:match('no parser for lang') then - vim.api.nvim_echo({ { err, 'WarningMsg' } }, true, {}) + api.nvim_echo({ { err, 'WarningMsg' } }, true, {}) return elseif not treeview then error(err) @@ -627,7 +627,7 @@ function M.edit_query(lang) local base_buf = base_win and api.nvim_win_get_buf(base_win) local inspect_win = base_buf and vim.b[base_buf].dev_inspect if base_win and base_buf and api.nvim_win_is_valid(inspect_win) then - vim.api.nvim_set_current_win(inspect_win) + api.nvim_set_current_win(inspect_win) buf = base_buf win = base_win cmd = 'new' diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua @@ -9,7 +9,7 @@ function M.check() health.info( string.format( 'Treesitter ABI support: min %d, max %d', - vim.treesitter.minimum_language_version, + ts.minimum_language_version, ts.language_version ) ) diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua @@ -188,7 +188,7 @@ end --- Returns available treesitter languages. function M._complete() - local parsers = vim.api.nvim_get_runtime_file('parser/*', true) + local parsers = api.nvim_get_runtime_file('parser/*', true) local parser_names_set = {} ---@type table<string, boolean> for _, parser in ipairs(parsers) do local parser_name = vim.fn.fnamemodify(parser, ':t:r') diff --git a/src/gen/gen_api_dispatch.lua b/src/gen/gen_api_dispatch.lua @@ -421,7 +421,7 @@ for _, k in ipairs(keysets) do local function typename(type) if type == 'HLGroupID' then return 'kObjectTypeInteger' - elseif not type or vim.startswith(type, 'Union') then + elseif not type or startswith(type, 'Union') then return 'kObjectTypeNil' elseif type == 'StringArray' then return 'kUnpackTypeStringArray' diff --git a/src/gen/gen_vimdoc.lua b/src/gen/gen_vimdoc.lua @@ -591,7 +591,7 @@ local function render_fields_or_params(xs, generics, classes, cfg) inline_type(p, classes) local nm, ty = p.name, p.type - local desc = p.classvar and string.format('See |%s|.', cfg.fn_helptag_fmt(p)) or p.desc + local desc = p.classvar and fmt('See |%s|.', cfg.fn_helptag_fmt(p)) or p.desc local fnm = p.kind == 'operator' and fmt('op(%s)', nm) or fmt_field_name(nm) local pnm = fmt(' • %-' .. indent .. 's', fnm) @@ -1071,7 +1071,7 @@ local function gen_target(cfg) for _, f in ipairs(cfg.section_order) do local section = sections[f] if section then - print(string.format(" Rendering section: '%s'", section.title)) + print(fmt(" Rendering section: '%s'", section.title)) local add_sep_and_header = not vim.tbl_contains(cfg.append_only or {}, f) docs[#docs + 1] = render_section(section, add_sep_and_header) end