132 lines
5.5 KiB
Lua
132 lines
5.5 KiB
Lua
local nvim_lsp = require 'lspconfig'
|
|
local utils = require('utils')
|
|
|
|
local system_name
|
|
if vim.fn.has("mac") == 1 then
|
|
system_name = "macOS"
|
|
elseif vim.fn.has("unix") == 1 then
|
|
system_name = "Linux"
|
|
elseif vim.fn.has('win32') == 1 then
|
|
system_name = "Windows"
|
|
else
|
|
print("Unsupported system for sumneko")
|
|
end
|
|
|
|
local sumneko_root_path = 'D:/tmp/lua-language-server'
|
|
local sumneko_binary = sumneko_root_path.."/bin/"..system_name.."/lua-language-server"
|
|
-- We use the default settings for ccls and pylsp: the option table can stay empty
|
|
-- nvim_lsp.ccls.setup {}
|
|
nvim_lsp.pyright.setup{}
|
|
nvim_lsp.clangd.setup{}
|
|
nvim_lsp.cmake.setup{}
|
|
nvim_lsp.jsonls.setup{}
|
|
nvim_lsp.groovyls.setup{
|
|
-- Unix
|
|
cmd = { "java", "-jar", "D:/tmp/groovy-language-server/build/libs/groovy-language-server-all.jar" }
|
|
}
|
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities.textDocument.completion.completionItem.documentationFormat = { 'markdown', 'plaintext' }
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
|
capabilities.textDocument.completion.completionItem.preselectSupport = true
|
|
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
|
|
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
|
|
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
|
|
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
|
|
capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
|
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
|
properties = {
|
|
'documentation',
|
|
'detail',
|
|
'additionalTextEdits',
|
|
},
|
|
}
|
|
|
|
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
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
-- Mappings.
|
|
local opts = { noremap=true, silent=true }
|
|
utils.map('n', '<space>,', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
|
utils.map('n', '<space>;', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
|
utils.map('n', '<space>a', '<cmd>Telescope lsp_code_actions<CR>', opts)
|
|
utils.map('n', '<space>d', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
utils.map('n', '<space>e', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
utils.map('n', '<space>h', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
utils.map('n', '<space>c', '<cmd>lua vim.lsp.buf.outgoing_calls()<CR>', opts)
|
|
utils.map('n', '<space>C', '<cmd>lua vim.lsp.buf.incoming_calls()<CR>', opts)
|
|
utils.map('n', '<space>m', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
-- utils.map('n', '<space>r', '<cmd>lua vim.lsp.buf.references()<CR, opts>')
|
|
utils.map('n', '<space>s', '<cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
|
|
utils.map('n', '<C-t>', '<cmd>Telescope lsp_dynamic_workspace_symbols<CR>', opts)
|
|
utils.map('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
utils.map('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
utils.map('n', '<space>r', '<cmd>Telescope lsp_references<cr>')
|
|
utils.map('n', '<C-S-o>', '<cmd>Telescope lsp_document_symbols<cr>')
|
|
utils.map('n', '<A-m>', '<cmd>Telescope lsp_document_symbols<cr>')
|
|
utils.map('n', '<space>v', '<cmd>Telescope lsp_document_diagnostics<cr>')
|
|
utils.map('n', '<A-o>', ':ClangdSwitchSourceHeader<CR>', opts)
|
|
|
|
-- Set some keybinds conditional on server capabilities
|
|
if client.resolved_capabilities.document_formatting then
|
|
utils.map('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
end
|
|
if client.resolved_capabilities.document_range_formatting then
|
|
utils.map('v', '<space>f', '<esc><cmd>lua vim.lsp.buf.range_formatting()<CR>', opts)
|
|
end
|
|
|
|
-- Set autocommands conditional on server_capabilities
|
|
if client.resolved_capabilities.document_highlight then
|
|
vim.api.nvim_exec([[
|
|
hi LspReferenceRead cterm=bold ctermbg=red guibg=DarkGreen
|
|
hi LspReferenceText cterm=bold ctermbg=Black guibg=DarkYellow guifg=Black
|
|
hi LspReferenceWrite cterm=bold ctermbg=red guibg=DarkRed
|
|
augroup lsp_document_highlight
|
|
autocmd! * <buffer>
|
|
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
|
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
|
|
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
|
augroup END
|
|
]], false)
|
|
end
|
|
require "lsp_signature".on_attach({
|
|
bind = true, -- This is mandatory, otherwise border config won't get registered.
|
|
handler_opts = {
|
|
border = "single"
|
|
},
|
|
hi_parameter = "IncSearch"
|
|
}, bufnr)
|
|
end
|
|
|
|
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
|
local servers = {'clangd', 'pyright', 'cmake', 'jsonls'}
|
|
for _, lsp in ipairs(servers) do
|
|
nvim_lsp[lsp].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
nvim_lsp.sumneko_lua.setup{
|
|
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
nvim_lsp.groovyls.setup{
|
|
-- Unix
|
|
cmd = { "java", "-jar", "D:/tmp/groovy-language-server/build/libs/groovy-language-server-all.jar" },
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
local signs = { Error = " ", Warning = " ", Hint = " ", Information = " " }
|
|
for type, icon in pairs(signs) do
|
|
local hl = "LspDiagnosticsSign" .. type
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
|
end
|