cmp polish, dotenv, improve lsp leader mappings

This commit is contained in:
Amanda Graven 2023-06-22 16:30:49 +02:00
parent 524afbb9aa
commit adefe5c331

View file

@ -62,7 +62,7 @@ vim.cmd 'filetype plugin indent on'
-- Enable persistent undo
if fn.has('persistent_undo') then
o.undodir = fn.expand('~/.local/share/nvim/undo')
o.undodir = fn.stdpath('data') .. '/undo'
o.undofile = true
end
@ -286,6 +286,8 @@ require'packer'.startup(function(use)
-- LSP --
use 'neovim/nvim-lspconfig'
use 'hrsh7th/nvim-cmp'
use 'rcarriga/cmp-dap'
use 'hrsh7th/cmp-nvim-lua'
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
@ -609,6 +611,12 @@ require'packer'.startup(function(use)
use 'antoinemadec/FixCursorHold.nvim'
end
use 'lewis6991/impatient.nvim' -- speeds up load times
use {'ellisonleao/dotenv.nvim', config = function ()
require'dotenv'.setup {
enable_on_load = false,
verbose = true,
}
end}
-- Finish bootstrap if we just cloned
if packer_bootstrap then
@ -744,16 +752,21 @@ local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local cmp = require'cmp'
local cmp_dap = require'cmp_dap'
cmp.setup {
enabled = function ()
return vim.bo.buftype ~= 'prompt' or cmp_dap.is_dap_buffer()
end,
preselect = cmp.PreselectMode.None,
snippet = {
expand = function(args)
vim.fn['vsnip#anonymous'](args.body)
end,
},
mapping = {
mapping = cmp.mapping.preset.insert {
-- Next item, or expand or jump snippet, or fallback
['<Tab>'] = cmp.mapping(function(fallback)
['<Tab>'] = cmp.mapping(
function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn['vsnip#available'](1) == 1 then
@ -761,9 +774,12 @@ cmp.setup {
else
fallback()
end
end, {'i', 's'}),
end,
{'i', 's'}
),
-- Prev item, or jump snippet back, or fallback
['<S-Tab>'] = cmp.mapping(function(fallback)
['<S-Tab>'] = cmp.mapping(
function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn['vsnip#available'](-1) == 1 then
@ -771,7 +787,13 @@ cmp.setup {
else
fallback()
end
end, {'i', 's'}),
end,
{'i', 's'}
),
-- Scroll documentation up
['<C-e'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
-- Scroll documentation down
['<C-y>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
-- Complete common substring
['<C-l>'] = cmp.mapping(cmp.mapping.complete_common_string(), {'i', 'c'}),
-- Complete
@ -782,6 +804,7 @@ cmp.setup {
sources = {
{ name = 'path' },
{ name = 'nvim_lsp' },
{ name = 'nvim_lua' },
{ name = 'vsnip' },
},
-- Experimental features
@ -790,6 +813,31 @@ cmp.setup {
ghost_text = true,
},
}
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
},
{
{
name = 'cmdline',
option = {
ignore_cmds = { 'Man', '!' }
}
}
}),
})
cmp.setup.cmdline({'/', '?'}, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
},
})
cmp.setup.filetype({'dap-repl', 'dapui_watches', 'dapui_hover'}, {
sources = {
{ name = 'dap' },
},
})
local capabilities = require'cmp_nvim_lsp'.default_capabilities()
---- lsp: language servers ----
@ -800,8 +848,9 @@ local function on_attach(client, bufnr)
require'which-key'.register({
['<Leader>l'] = {
d = {vim.lsp.buf.definition, 'Goto definition'},
D = {vim.lsp.buf.implementation, 'Goto implementation'},
D = {vim.lsp.buf.declaration, 'Declaration'},
d = {vim.lsp.buf.definition, 'Definition'},
i = {vim.lsp.buf.implementation, 'Implementation'},
a = {vim.lsp.buf.code_action, 'Code action'},
r = {vim.lsp.buf.rename, 'Rename'},
t = {vim.lsp.buf.type_definition, 'Type definition'},
@ -839,8 +888,6 @@ local function on_attach(client, bufnr)
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
require'nvim-navic'.attach(client, bufnr)
au('CursorMoved', { callback = vim.lsp.buf.clear_references, buffer = bufnr, })
end
-- Enable language servers