~gpanders/dotfiles

ref: aa7f35c908534aa4b9ffcb5e02832b8bcdf76173 dotfiles/.config/nvim/plugin/lspconfig.vim -rw-r--r-- 1.5 KiB
aa7f35c9Gregory Anders nvim: set cursorline autocmds in init.vim 2 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
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()
augroup END