~keving/dotfiles

ref: f67a30c111b00d1de11876b92557123dcfa838df dotfiles/.config/nvim/lua/plugin_configs/nvim-lspconfig.lua -rw-r--r-- 1.8 KiB
f67a30c1 — Kevin Guillaumond Add shortcut to show line diagnostic in floating window 1 year, 5 days 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
local cmd = vim.cmd

local utils = require('utils')

-- Set up language servers
require'lspconfig'.clangd.setup{
  -- on_attach = keybinds.on_attach,
  cmd = {
    'clangd',
    '--background-index',
    '--suggest-missing-includes',
    -- '--query-driver="/usr/local/opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc"'
  },
  filetypes = {'c', 'cpp'},
}
require'lspconfig'.pyright.setup{
  filetypes = {'python'},
}


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

utils.map('n', '<leader>rr', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
utils.map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
utils.map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
utils.map('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
utils.map('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
if vim.fn.has 'nvim-0.6' == 1 then
	utils.map('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
	utils.map('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
	utils.map('n', '<leader>df', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
else
	utils.map('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
	utils.map('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
	utils.map('n', '<leader>df', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
end
utils.map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) -- TODO still try vim docs first

-- TODO Map K to this so it shows vim documentation first
-- vim.api.nvim_exec([[
-- function! s:show_documentation()
--   if (index(['vim','help'], &filetype) >= 0)
--     execute 'h '.expand('<cword>')
--   else
--     call <cmd>lua vim.lsp.buf.hover()<CR>
--   endif
-- endfunction
-- ]], false)

-- Disable LSP diagnostics for now
vim.lsp.handlers['textDocument/publishDiagnostics'] = function() end