2022-04-09 14:47:28 +00:00
|
|
|
" Configure neovim 0.6+ experimental LSPs
|
2021-05-30 19:10:28 +00:00
|
|
|
" https://github.com/neovim/nvim-lspconfig
|
2022-04-09 14:47:28 +00:00
|
|
|
" https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
|
|
|
" https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization
|
2021-05-30 19:10:28 +00:00
|
|
|
" https://gitlab.com/Iron_E/dotfiles/-/blob/master/.config/nvim/lua/_config/plugin/nvim_lsp.lua
|
2022-01-19 00:13:15 +00:00
|
|
|
|
2024-08-18 22:07:22 +00:00
|
|
|
lua <<EOF
|
2022-06-04 14:49:07 +00:00
|
|
|
|
2024-08-18 22:07:22 +00:00
|
|
|
-- Set completeopt to have a better completion experience
|
|
|
|
vim.o.completeopt = 'menuone,noselect,noinsert'
|
|
|
|
vim.o.shortmess = vim.o.shortmess .. 'c'
|
|
|
|
vim.o.signcolumn = 'yes:2'
|
|
|
|
|
|
|
|
local lspconfig = require('lspconfig')
|
|
|
|
|
|
|
|
-- Mappings (global)
|
|
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
vim.api.nvim_set_keymap('n', 'g[', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', 'g]', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', '<leader>dq', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
|
2024-08-23 16:59:52 +00:00
|
|
|
vim.api.nvim_set_keymap('n', '<leader>do', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
|
|
|
vim.api.nvim_set_keymap('n', '<leader>bf', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
2024-08-18 22:07:22 +00:00
|
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
2024-08-18 22:23:24 +00:00
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
|
|
|
|
-- Mappings (available if LSP is configured and attached to buffer)
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
2024-08-23 16:59:52 +00:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gT', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
2024-08-18 22:23:24 +00:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
|
|
|
|
|
-- Show diagnostic popup on cursor hold
|
|
|
|
vim.api.nvim_create_autocmd("CursorHold", {
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = function()
|
|
|
|
local opts = {
|
|
|
|
focusable = false,
|
|
|
|
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
|
|
|
border = 'rounded',
|
|
|
|
source = 'always',
|
|
|
|
prefix = ' ',
|
|
|
|
scope = 'cursor',
|
|
|
|
}
|
|
|
|
vim.diagnostic.open_float(nil, opts)
|
|
|
|
end
|
|
|
|
})
|
2024-08-18 22:07:22 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local lspconfig = require 'lspconfig'
|
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
|
|
local CAPABILITIES = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
|
|
|
|
--- Event handlers
|
|
|
|
local HANDLERS = {
|
2024-08-18 22:23:24 +00:00
|
|
|
-- TODO: replace with vim.lsp.protocol.Methods
|
|
|
|
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, FLOAT_CONFIG),
|
|
|
|
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, FLOAT_CONFIG),
|
2024-08-18 22:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- vscode HTML lsp needs this https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#html
|
|
|
|
CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true
|
|
|
|
|
|
|
|
local function setup(lsp, config)
|
2024-08-18 22:23:24 +00:00
|
|
|
if config == nil then
|
|
|
|
config = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
config.capabilities = CAPABILITIES
|
|
|
|
config.handlers = HANDLERS
|
|
|
|
config.on_attach = on_attach
|
|
|
|
lspconfig[lsp].setup(config)
|
2024-08-18 22:07:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
setup('nixd')
|
|
|
|
setup('bashls')
|
|
|
|
setup('clangd')
|
|
|
|
setup('cssls')
|
|
|
|
setup('eslint')
|
|
|
|
setup('tsserver')
|
|
|
|
setup('denols')
|
|
|
|
setup('vuels')
|
|
|
|
setup('svelte')
|
|
|
|
setup('html')
|
|
|
|
setup('yamlls')
|
|
|
|
setup('jsonls', {
|
2024-08-18 22:23:24 +00:00
|
|
|
json = {
|
|
|
|
schemas = require('schemastore').json.schemas(),
|
|
|
|
validate = {
|
|
|
|
enable = true
|
|
|
|
}
|
|
|
|
}
|
2024-08-18 22:07:22 +00:00
|
|
|
})
|
|
|
|
setup('gopls', {
|
2024-08-18 22:23:24 +00:00
|
|
|
settings = {
|
|
|
|
gopls = { semanticTokens = true }
|
|
|
|
}
|
2024-08-18 22:07:22 +00:00
|
|
|
})
|
|
|
|
setup('phpactor')
|
|
|
|
setup('pylsp')
|
|
|
|
setup('solargraph') -- ruby
|
|
|
|
setup('rust_analyzer', {
|
2024-08-18 22:23:24 +00:00
|
|
|
settings = {
|
|
|
|
['rust-analyzer'] = {
|
|
|
|
checkOnSave = { extraArgs = { "--target-dir", "/tmp/rust-analyzer-check" } },
|
|
|
|
diagnostics = { disabled = { 'inactive-code' } },
|
|
|
|
},
|
|
|
|
}
|
2024-08-18 22:07:22 +00:00
|
|
|
})
|
|
|
|
setup('sqlls')
|
|
|
|
setup('salt_ls')
|
|
|
|
setup('ansiblels')
|
|
|
|
setup('dockerls')
|
|
|
|
setup('docker_compose_language_service')
|
|
|
|
setup('terraformls')
|
|
|
|
|
|
|
|
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#denols
|
|
|
|
vim.g.markdown_fenced_languages = {
|
2024-08-18 22:23:24 +00:00
|
|
|
"ts=typescript"
|
2024-08-18 22:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Configure diagnostics
|
|
|
|
vim.diagnostic.config({
|
2024-08-18 22:23:24 +00:00
|
|
|
virtual_text = false,
|
|
|
|
signs = true,
|
|
|
|
underline = true,
|
|
|
|
update_in_insert = false,
|
|
|
|
severity_sort = false,
|
2024-08-18 22:07:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Change diagnostic symbols in the sign column (gutter)
|
|
|
|
local signs = { Error = "x ", Warn = "! ", Hint = "? ", Info = "i " }
|
|
|
|
for type, icon in pairs(signs) do
|
2024-08-18 22:23:24 +00:00
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
2024-08-18 22:07:22 +00:00
|
|
|
end
|
2022-04-09 14:47:28 +00:00
|
|
|
EOF
|