1

Update generated neovim config

This commit is contained in:
2024-09-22 20:41:25 +02:00
parent 1743764e48
commit aa1271c42c
1247 changed files with 26512 additions and 15067 deletions

View File

@ -48,17 +48,89 @@ source.complete = function(self, params, callback)
end)
end
source.resolve = function(self, completion_item, callback)
--- get documentation in separate thread
---@param _ any
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
source.resolve = function(_, completion_item, callback)
local data = completion_item.data
if data.stat and data.stat.type == 'file' then
local ok, documentation = pcall(function()
return self:_get_documentation(data.path, constants.max_lines)
end)
if ok then
completion_item.documentation = documentation
end
---@diagnostic disable-next-line: undefined-field
if not data.stat or data.stat.type ~= 'file' then
-- return right away with no changes / no added docs
callback(completion_item)
return
end
callback(completion_item)
local work
work = assert(vim.uv.new_work(
--- Read file in thread
---@param filepath string
---@param count number max line count (-1 if no max)
---@return string|nil, string (error, serialized_table) either some error or the serialized table
function(filepath, count)
local ok, binary = pcall(io.open, filepath, 'rb')
if not ok or binary == nil then
---@diagnostic disable-next-line: redundant-return-value
return nil, vim.json.encode({
kind = "binary",
contents = "« cannot read this file »"
})
end
local first_kb = binary:read(1024)
if first_kb:find('\0') then
---@diagnostic disable-next-line: redundant-return-value
return nil, vim.json.encode({kind = "binary", contents = 'binary file'})
end
local contents = {}
for content in first_kb:gmatch("[^\r\n]+") do
table.insert(contents, content)
if count > -1 and #contents >= count then
break
end
end
---@diagnostic disable-next-line: redundant-return-value
return nil, vim.json.encode({contents = contents})
end,
--- deserialize doc and call callback(…)
---@param serialized_fileinfo string
function(worker_error, serialized_fileinfo)
if worker_error then
error(string.format("Worker error while fetching file doc: %s", worker_error))
end
local read_ok, file_info = pcall(vim.json.decode, serialized_fileinfo, {luanil = {object = true, array = true}})
if not read_ok then
error(string.format("Unexpected problem de-serializing item info: «%s»",
serialized_fileinfo))
end
if file_info.kind == "binary" then
completion_item.documentation = {
kind = cmp.lsp.MarkupKind.PlainText,
value = file_info.contents,
}
else
local contents = file_info.contents
local filetype = vim.filetype.match({contents = contents})
if not filetype then
completion_item.documentation = {
kind = cmp.lsp.MarkupKind.PlainText,
value = table.concat(contents, '\n'),
}
else
table.insert(contents, 1, '```' .. filetype)
table.insert(contents, '```')
completion_item.documentation = {
kind = cmp.lsp.MarkupKind.Markdown,
value = table.concat(contents, '\n'),
}
end
end
callback(completion_item)
end
))
work:queue(data.path, constants.max_lines or -1, cmp.lsp.MarkupKind.Markdown)
end
source._dirname = function(self, params, option)
@ -113,13 +185,22 @@ source._dirname = function(self, params, option)
end
source._candidates = function(_, dirname, include_hidden, option, callback)
local entries, err = vim.loop.fs_scandir(dirname)
local entries, err = vim.uv.fs_scandir(dirname)
if err then
return callback(err, nil)
end
local work
work = assert(vim.loop.new_work(
work = assert(vim.uv.new_work(
--- create path entries
---@param _entries uv_fs_t
---@param _dirname any see vim.fn.resolve()
---@param _include_hidden boolean
---@param label_trailing_slash boolean
---@param trailing_slash boolean
---@param file_kind table<string,number> see cmp.lsp.CompletionItemKind.Filee
---@param folder_kind table<string,number> see cmp.lsp.CompletionItemKind.Folder
---@return string|nil, string (error, serialized_results) "error text", nil or nil, "serialized items"
function(_entries, _dirname, _include_hidden,
label_trailing_slash, trailing_slash,
file_kind, folder_kind)
@ -131,13 +212,13 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
end
local path = _dirname .. '/' .. name
local stat = assert(vim.loop.fs_stat)(path)
local stat = assert(vim.uv.fs_stat)(path)
local lstat = nil
if stat then
fs_type = stat.type
elseif fs_type == 'link' then
-- Broken symlink
lstat = assert(vim.loop.fs_lstat)(_dirname)
lstat = assert(vim.uv.fs_lstat)(_dirname)
if not lstat then
return
end
@ -169,8 +250,9 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
end
while true do
local name, fs_type, e = assert(vim.loop.fs_scandir_next)(_entries)
local name, fs_type, e = assert(vim.uv.fs_scandir_next)(_entries)
if e then
---@diagnostic disable-next-line: redundant-return-value
return fs_type, ""
end
if not name then
@ -179,8 +261,13 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
create_item(name, fs_type)
end
---@diagnostic disable-next-line: redundant-return-value
return nil, vim.json.encode(items)
end, function(worker_error, serialized_items)
end,
---
---@param worker_error string|nil non-nil if some error happened in worker
---@param serialized_items string array-of-items serialized as string
function(worker_error, serialized_items)
if worker_error then
callback(err, nil)
return
@ -218,35 +305,5 @@ source._validate_option = function(_, params)
return option
end
source._get_documentation = function(_, filename, count)
local binary = assert(io.open(filename, 'rb'))
local first_kb = binary:read(1024)
if first_kb:find('\0') then
return {kind = cmp.lsp.MarkupKind.PlainText, value = 'binary file'}
end
local contents = {}
for content in first_kb:gmatch("[^\r\n]+") do
table.insert(contents, content)
if count ~= nil and #contents >= count then
break
end
end
local filetype = vim.filetype.match({filename = filename})
if not filetype then
return {
kind = cmp.lsp.MarkupKind.PlainText,
value = table.concat(contents, '\n'),
}
end
table.insert(contents, 1, '```' .. filetype)
table.insert(contents, '```')
return {
kind = cmp.lsp.MarkupKind.Markdown,
value = table.concat(contents, '\n'),
}
end
return source