[neovim] Set up all the LSP key bindings
This commit is contained in:
parent
47a622250f
commit
b381ff362d
2 changed files with 64 additions and 0 deletions
|
@ -20,3 +20,33 @@ map('n', '<C-p>', ':bp<CR>', options)
|
|||
map('n', '<leader><space>', function()
|
||||
vim.cmd [[ setlocal invhlsearch ]]
|
||||
end, options)
|
||||
|
||||
--
|
||||
-- Language Server mappings
|
||||
--
|
||||
|
||||
-- Basic diagnostic mappings, these will navigate to or display diagnostics
|
||||
local diagnostic_options = { noremap=true, silent=true }
|
||||
map('n', '<leader>d', vim.diagnostic.open_float, diagnostic_options)
|
||||
map('n', '[d', vim.diagnostic.goto_prev, diagnostic_options)
|
||||
map('n', ']d', vim.diagnostic.goto_next, diagnostic_options)
|
||||
map('n', '<leader>q', vim.diagnostic.setloclist, diagnostic_options)
|
||||
|
||||
function set_up_local_lsp_mappings(buffer_number)
|
||||
local options = { noremap=true, silent=true, buffer=buffer_number }
|
||||
|
||||
map('n', 'gD', vim.lsp.buf.declaration, options)
|
||||
map('n', 'gd', vim.lsp.buf.definition, options)
|
||||
map('n', 'gk', vim.lsp.buf.hover, options)
|
||||
map('n', 'gi', vim.lsp.buf.implementation, options)
|
||||
map('n', 'gK', vim.lsp.buf.signature_help, options)
|
||||
map('n', '<leader>D', vim.lsp.buf.type_definition, options)
|
||||
map('n', '<leader>rn', vim.lsp.buf.rename, options)
|
||||
map('n', '<leader>ca', vim.lsp.buf.code_action, options)
|
||||
map('n', 'gr', vim.lsp.buf.references, options)
|
||||
|
||||
-- Replace <leader>W in .vimrc.common
|
||||
map('n', '<leader>W', function()
|
||||
vim.lsp.buf.format { async = true }
|
||||
end, options)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
local clangd_extensions = require 'clangd_extensions'
|
||||
local cmp = require 'cmp'
|
||||
local keys = require 'keys'
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
cmp.setup {
|
||||
|
@ -9,9 +11,29 @@ cmp.setup {
|
|||
},
|
||||
window = {
|
||||
-- completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
-- Accept currently selected item. Set `select` to `false` to only
|
||||
-- confirm explicitly selected items.
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
}),
|
||||
sorting = {
|
||||
comparators = {
|
||||
cmp.config.compare.offset,
|
||||
cmp.config.compare.exact,
|
||||
cmp.config.compare.recently_used,
|
||||
clangd_extensions.cmp_scores,
|
||||
cmp.config.compare.kind,
|
||||
cmp.config.compare.sort_text,
|
||||
cmp.config.compare.length,
|
||||
cmp.config.compare.order,
|
||||
},
|
||||
},
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "nvim_signature_help" },
|
||||
|
@ -29,8 +51,20 @@ local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|||
|
||||
local on_attach = function(client, buffer_number)
|
||||
vim.api.nvim_buf_set_option(buffer_number, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
||||
keys.set_up_local_lsp_mappings(buffer_number)
|
||||
end
|
||||
|
||||
lspconfig.clangd.setup {
|
||||
on_attach = function(client, buffer_number)
|
||||
on_attach(client, buffer_number)
|
||||
|
||||
local clangd_inlay_hints = require('clangd_extensions.inlay_hints')
|
||||
clangd_inlay_hints.setup_autocmd()
|
||||
clangd_inlay_hints.set_inlay_hints()
|
||||
end,
|
||||
capabilities = cmp_capabilities,
|
||||
}
|
||||
|
||||
lspconfig.eslint.setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = cmp_capabilities,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue