refactor(lua): consistent use of local aliases

This commit is contained in:
Christian Clason
2025-08-26 15:31:16 +02:00
committed by Christian Clason
parent a33284c2c0
commit c10e36fc01
27 changed files with 59 additions and 59 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 })

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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],

View File

@@ -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

View File

@@ -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,

View File

@@ -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,

View File

@@ -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)

View File

@@ -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