config/nvim/lua/lsp/init.lua (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
local status_ok, lspconfig = pcall(require, "lspconfig") if not status_ok then return end local signs = { { name = "DiagnosticSignError", text = "" }, { name = "DiagnosticSignWarn", text = "" }, { name = "DiagnosticSignHint", text = "" }, { name = "DiagnosticSignInfo", text = "" }, } for _, sign in ipairs(signs) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) end local config = { virtual_text = false, signs = { active = signs, }, update_in_insert = true, underline = true, severity_sort = true, float = { focusable = false, style = "minimal", border = "none", -- max_width = 80, source = "always", header = "", prefix = "", }, } -- TODO set this up when upgrading to Neovim v0.8 local navic = require('nvim-navic') vim.diagnostic.config(config) vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded", }) local capabilities = vim.lsp.protocol.make_client_capabilities() local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not status_ok then return end capabilities = cmp_nvim_lsp.update_capabilities(capabilities) local opts = { noremap=true, silent=true } vim.keymap.set('n', 'gl', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, 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. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', '<leader>]', vim.lsp.buf.formatting, bufopts) -- TODO set this up when upgrading to Neovim v0.8 if client.server_capabilities.documentSymbolProvider then navic.attach(client, bufnr) end end lspconfig.pyright.setup{ capabilities = capabilities, on_attach = on_attach, settings = { python = { analysis = { typeCheckingMode = "off" } } } } lspconfig.gopls.setup{ capabilities = capabilities, on_attach = on_attach } lspconfig.tsserver.setup{ capabilities = capabilities, on_attach = on_attach, } -- local null_ls = require("null-ls") null_ls.setup({ debug = false, on_attach = on_attach, sources = { -- (java|type)script null_ls.builtins.formatting.prettierd, -- python null_ls.builtins.formatting.black.with({extra_args={"--fast"}}), null_ls.builtins.formatting.isort.with({extra_args={"--profile", "black"}}), -- null_ls.builtins.diagnostics.flake8.with({ -- condition = function(utils) -- return utils.root_has_file({".flake8"}) -- end, -- }), -- null_ls.builtins.diagnostics.mypy.with({ -- condition = function(utils) -- return utils.root_has_file({"pyproject.toml"}) -- end, -- }), }, }) |