mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(lsp): make the use of local aliases more consistent
This commit is contained in:
parent
9370e1c511
commit
8a5c7e91f2
@ -4,15 +4,15 @@ local lsp_rpc = require('vim.lsp.rpc')
|
||||
local protocol = require('vim.lsp.protocol')
|
||||
local util = require('vim.lsp.util')
|
||||
local sync = require('vim.lsp.sync')
|
||||
local api = vim.api
|
||||
|
||||
local vim = vim
|
||||
local a = vim.api
|
||||
local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_buf_get_option, nvim_exec_autocmds =
|
||||
vim.api.nvim_err_writeln,
|
||||
vim.api.nvim_buf_get_lines,
|
||||
vim.api.nvim_command,
|
||||
vim.api.nvim_buf_get_option,
|
||||
vim.api.nvim_exec_autocmds
|
||||
a.nvim_err_writeln,
|
||||
a.nvim_buf_get_lines,
|
||||
a.nvim_command,
|
||||
a.nvim_buf_get_option,
|
||||
a.nvim_exec_autocmds
|
||||
local uv = vim.loop
|
||||
local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend
|
||||
local validate = vim.validate
|
||||
@ -79,7 +79,7 @@ end
|
||||
local function resolve_bufnr(bufnr)
|
||||
validate({ bufnr = { bufnr, 'n', true } })
|
||||
if bufnr == nil or bufnr == 0 then
|
||||
return vim.api.nvim_get_current_buf()
|
||||
return a.nvim_get_current_buf()
|
||||
end
|
||||
return bufnr
|
||||
end
|
||||
@ -216,7 +216,7 @@ end
|
||||
---@returns (string) the command
|
||||
---@returns (list of strings) its arguments
|
||||
function lsp._cmd_parts(input)
|
||||
vim.validate({
|
||||
validate({
|
||||
cmd = {
|
||||
input,
|
||||
function()
|
||||
@ -230,7 +230,7 @@ function lsp._cmd_parts(input)
|
||||
local cmd_args = {}
|
||||
-- Don't mutate our input.
|
||||
for i, v in ipairs(input) do
|
||||
vim.validate({ ['cmd argument'] = { v, 's' } })
|
||||
validate({ ['cmd argument'] = { v, 's' } })
|
||||
if i > 1 then
|
||||
table.insert(cmd_args, v)
|
||||
end
|
||||
@ -505,7 +505,7 @@ do
|
||||
end
|
||||
buf_state.pending_change = nil
|
||||
buf_state.last_flush = uv.hrtime()
|
||||
if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then
|
||||
if client.is_stopped() or not a.nvim_buf_is_valid(bufnr) then
|
||||
return
|
||||
end
|
||||
local changes = state.use_incremental_sync and buf_state.pending_changes
|
||||
@ -522,7 +522,7 @@ do
|
||||
if debounce == 0 then
|
||||
buf_state.pending_change()
|
||||
else
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = uv.new_timer()
|
||||
buf_state.timer = timer
|
||||
-- Must use schedule_wrap because `full_changes()` calls nvim_buf_get_lines
|
||||
timer:start(debounce, 0, vim.schedule_wrap(buf_state.pending_change))
|
||||
@ -572,7 +572,7 @@ local function text_document_did_open_handler(bufnr, client)
|
||||
if not vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
||||
return
|
||||
end
|
||||
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
if not a.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
local filetype = nvim_buf_get_option(bufnr, 'filetype')
|
||||
@ -592,7 +592,7 @@ local function text_document_did_open_handler(bufnr, client)
|
||||
vim.schedule(function()
|
||||
-- Protect against a race where the buffer disappears
|
||||
-- between `did_open_handler` and the scheduled function firing.
|
||||
if vim.api.nvim_buf_is_valid(bufnr) then
|
||||
if a.nvim_buf_is_valid(bufnr) then
|
||||
local namespace = vim.lsp.diagnostic.get_namespace(client.id)
|
||||
vim.diagnostic.show(namespace, bufnr)
|
||||
end
|
||||
@ -738,7 +738,7 @@ function lsp.start(config, opts)
|
||||
return client.config.root_dir == conf.root_dir and client.name == conf.name
|
||||
end
|
||||
config.name = config.name or (config.cmd[1] and vim.fs.basename(config.cmd[1])) or nil
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
for _, clients in ipairs({ uninitialized_clients, lsp.get_active_clients() }) do
|
||||
for _, client in pairs(clients) do
|
||||
if reuse_client(client, config) then
|
||||
@ -1433,7 +1433,7 @@ function lsp.buf_attach_client(bufnr, client_id)
|
||||
client_id = { client_id, 'n' },
|
||||
})
|
||||
bufnr = resolve_bufnr(bufnr)
|
||||
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
if not a.nvim_buf_is_loaded(bufnr) then
|
||||
local _ = log.warn()
|
||||
and log.warn(string.format('buf_attach_client called on unloaded buffer (id: %d): ', bufnr))
|
||||
return false
|
||||
@ -1451,9 +1451,9 @@ function lsp.buf_attach_client(bufnr, client_id)
|
||||
au BufWritePost <buffer=%d> lua vim.lsp._text_document_did_save_handler(0)
|
||||
augroup END
|
||||
]=]
|
||||
vim.api.nvim_exec(string.format(buf_did_save_autocommand, client_id, bufnr, bufnr), false)
|
||||
a.nvim_exec(string.format(buf_did_save_autocommand, client_id, bufnr, bufnr), false)
|
||||
-- First time, so attach and set up stuff.
|
||||
vim.api.nvim_buf_attach(bufnr, false, {
|
||||
a.nvim_buf_attach(bufnr, false, {
|
||||
on_lines = text_document_did_change_handler,
|
||||
on_reload = function()
|
||||
local params = { textDocument = { uri = uri } }
|
||||
@ -1723,7 +1723,7 @@ function lsp.buf_request(bufnr, method, params, handler)
|
||||
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')
|
||||
nvim_command('redraw')
|
||||
return {}, function() end
|
||||
end
|
||||
|
||||
@ -1888,8 +1888,8 @@ function lsp.omnifunc(findstart, base)
|
||||
-- Then, perform standard completion request
|
||||
local _ = log.info() and log.info('base ', base)
|
||||
|
||||
local pos = vim.api.nvim_win_get_cursor(0)
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
local pos = a.nvim_win_get_cursor(0)
|
||||
local line = a.nvim_get_current_line()
|
||||
local line_to_cursor = line:sub(1, pos[2])
|
||||
local _ = log.trace() and log.trace('omnifunc.line', pos, line)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
local vim = vim
|
||||
local a = vim.api
|
||||
local validate = vim.validate
|
||||
local vfn = vim.fn
|
||||
local util = require('vim.lsp.util')
|
||||
|
||||
local M = {}
|
||||
@ -201,7 +201,7 @@ end
|
||||
|
||||
function M.format(options)
|
||||
options = options or {}
|
||||
local bufnr = options.bufnr or vim.api.nvim_get_current_buf()
|
||||
local bufnr = options.bufnr or a.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_active_clients({
|
||||
id = options.id,
|
||||
bufnr = bufnr,
|
||||
@ -262,7 +262,7 @@ function M.formatting(options)
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local params = util.make_formatting_params(options)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
select_client('textDocument/formatting', function(client)
|
||||
if client == nil then
|
||||
return
|
||||
@ -290,7 +290,7 @@ function M.formatting_sync(options, timeout_ms)
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local params = util.make_formatting_params(options)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
select_client('textDocument/formatting', function(client)
|
||||
if client == nil then
|
||||
return
|
||||
@ -327,7 +327,7 @@ function M.formatting_seq_sync(options, timeout_ms, order)
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local clients = vim.tbl_values(vim.lsp.buf_get_clients())
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
|
||||
-- sort the clients according to `order`
|
||||
for _, client_name in pairs(order or {}) do
|
||||
@ -348,7 +348,7 @@ function M.formatting_seq_sync(options, timeout_ms, order)
|
||||
'textDocument/formatting',
|
||||
params,
|
||||
timeout_ms,
|
||||
vim.api.nvim_get_current_buf()
|
||||
a.nvim_get_current_buf()
|
||||
)
|
||||
if result and result.result then
|
||||
util.apply_text_edits(result.result, bufnr, client.offset_encoding)
|
||||
@ -394,7 +394,7 @@ end
|
||||
--- this field.
|
||||
function M.rename(new_name, options)
|
||||
options = options or {}
|
||||
local bufnr = options.bufnr or vim.api.nvim_get_current_buf()
|
||||
local bufnr = options.bufnr or a.nvim_get_current_buf()
|
||||
local clients = vim.lsp.get_active_clients({
|
||||
bufnr = bufnr,
|
||||
name = options.name,
|
||||
@ -412,14 +412,14 @@ function M.rename(new_name, options)
|
||||
vim.notify('[LSP] Rename, no matching language servers with rename capability.')
|
||||
end
|
||||
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local win = a.nvim_get_current_win()
|
||||
|
||||
-- Compute early to account for cursor movements after going async
|
||||
local cword = vfn.expand('<cword>')
|
||||
local cword = vim.fn.expand('<cword>')
|
||||
|
||||
---@private
|
||||
local function get_text_at_range(range, offset_encoding)
|
||||
return vim.api.nvim_buf_get_text(
|
||||
return a.nvim_buf_get_text(
|
||||
bufnr,
|
||||
range.start.line,
|
||||
util._get_line_byte_from_position(bufnr, range.start, offset_encoding),
|
||||
@ -603,8 +603,8 @@ end
|
||||
--- 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')
|
||||
vim.api.nvim_command('redraw')
|
||||
or npcall(vim.fn.input, 'Workspace Folder: ', vim.fn.expand('%:p:h'), 'dir')
|
||||
a.nvim_command('redraw')
|
||||
if not (workspace_folder and #workspace_folder > 0) then
|
||||
return
|
||||
end
|
||||
@ -640,8 +640,8 @@ end
|
||||
--- 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'))
|
||||
vim.api.nvim_command('redraw')
|
||||
or npcall(vim.fn.input, 'Workspace Folder: ', vim.fn.expand('%:p:h'))
|
||||
a.nvim_command('redraw')
|
||||
if not (workspace_folder and #workspace_folder > 0) then
|
||||
return
|
||||
end
|
||||
@ -669,7 +669,7 @@ end
|
||||
---
|
||||
---@param query (string, optional)
|
||||
function M.workspace_symbol(query)
|
||||
query = query or npcall(vfn.input, 'Query: ')
|
||||
query = query or npcall(vim.fn.input, 'Query: ')
|
||||
if query == nil then
|
||||
return
|
||||
end
|
||||
@ -838,7 +838,7 @@ end
|
||||
--- with all aggregated results
|
||||
---@private
|
||||
local function code_action_request(params, options)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
local method = 'textDocument/codeAction'
|
||||
vim.lsp.buf_request_all(bufnr, method, params, function(results)
|
||||
local ctx = { bufnr = bufnr, method = method, params = params }
|
||||
@ -875,7 +875,7 @@ function M.code_action(options)
|
||||
end
|
||||
local context = options.context or {}
|
||||
if not context.diagnostics then
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
|
||||
end
|
||||
local params = util.make_range_params()
|
||||
@ -902,7 +902,7 @@ function M.range_code_action(context, start_pos, end_pos)
|
||||
validate({ context = { context, 't', true } })
|
||||
context = context or {}
|
||||
if not context.diagnostics then
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
|
||||
end
|
||||
local params = util.make_given_range_params(start_pos, end_pos)
|
||||
|
@ -1,6 +1,6 @@
|
||||
local util = require('vim.lsp.util')
|
||||
local log = require('vim.lsp.log')
|
||||
local api = vim.api
|
||||
local a = vim.api
|
||||
local M = {}
|
||||
|
||||
--- bufnr → true|nil
|
||||
@ -10,14 +10,14 @@ local active_refreshes = {}
|
||||
--- bufnr -> client_id -> lenses
|
||||
local lens_cache_by_buf = setmetatable({}, {
|
||||
__index = function(t, b)
|
||||
local key = b > 0 and b or api.nvim_get_current_buf()
|
||||
local key = b > 0 and b or a.nvim_get_current_buf()
|
||||
return rawget(t, key)
|
||||
end,
|
||||
})
|
||||
|
||||
local namespaces = setmetatable({}, {
|
||||
__index = function(t, key)
|
||||
local value = api.nvim_create_namespace('vim_lsp_codelens:' .. key)
|
||||
local value = a.nvim_create_namespace('vim_lsp_codelens:' .. key)
|
||||
rawset(t, key, value)
|
||||
return value
|
||||
end,
|
||||
@ -29,7 +29,7 @@ M.__namespaces = namespaces
|
||||
---@private
|
||||
local function execute_lens(lens, bufnr, client_id)
|
||||
local line = lens.range.start.line
|
||||
api.nvim_buf_clear_namespace(bufnr, namespaces[client_id], line, line + 1)
|
||||
a.nvim_buf_clear_namespace(bufnr, namespaces[client_id], line, line + 1)
|
||||
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
|
||||
@ -78,8 +78,8 @@ end
|
||||
--- Run the code lens in the current line
|
||||
---
|
||||
function M.run()
|
||||
local line = api.nvim_win_get_cursor(0)[1]
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local line = a.nvim_win_get_cursor(0)[1]
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
local options = {}
|
||||
local lenses_by_client = lens_cache_by_buf[bufnr] or {}
|
||||
for client, lenses in pairs(lenses_by_client) do
|
||||
@ -127,10 +127,10 @@ function M.display(lenses, bufnr, client_id)
|
||||
table.insert(line_lenses, lens)
|
||||
end
|
||||
local ns = namespaces[client_id]
|
||||
local num_lines = api.nvim_buf_line_count(bufnr)
|
||||
local num_lines = a.nvim_buf_line_count(bufnr)
|
||||
for i = 0, num_lines do
|
||||
local line_lenses = lenses_by_lnum[i] or {}
|
||||
api.nvim_buf_clear_namespace(bufnr, ns, i, i + 1)
|
||||
a.nvim_buf_clear_namespace(bufnr, ns, i, i + 1)
|
||||
local chunks = {}
|
||||
local num_line_lenses = #line_lenses
|
||||
table.sort(line_lenses, function(a, b)
|
||||
@ -144,7 +144,7 @@ function M.display(lenses, bufnr, client_id)
|
||||
end
|
||||
end
|
||||
if #chunks > 0 then
|
||||
api.nvim_buf_set_extmark(bufnr, ns, i, 0, {
|
||||
a.nvim_buf_set_extmark(bufnr, ns, i, 0, {
|
||||
virt_text = chunks,
|
||||
hl_mode = 'combine',
|
||||
})
|
||||
@ -163,12 +163,12 @@ function M.save(lenses, bufnr, client_id)
|
||||
lenses_by_client = {}
|
||||
lens_cache_by_buf[bufnr] = lenses_by_client
|
||||
local ns = namespaces[client_id]
|
||||
api.nvim_buf_attach(bufnr, false, {
|
||||
a.nvim_buf_attach(bufnr, false, {
|
||||
on_detach = function(b)
|
||||
lens_cache_by_buf[b] = nil
|
||||
end,
|
||||
on_lines = function(_, b, _, first_lnum, last_lnum)
|
||||
api.nvim_buf_clear_namespace(b, ns, first_lnum, last_lnum)
|
||||
a.nvim_buf_clear_namespace(b, ns, first_lnum, last_lnum)
|
||||
end,
|
||||
})
|
||||
end
|
||||
@ -203,7 +203,7 @@ local function resolve_lenses(lenses, bufnr, client_id, callback)
|
||||
-- Eager display to have some sort of incremental feedback
|
||||
-- Once all lenses got resolved there will be a full redraw for all lenses
|
||||
-- So that multiple lens per line are properly displayed
|
||||
api.nvim_buf_set_extmark(
|
||||
a.nvim_buf_set_extmark(
|
||||
bufnr,
|
||||
ns,
|
||||
lens.range.start.line,
|
||||
@ -249,7 +249,7 @@ function M.refresh()
|
||||
local params = {
|
||||
textDocument = util.make_text_document_params(),
|
||||
}
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
if active_refreshes[bufnr] then
|
||||
return
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ local log = require('vim.lsp.log')
|
||||
local protocol = require('vim.lsp.protocol')
|
||||
local util = require('vim.lsp.util')
|
||||
local vim = vim
|
||||
local api = vim.api
|
||||
local a = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
@ -13,7 +13,7 @@ local M = {}
|
||||
---@param ... (table of strings) Will be concatenated before being written
|
||||
local function err_message(...)
|
||||
vim.notify(table.concat(vim.tbl_flatten({ ... })), vim.log.levels.ERROR)
|
||||
api.nvim_command('redraw')
|
||||
a.nvim_command('redraw')
|
||||
end
|
||||
|
||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
||||
@ -61,7 +61,7 @@ local function progress_handler(_, result, ctx, _)
|
||||
client.messages.progress[token].done = true
|
||||
end
|
||||
|
||||
vim.api.nvim_command('doautocmd <nomodeline> User LspProgressUpdate')
|
||||
a.nvim_command('doautocmd <nomodeline> User LspProgressUpdate')
|
||||
end
|
||||
|
||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
|
||||
@ -195,14 +195,14 @@ M['textDocument/references'] = function(_, result, ctx, config)
|
||||
items = util.locations_to_items(result, client.offset_encoding),
|
||||
context = ctx,
|
||||
})
|
||||
api.nvim_command('lopen')
|
||||
a.nvim_command('lopen')
|
||||
else
|
||||
vim.fn.setqflist({}, ' ', {
|
||||
title = 'References',
|
||||
items = util.locations_to_items(result, client.offset_encoding),
|
||||
context = ctx,
|
||||
})
|
||||
api.nvim_command('botright copen')
|
||||
a.nvim_command('botright copen')
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -230,14 +230,14 @@ local function response_to_list(map_result, entity, title_fn)
|
||||
items = map_result(result, ctx.bufnr),
|
||||
context = ctx,
|
||||
})
|
||||
api.nvim_command('lopen')
|
||||
a.nvim_command('lopen')
|
||||
else
|
||||
vim.fn.setqflist({}, ' ', {
|
||||
title = title_fn(ctx),
|
||||
items = map_result(result, ctx.bufnr),
|
||||
context = ctx,
|
||||
})
|
||||
api.nvim_command('botright copen')
|
||||
a.nvim_command('botright copen')
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -290,8 +290,8 @@ M['textDocument/completion'] = function(_, result, _, _)
|
||||
if vim.tbl_isempty(result or {}) then
|
||||
return
|
||||
end
|
||||
local row, col = unpack(api.nvim_win_get_cursor(0))
|
||||
local line = assert(api.nvim_buf_get_lines(0, row - 1, row, false)[1])
|
||||
local row, col = unpack(a.nvim_win_get_cursor(0))
|
||||
local line = assert(a.nvim_buf_get_lines(0, row - 1, row, false)[1])
|
||||
local line_to_cursor = line:sub(col + 1)
|
||||
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
|
||||
local prefix = line_to_cursor:sub(textMatch + 1)
|
||||
@ -358,7 +358,7 @@ local function location_handler(_, result, ctx, config)
|
||||
title = 'LSP locations',
|
||||
items = util.locations_to_items(result, client.offset_encoding),
|
||||
})
|
||||
api.nvim_command('botright copen')
|
||||
a.nvim_command('botright copen')
|
||||
end
|
||||
else
|
||||
util.jump_to_location(result, client.offset_encoding, config.reuse_win)
|
||||
@ -402,7 +402,7 @@ function M.signature_help(_, result, ctx, config)
|
||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||
local triggers =
|
||||
vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
|
||||
local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype')
|
||||
local ft = a.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)
|
||||
if vim.tbl_isempty(lines) then
|
||||
@ -413,7 +413,7 @@ function M.signature_help(_, result, ctx, config)
|
||||
end
|
||||
local fbuf, fwin = util.open_floating_preview(lines, 'markdown', config)
|
||||
if hl then
|
||||
api.nvim_buf_add_highlight(fbuf, -1, 'LspSignatureActiveParameter', 0, unpack(hl))
|
||||
a.nvim_buf_add_highlight(fbuf, -1, 'LspSignatureActiveParameter', 0, unpack(hl))
|
||||
end
|
||||
return fbuf, fwin
|
||||
end
|
||||
@ -459,7 +459,7 @@ local make_call_hierarchy_handler = function(direction)
|
||||
end
|
||||
end
|
||||
vim.fn.setqflist({}, ' ', { title = 'LSP call hierarchy', items = items })
|
||||
api.nvim_command('botright copen')
|
||||
a.nvim_command('botright copen')
|
||||
end
|
||||
end
|
||||
|
||||
@ -505,7 +505,7 @@ M['window/showMessage'] = function(_, result, ctx, _)
|
||||
err_message('LSP[', client_name, '] ', message)
|
||||
else
|
||||
local message_type_name = protocol.MessageType[message_type]
|
||||
api.nvim_out_write(string.format('LSP[%s][%s] %s\n', client_name, message_type_name, message))
|
||||
a.nvim_out_write(string.format('LSP[%s][%s] %s\n', client_name, message_type_name, message))
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ local is_win = uv.os_uname().version:find('Windows')
|
||||
---@param filename (string) path to check
|
||||
---@returns (bool)
|
||||
local function is_dir(filename)
|
||||
local stat = vim.loop.fs_stat(filename)
|
||||
local stat = uv.fs_stat(filename)
|
||||
return stat and stat.type == 'directory' or false
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
local lsp = vim.lsp
|
||||
local util = vim.lsp.util
|
||||
local util = lsp.util
|
||||
|
||||
---@private
|
||||
local function mk_tag_item(name, range, uri, offset_encoding)
|
||||
@ -15,7 +15,7 @@ end
|
||||
|
||||
---@private
|
||||
local function query_definition(pattern)
|
||||
local params = lsp.util.make_position_params()
|
||||
local params = util.make_position_params()
|
||||
local results_by_client, err = lsp.buf_request_sync(0, 'textDocument/definition', params, 1000)
|
||||
if err then
|
||||
return {}
|
||||
|
@ -2,7 +2,7 @@ local protocol = require('vim.lsp.protocol')
|
||||
local snippet = require('vim.lsp._snippet')
|
||||
local vim = vim
|
||||
local validate = vim.validate
|
||||
local api = vim.api
|
||||
local a = vim.api
|
||||
local list_extend = vim.list_extend
|
||||
local highlight = require('vim.highlight')
|
||||
local uv = vim.loop
|
||||
@ -238,14 +238,14 @@ local function get_lines(bufnr, rows)
|
||||
|
||||
-- This is needed for bufload and bufloaded
|
||||
if bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
---@private
|
||||
local function buf_lines()
|
||||
local lines = {}
|
||||
for _, row in pairs(rows) do
|
||||
lines[row] = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or { '' })[1]
|
||||
lines[row] = (a.nvim_buf_get_lines(bufnr, row, row + 1, false) or { '' })[1]
|
||||
end
|
||||
return lines
|
||||
end
|
||||
@ -264,7 +264,7 @@ local function get_lines(bufnr, rows)
|
||||
return buf_lines()
|
||||
end
|
||||
|
||||
local filename = api.nvim_buf_get_name(bufnr)
|
||||
local filename = a.nvim_buf_get_name(bufnr)
|
||||
|
||||
-- get the data from the file
|
||||
local fd = uv.fs_open(filename, 'r', 438)
|
||||
@ -389,10 +389,10 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
if not next(text_edits) then
|
||||
return
|
||||
end
|
||||
if not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not a.nvim_buf_is_loaded(bufnr) then
|
||||
vim.fn.bufload(bufnr)
|
||||
end
|
||||
api.nvim_buf_set_option(bufnr, 'buflisted', true)
|
||||
a.nvim_buf_set_option(bufnr, 'buflisted', true)
|
||||
|
||||
-- Fix reversed range and indexing each text_edits
|
||||
local index = 0
|
||||
@ -427,7 +427,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
|
||||
-- Some LSP servers are depending on the VSCode behavior.
|
||||
-- The VSCode will re-locate the cursor position after applying TextEdit so we also do it.
|
||||
local is_current_buf = vim.api.nvim_get_current_buf() == bufnr
|
||||
local is_current_buf = a.nvim_get_current_buf() == bufnr
|
||||
local cursor = (function()
|
||||
if not is_current_buf then
|
||||
return {
|
||||
@ -435,7 +435,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
col = -1,
|
||||
}
|
||||
end
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local cursor = a.nvim_win_get_cursor(0)
|
||||
return {
|
||||
row = cursor[1] - 1,
|
||||
col = cursor[2],
|
||||
@ -455,11 +455,11 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
start_col = get_line_byte_from_position(bufnr, text_edit.range.start, offset_encoding),
|
||||
end_row = text_edit.range['end'].line,
|
||||
end_col = get_line_byte_from_position(bufnr, text_edit.range['end'], offset_encoding),
|
||||
text = vim.split(text_edit.newText, '\n', true),
|
||||
text = split(text_edit.newText, '\n', true),
|
||||
}
|
||||
|
||||
-- Some LSP servers may return +1 range of the buffer content but nvim_buf_set_text can't accept it so we should fix it here.
|
||||
local max = vim.api.nvim_buf_line_count(bufnr)
|
||||
local max = a.nvim_buf_line_count(bufnr)
|
||||
if max <= e.start_row or max <= e.end_row then
|
||||
local len = #(get_line(bufnr, max - 1) or '')
|
||||
if max <= e.start_row then
|
||||
@ -473,7 +473,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
end
|
||||
has_eol_text_edit = true
|
||||
end
|
||||
vim.api.nvim_buf_set_text(bufnr, e.start_row, e.start_col, e.end_row, e.end_col, e.text)
|
||||
a.nvim_buf_set_text(bufnr, e.start_row, e.start_col, e.end_row, e.end_col, e.text)
|
||||
|
||||
-- Fix cursor position.
|
||||
local row_count = (e.end_row - e.start_row) + 1
|
||||
@ -490,7 +490,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
end
|
||||
end
|
||||
|
||||
local max = vim.api.nvim_buf_line_count(bufnr)
|
||||
local max = a.nvim_buf_line_count(bufnr)
|
||||
|
||||
-- Apply fixed cursor position.
|
||||
if is_cursor_fixed then
|
||||
@ -498,7 +498,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
is_valid_cursor = is_valid_cursor and cursor.row < max
|
||||
is_valid_cursor = is_valid_cursor and cursor.col <= #(get_line(bufnr, max - 1) or '')
|
||||
if is_valid_cursor then
|
||||
vim.api.nvim_win_set_cursor(0, { cursor.row + 1, cursor.col })
|
||||
a.nvim_win_set_cursor(0, { cursor.row + 1, cursor.col })
|
||||
end
|
||||
end
|
||||
|
||||
@ -506,12 +506,12 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
local fix_eol = has_eol_text_edit
|
||||
fix_eol = fix_eol
|
||||
and (
|
||||
api.nvim_buf_get_option(bufnr, 'eol')
|
||||
or (api.nvim_buf_get_option(bufnr, 'fixeol') and not api.nvim_buf_get_option(bufnr, 'binary'))
|
||||
a.nvim_buf_get_option(bufnr, 'eol')
|
||||
or (a.nvim_buf_get_option(bufnr, 'fixeol') and not a.nvim_buf_get_option(bufnr, 'binary'))
|
||||
)
|
||||
fix_eol = fix_eol and get_line(bufnr, max - 1) == ''
|
||||
if fix_eol then
|
||||
vim.api.nvim_buf_set_lines(bufnr, -2, -1, false, {})
|
||||
a.nvim_buf_set_lines(bufnr, -2, -1, false, {})
|
||||
end
|
||||
end
|
||||
|
||||
@ -710,8 +710,8 @@ end
|
||||
---@private
|
||||
--- Like vim.fn.bufwinid except it works across tabpages.
|
||||
local function bufwinid(bufnr)
|
||||
for _, win in ipairs(api.nvim_list_wins()) do
|
||||
if api.nvim_win_get_buf(win) == bufnr then
|
||||
for _, win in ipairs(a.nvim_list_wins()) do
|
||||
if a.nvim_win_get_buf(win) == bufnr then
|
||||
return win
|
||||
end
|
||||
end
|
||||
@ -724,7 +724,7 @@ end
|
||||
-- ignoreIfExists? bool
|
||||
function M.rename(old_fname, new_fname, opts)
|
||||
opts = opts or {}
|
||||
local target_exists = vim.loop.fs_stat(new_fname) ~= nil
|
||||
local target_exists = uv.fs_stat(new_fname) ~= nil
|
||||
if target_exists and not opts.overwrite or opts.ignoreIfExists then
|
||||
vim.notify('Rename target already exists. Skipping rename.')
|
||||
return
|
||||
@ -733,7 +733,7 @@ function M.rename(old_fname, new_fname, opts)
|
||||
vim.fn.bufload(oldbuf)
|
||||
|
||||
-- The there may be pending changes in the buffer
|
||||
api.nvim_buf_call(oldbuf, function()
|
||||
a.nvim_buf_call(oldbuf, function()
|
||||
vim.cmd('w!')
|
||||
end)
|
||||
|
||||
@ -743,9 +743,9 @@ function M.rename(old_fname, new_fname, opts)
|
||||
local newbuf = vim.fn.bufadd(new_fname)
|
||||
local win = bufwinid(oldbuf)
|
||||
if win then
|
||||
api.nvim_win_set_buf(win, newbuf)
|
||||
a.nvim_win_set_buf(win, newbuf)
|
||||
end
|
||||
api.nvim_buf_delete(oldbuf, { force = true })
|
||||
a.nvim_buf_delete(oldbuf, { force = true })
|
||||
end
|
||||
|
||||
---@private
|
||||
@ -764,7 +764,7 @@ end
|
||||
local function delete_file(change)
|
||||
local opts = change.options or {}
|
||||
local fname = vim.uri_to_fname(change.uri)
|
||||
local stat = vim.loop.fs_stat(fname)
|
||||
local stat = uv.fs_stat(fname)
|
||||
if opts.ignoreIfNotExists and not stat then
|
||||
return
|
||||
end
|
||||
@ -778,7 +778,7 @@ local function delete_file(change)
|
||||
local bufnr = vim.fn.bufadd(fname)
|
||||
local result = tonumber(vim.fn.delete(fname, flags))
|
||||
assert(result == 0, 'Could not delete file: ' .. fname .. ', stat: ' .. vim.inspect(stat))
|
||||
api.nvim_buf_delete(bufnr, { force = true })
|
||||
a.nvim_buf_delete(bufnr, { force = true })
|
||||
end
|
||||
|
||||
--- Applies a `WorkspaceEdit`.
|
||||
@ -906,7 +906,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers
|
||||
-- wrap inside a code block so stylize_markdown can render it properly
|
||||
label = ('```%s\n%s\n```'):format(ft, label)
|
||||
end
|
||||
vim.list_extend(contents, vim.split(label, '\n', true))
|
||||
list_extend(contents, split(label, '\n', true))
|
||||
if signature.documentation then
|
||||
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
||||
end
|
||||
@ -1013,7 +1013,7 @@ function M.make_floating_popup_options(width, height, opts)
|
||||
row = 0
|
||||
end
|
||||
|
||||
if vim.fn.wincol() + width + (opts.offset_x or 0) <= api.nvim_get_option('columns') then
|
||||
if vim.fn.wincol() + width + (opts.offset_x or 0) <= a.nvim_get_option('columns') then
|
||||
anchor = anchor .. 'W'
|
||||
col = 0
|
||||
else
|
||||
@ -1065,15 +1065,15 @@ function M.jump_to_location(location, offset_encoding, reuse_win)
|
||||
--- Jump to new location (adjusting for UTF-16 encoding of characters)
|
||||
local win = reuse_win and bufwinid(bufnr)
|
||||
if win then
|
||||
api.nvim_set_current_win(win)
|
||||
a.nvim_set_current_win(win)
|
||||
else
|
||||
api.nvim_buf_set_option(bufnr, 'buflisted', true)
|
||||
api.nvim_set_current_buf(bufnr)
|
||||
a.nvim_buf_set_option(bufnr, 'buflisted', true)
|
||||
a.nvim_set_current_buf(bufnr)
|
||||
end
|
||||
local range = location.range or location.targetSelectionRange
|
||||
local row = range.start.line
|
||||
local col = get_line_byte_from_position(bufnr, range.start, offset_encoding)
|
||||
api.nvim_win_set_cursor(0, { row + 1, col })
|
||||
a.nvim_win_set_cursor(0, { row + 1, col })
|
||||
-- Open folds under the cursor
|
||||
vim.cmd('normal! zv')
|
||||
return true
|
||||
@ -1094,17 +1094,17 @@ function M.preview_location(location, opts)
|
||||
return
|
||||
end
|
||||
local bufnr = vim.uri_to_bufnr(uri)
|
||||
if not api.nvim_buf_is_loaded(bufnr) then
|
||||
if not a.nvim_buf_is_loaded(bufnr) then
|
||||
vim.fn.bufload(bufnr)
|
||||
end
|
||||
local range = location.targetRange or location.range
|
||||
local contents = api.nvim_buf_get_lines(bufnr, range.start.line, range['end'].line + 1, false)
|
||||
local syntax = api.nvim_buf_get_option(bufnr, 'syntax')
|
||||
local contents = a.nvim_buf_get_lines(bufnr, range.start.line, range['end'].line + 1, false)
|
||||
local syntax = a.nvim_buf_get_option(bufnr, 'syntax')
|
||||
if syntax == '' then
|
||||
-- When no syntax is set, we use filetype as fallback. This might not result
|
||||
-- in a valid syntax definition. See also ft detection in stylize_markdown.
|
||||
-- An empty syntax is more common now with TreeSitter, since TS disables syntax.
|
||||
syntax = api.nvim_buf_get_option(bufnr, 'filetype')
|
||||
syntax = a.nvim_buf_get_option(bufnr, 'filetype')
|
||||
end
|
||||
opts = opts or {}
|
||||
opts.focus_id = 'location'
|
||||
@ -1113,8 +1113,8 @@ end
|
||||
|
||||
---@private
|
||||
local function find_window_by_var(name, value)
|
||||
for _, win in ipairs(api.nvim_list_wins()) do
|
||||
if npcall(api.nvim_win_get_var, win, name) == value then
|
||||
for _, win in ipairs(a.nvim_list_wins()) do
|
||||
if npcall(a.nvim_win_get_var, win, name) == value then
|
||||
return win
|
||||
end
|
||||
end
|
||||
@ -1279,7 +1279,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
||||
end
|
||||
|
||||
-- Compute size of float needed to show (wrapped) lines
|
||||
opts.wrap_at = opts.wrap_at or (vim.wo['wrap'] and api.nvim_win_get_width(0))
|
||||
opts.wrap_at = opts.wrap_at or (vim.wo['wrap'] and a.nvim_win_get_width(0))
|
||||
local width = M._make_floating_popup_size(stripped, opts)
|
||||
|
||||
local sep_line = string.rep('─', math.min(width, opts.wrap_at or width))
|
||||
@ -1290,7 +1290,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
||||
a.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
||||
|
||||
local idx = 1
|
||||
---@private
|
||||
@ -1315,7 +1315,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
||||
local lang = '@' .. ft:upper()
|
||||
if not langs[lang] then
|
||||
-- HACK: reset current_syntax, since some syntax files like markdown won't load if it is already set
|
||||
pcall(vim.api.nvim_buf_del_var, bufnr, 'current_syntax')
|
||||
pcall(a.nvim_buf_del_var, bufnr, 'current_syntax')
|
||||
-- TODO(ashkan): better validation before this.
|
||||
if not pcall(vim.cmd, string.format('syntax include %s syntax/%s.vim', lang, ft)) then
|
||||
return
|
||||
@ -1334,7 +1334,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
||||
end
|
||||
|
||||
-- needs to run in the buffer for the regions to work
|
||||
api.nvim_buf_call(bufnr, function()
|
||||
a.nvim_buf_call(bufnr, function()
|
||||
-- we need to apply lsp_markdown regions speperately, since otherwise
|
||||
-- markdown regions can "bleed" through the other syntax regions
|
||||
-- and mess up the formatting
|
||||
@ -1362,13 +1362,13 @@ end
|
||||
local function close_preview_window(winnr, bufnrs)
|
||||
vim.schedule(function()
|
||||
-- exit if we are in one of ignored buffers
|
||||
if bufnrs and vim.tbl_contains(bufnrs, api.nvim_get_current_buf()) then
|
||||
if bufnrs and vim.tbl_contains(bufnrs, a.nvim_get_current_buf()) then
|
||||
return
|
||||
end
|
||||
|
||||
local augroup = 'preview_window_' .. winnr
|
||||
pcall(api.nvim_del_augroup_by_name, augroup)
|
||||
pcall(api.nvim_win_close, winnr, true)
|
||||
pcall(a.nvim_del_augroup_by_name, augroup)
|
||||
pcall(a.nvim_win_close, winnr, true)
|
||||
end)
|
||||
end
|
||||
|
||||
@ -1380,13 +1380,13 @@ end
|
||||
---@param bufnrs table list of buffers where the preview window will remain visible
|
||||
---@see |autocmd-events|
|
||||
local function close_preview_autocmd(events, winnr, bufnrs)
|
||||
local augroup = api.nvim_create_augroup('preview_window_' .. winnr, {
|
||||
local augroup = a.nvim_create_augroup('preview_window_' .. winnr, {
|
||||
clear = true,
|
||||
})
|
||||
|
||||
-- close the preview window when entered a buffer that is not
|
||||
-- the floating window buffer or the buffer that spawned it
|
||||
api.nvim_create_autocmd('BufEnter', {
|
||||
a.nvim_create_autocmd('BufEnter', {
|
||||
group = augroup,
|
||||
callback = function()
|
||||
close_preview_window(winnr, bufnrs)
|
||||
@ -1394,7 +1394,7 @@ local function close_preview_autocmd(events, winnr, bufnrs)
|
||||
})
|
||||
|
||||
if #events > 0 then
|
||||
api.nvim_create_autocmd(events, {
|
||||
a.nvim_create_autocmd(events, {
|
||||
buffer = bufnrs[2],
|
||||
callback = function()
|
||||
close_preview_window(winnr)
|
||||
@ -1438,7 +1438,7 @@ function M._make_floating_popup_size(contents, opts)
|
||||
end
|
||||
|
||||
local border_width = get_border_size(opts).width
|
||||
local screen_width = api.nvim_win_get_width(0)
|
||||
local screen_width = a.nvim_win_get_width(0)
|
||||
width = math.min(width, screen_width)
|
||||
|
||||
-- make sure borders are always inside the screen
|
||||
@ -1511,35 +1511,35 @@ function M.open_floating_preview(contents, syntax, opts)
|
||||
opts.focus = opts.focus ~= false
|
||||
opts.close_events = opts.close_events or { 'CursorMoved', 'CursorMovedI', 'InsertCharPre' }
|
||||
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local bufnr = a.nvim_get_current_buf()
|
||||
|
||||
-- check if this popup is focusable and we need to focus
|
||||
if opts.focus_id and opts.focusable ~= false and opts.focus then
|
||||
-- Go back to previous window if we are in a focusable one
|
||||
local current_winnr = api.nvim_get_current_win()
|
||||
if npcall(api.nvim_win_get_var, current_winnr, opts.focus_id) then
|
||||
api.nvim_command('wincmd p')
|
||||
local current_winnr = a.nvim_get_current_win()
|
||||
if npcall(a.nvim_win_get_var, current_winnr, opts.focus_id) then
|
||||
a.nvim_command('wincmd p')
|
||||
return bufnr, current_winnr
|
||||
end
|
||||
do
|
||||
local win = find_window_by_var(opts.focus_id, bufnr)
|
||||
if win and api.nvim_win_is_valid(win) and vim.fn.pumvisible() == 0 then
|
||||
if win and a.nvim_win_is_valid(win) and vim.fn.pumvisible() == 0 then
|
||||
-- focus and return the existing buf, win
|
||||
api.nvim_set_current_win(win)
|
||||
api.nvim_command('stopinsert')
|
||||
return api.nvim_win_get_buf(win), win
|
||||
a.nvim_set_current_win(win)
|
||||
a.nvim_command('stopinsert')
|
||||
return a.nvim_win_get_buf(win), win
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check if another floating preview already exists for this buffer
|
||||
-- and close it if needed
|
||||
local existing_float = npcall(api.nvim_buf_get_var, bufnr, 'lsp_floating_preview')
|
||||
if existing_float and api.nvim_win_is_valid(existing_float) then
|
||||
api.nvim_win_close(existing_float, true)
|
||||
local existing_float = npcall(a.nvim_buf_get_var, bufnr, 'lsp_floating_preview')
|
||||
if existing_float and a.nvim_win_is_valid(existing_float) then
|
||||
a.nvim_win_close(existing_float, true)
|
||||
end
|
||||
|
||||
local floating_bufnr = api.nvim_create_buf(false, true)
|
||||
local floating_bufnr = a.nvim_create_buf(false, true)
|
||||
local do_stylize = syntax == 'markdown' and opts.stylize_markdown
|
||||
|
||||
-- Clean up input: trim empty lines from the end, pad
|
||||
@ -1550,33 +1550,33 @@ function M.open_floating_preview(contents, syntax, opts)
|
||||
contents = M.stylize_markdown(floating_bufnr, contents, opts)
|
||||
else
|
||||
if syntax then
|
||||
api.nvim_buf_set_option(floating_bufnr, 'syntax', syntax)
|
||||
a.nvim_buf_set_option(floating_bufnr, 'syntax', syntax)
|
||||
end
|
||||
api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents)
|
||||
a.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents)
|
||||
end
|
||||
|
||||
-- Compute size of float needed to show (wrapped) lines
|
||||
if opts.wrap then
|
||||
opts.wrap_at = opts.wrap_at or api.nvim_win_get_width(0)
|
||||
opts.wrap_at = opts.wrap_at or a.nvim_win_get_width(0)
|
||||
else
|
||||
opts.wrap_at = nil
|
||||
end
|
||||
local width, height = M._make_floating_popup_size(contents, opts)
|
||||
|
||||
local float_option = M.make_floating_popup_options(width, height, opts)
|
||||
local floating_winnr = api.nvim_open_win(floating_bufnr, false, float_option)
|
||||
local floating_winnr = a.nvim_open_win(floating_bufnr, false, float_option)
|
||||
if do_stylize then
|
||||
api.nvim_win_set_option(floating_winnr, 'conceallevel', 2)
|
||||
api.nvim_win_set_option(floating_winnr, 'concealcursor', 'n')
|
||||
a.nvim_win_set_option(floating_winnr, 'conceallevel', 2)
|
||||
a.nvim_win_set_option(floating_winnr, 'concealcursor', 'n')
|
||||
end
|
||||
-- disable folding
|
||||
api.nvim_win_set_option(floating_winnr, 'foldenable', false)
|
||||
a.nvim_win_set_option(floating_winnr, 'foldenable', false)
|
||||
-- soft wrapping
|
||||
api.nvim_win_set_option(floating_winnr, 'wrap', opts.wrap)
|
||||
a.nvim_win_set_option(floating_winnr, 'wrap', opts.wrap)
|
||||
|
||||
api.nvim_buf_set_option(floating_bufnr, 'modifiable', false)
|
||||
api.nvim_buf_set_option(floating_bufnr, 'bufhidden', 'wipe')
|
||||
api.nvim_buf_set_keymap(
|
||||
a.nvim_buf_set_option(floating_bufnr, 'modifiable', false)
|
||||
a.nvim_buf_set_option(floating_bufnr, 'bufhidden', 'wipe')
|
||||
a.nvim_buf_set_keymap(
|
||||
floating_bufnr,
|
||||
'n',
|
||||
'q',
|
||||
@ -1587,22 +1587,22 @@ function M.open_floating_preview(contents, syntax, opts)
|
||||
|
||||
-- save focus_id
|
||||
if opts.focus_id then
|
||||
api.nvim_win_set_var(floating_winnr, opts.focus_id, bufnr)
|
||||
a.nvim_win_set_var(floating_winnr, opts.focus_id, bufnr)
|
||||
end
|
||||
api.nvim_buf_set_var(bufnr, 'lsp_floating_preview', floating_winnr)
|
||||
a.nvim_buf_set_var(bufnr, 'lsp_floating_preview', floating_winnr)
|
||||
|
||||
return floating_bufnr, floating_winnr
|
||||
end
|
||||
|
||||
do --[[ References ]]
|
||||
local reference_ns = api.nvim_create_namespace('vim_lsp_references')
|
||||
local reference_ns = a.nvim_create_namespace('vim_lsp_references')
|
||||
|
||||
--- Removes document highlights from a buffer.
|
||||
---
|
||||
---@param bufnr number Buffer id
|
||||
function M.buf_clear_references(bufnr)
|
||||
validate({ bufnr = { bufnr, 'n', true } })
|
||||
api.nvim_buf_clear_namespace(bufnr or 0, reference_ns, 0, -1)
|
||||
a.nvim_buf_clear_namespace(bufnr or 0, reference_ns, 0, -1)
|
||||
end
|
||||
|
||||
--- Shows a list of document highlights for a certain buffer.
|
||||
@ -1750,7 +1750,7 @@ function M.symbols_to_items(symbols, bufnr)
|
||||
local kind = M._get_symbol_kind_name(symbol.kind)
|
||||
table.insert(_items, {
|
||||
-- bufnr = _bufnr,
|
||||
filename = vim.api.nvim_buf_get_name(_bufnr),
|
||||
filename = a.nvim_buf_get_name(_bufnr),
|
||||
lnum = symbol.selectionRange.start.line + 1,
|
||||
col = symbol.selectionRange.start.character + 1,
|
||||
kind = kind,
|
||||
@ -1788,7 +1788,7 @@ function M.trim_empty_lines(lines)
|
||||
break
|
||||
end
|
||||
end
|
||||
return vim.list_extend({}, lines, start, finish)
|
||||
return list_extend({}, lines, start, finish)
|
||||
end
|
||||
|
||||
--- Accepts markdown lines and tries to reduce them to a filetype if they
|
||||
@ -1824,11 +1824,11 @@ end
|
||||
---@param offset_encoding string utf-8|utf-16|utf-32|nil defaults to `offset_encoding` of first client of buffer of `window`
|
||||
local function make_position_param(window, offset_encoding)
|
||||
window = window or 0
|
||||
local buf = vim.api.nvim_win_get_buf(window)
|
||||
local row, col = unpack(api.nvim_win_get_cursor(window))
|
||||
local buf = a.nvim_win_get_buf(window)
|
||||
local row, col = unpack(a.nvim_win_get_cursor(window))
|
||||
offset_encoding = offset_encoding or M._get_offset_encoding(buf)
|
||||
row = row - 1
|
||||
local line = api.nvim_buf_get_lines(buf, row, row + 1, true)[1]
|
||||
local line = a.nvim_buf_get_lines(buf, row, row + 1, true)[1]
|
||||
if not line then
|
||||
return { line = 0, character = 0 }
|
||||
end
|
||||
@ -1846,7 +1846,7 @@ end
|
||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
|
||||
function M.make_position_params(window, offset_encoding)
|
||||
window = window or 0
|
||||
local buf = vim.api.nvim_win_get_buf(window)
|
||||
local buf = a.nvim_win_get_buf(window)
|
||||
offset_encoding = offset_encoding or M._get_offset_encoding(buf)
|
||||
return {
|
||||
textDocument = M.make_text_document_params(buf),
|
||||
@ -1898,7 +1898,7 @@ end
|
||||
---@returns { textDocument = { uri = `current_file_uri` }, range = { start =
|
||||
---`current_position`, end = `current_position` } }
|
||||
function M.make_range_params(window, offset_encoding)
|
||||
local buf = vim.api.nvim_win_get_buf(window or 0)
|
||||
local buf = a.nvim_win_get_buf(window or 0)
|
||||
offset_encoding = offset_encoding or M._get_offset_encoding(buf)
|
||||
local position = make_position_param(window, offset_encoding)
|
||||
return {
|
||||
@ -1924,10 +1924,10 @@ function M.make_given_range_params(start_pos, end_pos, bufnr, offset_encoding)
|
||||
end_pos = { end_pos, 't', true },
|
||||
offset_encoding = { offset_encoding, 's', true },
|
||||
})
|
||||
bufnr = bufnr or vim.api.nvim_get_current_buf()
|
||||
bufnr = bufnr or a.nvim_get_current_buf()
|
||||
offset_encoding = offset_encoding or M._get_offset_encoding(bufnr)
|
||||
local A = list_extend({}, start_pos or api.nvim_buf_get_mark(bufnr, '<'))
|
||||
local B = list_extend({}, end_pos or api.nvim_buf_get_mark(bufnr, '>'))
|
||||
local A = list_extend({}, start_pos or a.nvim_buf_get_mark(bufnr, '<'))
|
||||
local B = list_extend({}, end_pos or a.nvim_buf_get_mark(bufnr, '>'))
|
||||
-- convert to 0-index
|
||||
A[1] = A[1] - 1
|
||||
B[1] = B[1] - 1
|
||||
|
Loading…
Reference in New Issue
Block a user