" Configure neovim 0.6+ experimental LSPs " https://github.com/neovim/nvim-lspconfig " https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md " https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization " https://gitlab.com/Iron_E/dotfiles/-/blob/master/.config/nvim/lua/_config/plugin/nvim_lsp.lua lua <e', 'lua vim.diagnostic.open_float()', opts) vim.api.nvim_set_keymap('n', 'g[', 'lua vim.diagnostic.goto_prev()', opts) vim.api.nvim_set_keymap('n', 'g]', 'lua vim.diagnostic.goto_next()', opts) vim.api.nvim_set_keymap('n', 'dq', 'lua vim.diagnostic.setloclist()', opts) vim.api.nvim_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) local on_attach = function(client, bufnr) -- Enable completion triggered by 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', 'lua vim.lsp.buf.declaration()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', 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 }) end local lspconfig = require 'lspconfig' -- Add additional capabilities supported by nvim-cmp local CAPABILITIES = require('cmp_nvim_lsp').default_capabilities() --- 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), } -- 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) if config == nil then config = {} end 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') setup('ts_ls') setup('denols') setup('vuels') setup('svelte') setup('html') setup('yamlls') setup('jsonls', { json = { schemas = require('schemastore').json.schemas(), validate = { enable = true } } }) setup('gopls', { settings = { gopls = { semanticTokens = true } } }) setup('phpactor') setup('ruff_lsp') -- python3 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 EOF