Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
166 lines
6.4 KiB
Lua
166 lines
6.4 KiB
Lua
local M = {}
|
|
|
|
function M.server_ready()
|
|
return vim.b.lsp_server_ready
|
|
end
|
|
|
|
function M.lsp_diagnostic_count()
|
|
if vim.diagnostic.count then
|
|
return vim.diagnostic.count(0)
|
|
end
|
|
return {}
|
|
end
|
|
|
|
M.clients = {}
|
|
-- store the clients for different filetype
|
|
-- which can be called via vim.lsp.start_client()
|
|
|
|
function M.register(filetype, cmd)
|
|
M.clients[filetype] = {
|
|
['cmd'] = cmd,
|
|
}
|
|
end
|
|
|
|
function M.setup(enabled_clients, override_client_cmds) -- {{{
|
|
local nvim_lsp = require('lspconfig')
|
|
-- LspAttach and LspDetach event require nvim-0.8.0
|
|
if vim.fn.has('nvim-0.8.0') == 1 then
|
|
local augroup = vim.api.nvim_create_augroup('spacevim_lsp', { clear = true })
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = augroup,
|
|
callback = function(args)
|
|
vim.api.nvim_buf_set_var(args.buf, 'lsp_server_ready', true)
|
|
end,
|
|
})
|
|
vim.api.nvim_create_autocmd('LspDetach', {
|
|
group = augroup,
|
|
callback = function(args)
|
|
vim.api.nvim_buf_set_var(args.buf, 'lsp_server_ready', false)
|
|
end,
|
|
})
|
|
end
|
|
|
|
-- Use an on_attach function to only map the following keys
|
|
-- after the language server attaches to the current buffer
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...)
|
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
end
|
|
local function buf_set_option(...)
|
|
vim.api.nvim_buf_set_option(bufnr, ...)
|
|
end
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
-- Mappings.
|
|
-- local opts = { noremap=true, silent=true }
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
-- buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
-- buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
-- buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
-- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
-- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>e', '<cmd>lua require("spacevim.diagnostic").show_line_diagnostics()<CR>', opts)
|
|
-- buf_set_keymap('n', '[d', '<cmd>lua require("spacevim.diagnostic").goto_prev()<CR>', opts)
|
|
-- buf_set_keymap('n', ']d', '<cmd>lua require("spacevim.diagnostic").goto_next()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>q', '<cmd>lua require("spacevim.diagnostic").set_loclist()<CR>', opts)
|
|
-- buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
end
|
|
|
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
|
-- map buffer local keybindings when the language server attaches
|
|
for _, lsp in ipairs(enabled_clients) do
|
|
nvim_lsp[lsp].setup({
|
|
on_attach = on_attach,
|
|
flags = {
|
|
debounce_text_changes = 150,
|
|
},
|
|
})
|
|
end
|
|
for client, override_cmd in pairs(override_client_cmds) do
|
|
if type(client) == 'string' then
|
|
nvim_lsp[client].setup({
|
|
cmd = override_cmd,
|
|
on_attach = on_attach,
|
|
flags = {
|
|
debounce_text_changes = 150,
|
|
},
|
|
})
|
|
end
|
|
end
|
|
end
|
|
-- }}}
|
|
|
|
local function spliteof(data, delimiter)
|
|
local result = {}
|
|
local from = 1
|
|
local delim_from, delim_to = string.find(data, delimiter, from)
|
|
while delim_from do
|
|
table.insert(result, string.sub(data, from, delim_from - 1))
|
|
from = delim_to + 1
|
|
delim_from, delim_to = string.find(data, delimiter, from)
|
|
end
|
|
table.insert(result, string.sub(data, from))
|
|
return result
|
|
end
|
|
--
|
|
-- if data.contents is a string and not empty
|
|
-- silent put =a:data
|
|
-- return 'markdown'
|
|
-- if data
|
|
function M.hover_callback(success, data)
|
|
if not success then
|
|
vim.api.nvim_command('call SpaceVim#util#echoWarn("Failed to retrieve hover information")')
|
|
return
|
|
end
|
|
if type(data.contents) == 'table' then
|
|
vim.api.nvim_command('leftabove split __lspdoc__')
|
|
vim.api.nvim_command('set filetype=markdown.lspdoc')
|
|
vim.api.nvim_command('setlocal nobuflisted')
|
|
vim.api.nvim_command('setlocal buftype=nofile')
|
|
vim.api.nvim_command('setlocal bufhidden=wipe')
|
|
vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents.value, '\n'))
|
|
elseif type(data.contents) == 'string' and data.contents ~= '' then
|
|
-- for k, v in pairs(data) do
|
|
-- print(k .. " - " .. v)
|
|
-- kind is filetype
|
|
-- value is contents string
|
|
-- end
|
|
vim.api.nvim_command('leftabove split __lspdoc__')
|
|
vim.api.nvim_command('set filetype=markdown.lspdoc')
|
|
vim.api.nvim_command('setlocal nobuflisted')
|
|
vim.api.nvim_command('setlocal buftype=nofile')
|
|
vim.api.nvim_command('setlocal bufhidden=wipe')
|
|
vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, '\n'))
|
|
elseif type(data.contents.language) ~= 'string' and data.contents.language ~= '' then
|
|
vim.api.nvim_command('leftabove split __lspdoc__')
|
|
vim.api.nvim_command('set filetype=markdown.lspdoc')
|
|
vim.api.nvim_command('setlocal nobuflisted')
|
|
vim.api.nvim_command('setlocal buftype=nofile')
|
|
vim.api.nvim_command('setlocal bufhidden=wipe')
|
|
vim.api.nvim_buf_set_lines(0, 0, -1, 0, { '```' .. data.contents.language })
|
|
vim.api.nvim_buf_set_lines(0, 1, -1, 0, spliteof(data.contents, '\n'))
|
|
vim.api.nvim_buf_set_lines(0, -1, -1, 0, { '```' })
|
|
elseif type(data.contents.kind) ~= 'string' and data.contents.kind ~= '' then
|
|
vim.api.nvim_command('leftabove split __lspdoc__')
|
|
vim.api.nvim_command('set filetype=' .. data.contents.kind .. '.lspdoc')
|
|
vim.api.nvim_command('setlocal nobuflisted')
|
|
vim.api.nvim_command('setlocal buftype=nofile')
|
|
vim.api.nvim_command('setlocal bufhidden=wipe')
|
|
vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, '\n'))
|
|
else
|
|
print('No hover information found')
|
|
end
|
|
-- print(type(data))
|
|
end
|
|
return M
|