~gpanders/dotfiles

ref: f9dc228895c7645f62bd304ad256035d46630887 dotfiles/.config/nvim/plugin/lspconfig.vim -rw-r--r-- 2.0 KiB
f9dc2288Gregory Anders nvim: replace ale with nvim-lint 3 months ago
                                                                                
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
function! s:load()
    packadd nvim-lspconfig
    if !exists('g:lspconfig')
        return
    endif

lua <<
local on_attach = function(client, bufnr)
    vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")

    local opts = { noremap = true, silent = true }

    vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-]>", "<Cmd>lua vim.lsp.buf.definition()<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", "gr", "<Cmd>lua vim.lsp.buf.references()<CR>", opts)
    vim.api.nvim_buf_set_keymap(bufnr, "n", "gR", "<Cmd>lua vim.lsp.buf.rename()<CR>", opts)

    vim.cmd "doautocmd User LspAttached"
end

local servers = {
    rust_analyzer = {},
    clangd = {},
    gopls = {
        analyses = {
            unusedparams = true,
            unusedwrite = true,
            nilness = true,
        },
    },
    pylsp = {
        configurationSources = { "flake8" },
    },
}

for server_name, settings in pairs(servers) do
    local config = require("lspconfig")[server_name]
    config.setup {
        on_attach = on_attach,
        settings = { server_name = settings },
        flags = {
            debounce_text_changes = 150,
        },
    }

    -- Start the server for the current buffer
    if vim.tbl_contains(config.filetypes, vim.bo.filetype) then
        config.autostart()
    end
end
.
endfunction

augroup load_lspconfig
    autocmd!
    autocmd FileType go,c,cpp,rust,python ++once call s:load()
    autocmd User LspDiagnosticsChanged lua vim.lsp.diagnostic.set_loclist({ open_loclist = false })
augroup END

hi link LspDiagnosticsDefaultError ErrorMsg
hi link LspDiagnosticsDefaultWarning WarningMsg
hi link LspDiagnosticsDefaultInformation Question
hi link LspDiagnosticsDefaultHint NonText

hi LspDiagnosticsSignError ctermfg=1 ctermbg=10
hi LspDiagnosticsSignWarning ctermfg=3 ctermbg=10
hi LspDiagnosticsSignInformation ctermfg=4 ctermbg=10
hi LspDiagnosticsSignHint ctermfg=7 ctermbg=10