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-05 21:56:03 +00:00
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
lua <<EOF
|
2022-01-05 21:56:03 +00:00
|
|
|
|
2024-08-19 08:18:12 +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', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
|
|
|
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)
|
|
|
|
vim.api.nvim_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
-- 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)
|
|
|
|
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>D', '<cmd>lua vim.lsp.buf.type_definition()<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
|
|
|
|
})
|
2022-01-19 00:13:15 +00:00
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
end
|
2022-06-04 14:49:07 +00:00
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
local lspconfig = require 'lspconfig'
|
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
|
|
local CAPABILITIES = require('cmp_nvim_lsp').default_capabilities()
|
2022-06-04 14:49:07 +00:00
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
--- Event handlers
|
|
|
|
local HANDLERS = {
|
|
|
|
-- 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),
|
|
|
|
}
|
2022-06-04 14:49:07 +00:00
|
|
|
|
2024-08-19 08:18:12 +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
|
2021-06-28 12:01:19 +00:00
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
local function setup(lsp, config)
|
|
|
|
if config == nil then
|
|
|
|
config = {}
|
2023-11-10 18:48:06 +00:00
|
|
|
end
|
|
|
|
|
2024-08-19 08:18:12 +00:00
|
|
|
config.capabilities = CAPABILITIES
|
|
|
|
config.handlers = HANDLERS
|
|
|
|
config.on_attach = on_attach
|
|
|
|
lspconfig[lsp].setup(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
setup('nixd')
|
|
|
|
setup('bashls')
|
|
|
|
setup('clangd')
|
|
|
|
setup('cssls')
|
|
|
|
setup('eslint')
|
2024-09-24 12:31:20 +00:00
|
|
|
setup('ts_ls')
|
2024-08-19 08:18:12 +00:00
|
|
|
setup('denols')
|
|
|
|
setup('vuels')
|
|
|
|
setup('svelte')
|
|
|
|
setup('html')
|
|
|
|
setup('yamlls')
|
|
|
|
setup('jsonls', {
|
|
|
|
json = {
|
|
|
|
schemas = require('schemastore').json.schemas(),
|
|
|
|
validate = {
|
|
|
|
enable = true
|
|
|
|
}
|
2022-01-05 21:56:03 +00:00
|
|
|
}
|
2024-08-19 08:18:12 +00:00
|
|
|
})
|
|
|
|
setup('gopls', {
|
|
|
|
settings = {
|
|
|
|
gopls = { semanticTokens = true }
|
2022-06-04 14:49:07 +00:00
|
|
|
}
|
2024-08-19 08:18:12 +00:00
|
|
|
})
|
|
|
|
setup('phpactor')
|
2024-11-11 17:02:10 +00:00
|
|
|
setup('ruff_lsp') -- python3
|
2024-08-19 08:18:12 +00:00
|
|
|
setup('solargraph') -- ruby
|
|
|
|
setup('rust_analyzer', {
|
|
|
|
settings = {
|
|
|
|
['rust-analyzer'] = {
|
|
|
|
checkOnSave = { extraArgs = { "--target-dir", "/tmp/rust-analyzer-check" } },
|
|
|
|
diagnostics = { disabled = { 'inactive-code' } },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
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 = {
|
|
|
|
"ts=typescript"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Configure diagnostics
|
|
|
|
vim.diagnostic.config({
|
|
|
|
virtual_text = false,
|
|
|
|
signs = true,
|
|
|
|
underline = true,
|
|
|
|
update_in_insert = false,
|
|
|
|
severity_sort = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Change diagnostic symbols in the sign column (gutter)
|
|
|
|
local signs = { Error = "x ", Warn = "! ", Hint = "? ", Info = "i " }
|
|
|
|
for type, icon in pairs(signs) do
|
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
|
|
end
|
2022-04-09 14:47:28 +00:00
|
|
|
EOF
|