nvim: Switch to lsp-zero

lsp-zero offers a simple to set-up lsp configuration which is based
around the plugins I use anyway (lsp, cmp, luasnip) but integrates them
very well. I add a few small quality of life things on top (cmp
completion for / search and for vim command mode) as well as a boatload
of custom completion sources but otherwise make use of the nice presets.

This has de-bloated my _cmp.lua settings somewhat and allows me to have
a simple treesitter and a simple(r) lsp setup!

Additionally, switched to mason.nvim to manage my lsp sources (and
linters), which is both the new hotness and actually really useful.
Allows portable installation of most lsp servers into neovim data
directory so they do not clutter any other directories or global
namespaces.
This commit is contained in:
Marty Oehme 2023-02-10 15:33:33 +01:00
parent ee4640b186
commit 2026f6d064
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 137 additions and 195 deletions

View file

@ -1,5 +1,6 @@
{
"BetterLua.vim": { "branch": "master", "commit": "d2d6c115575d09258a794a6f20ac60233eee59d5" },
"LuaSnip": { "branch": "master", "commit": "500981ff6cefc7343e3959ef0f939bd0bfd49ba9" },
"Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" },
"bats.vim": { "branch": "master", "commit": "6a5d2ef22b0ede503d867770afd02ebb1f97b709" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
@ -12,7 +13,7 @@
"cmp-spell": { "branch": "master", "commit": "60584cb75e5e8bba5a0c9e4c3ab0791e0698bffa" },
"cmp-tmux": { "branch": "main", "commit": "984772716f66d8ee88535a6bf3f94c4b4e1301f5" },
"cmp-treesitter": { "branch": "master", "commit": "b40178b780d547bcf131c684bc5fd41af17d05f2" },
"cmp-vsnip": { "branch": "main", "commit": "989a8a73c44e926199bfd05fa7a516d51f2d2752" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"completion-vcard": { "branch": "master", "commit": "2220fd517a985ececed1adcf0e5be8f2815564c7" },
"dial.nvim": { "branch": "master", "commit": "5020da900cc5dfd7067f181ee2ebd872ca7c84e8" },
"formatter.nvim": { "branch": "master", "commit": "8a4c961330cc4688087f23d18fa7d2f1af9a4902" },
@ -21,11 +22,14 @@
"guihua.lua": { "branch": "master", "commit": "d3f6d01639b52e6a83ea98dd6ca244c9aa98b79b" },
"lazy.nvim": { "branch": "main", "commit": "273081443471cbc52c327bcb99614c32f247998d" },
"lightspeed.nvim": { "branch": "main", "commit": "299eefa6a9e2d881f1194587c573dad619fdb96f" },
"lsp-format.nvim": { "branch": "master", "commit": "ca0df5c8544e51517209ea7b86ecc522c98d4f0a" },
"lsp-zero.nvim": { "branch": "main", "commit": "42bc5a1081666098a7154532e6ff5e3edc483b39" },
"lsp_signature.nvim": { "branch": "master", "commit": "6f6252f63b0baf0f2224c4caea33819a27f3f550" },
"lspkind-nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" },
"lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" },
"magma-nvim-goose": { "branch": "main", "commit": "94370733757d550594fe4a1d65643949d7485989" },
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "7a97a77eee486ae152d2c559a459eda7c8aa12aa" },
"mason.nvim": { "branch": "main", "commit": "14ae1ca58440b158a0a35cf90773013caddf788a" },
"mini.nvim": { "branch": "main", "commit": "dc0ccf1b0499d649a6177d2a406babcfe73b97de" },
"nabla.nvim": { "branch": "master", "commit": "ddbfc6e244e79db9280c535ee85c81388c5d1b46" },
"navigator.lua": { "branch": "master", "commit": "66d84151e94052f710b1dfb0d1fce2faaca6dced" },
@ -63,7 +67,6 @@
"vim-pandoc": { "branch": "master", "commit": "9f406d964ca70d959b7867f1b5cee3d4884d4d3c" },
"vim-pandoc-syntax": { "branch": "master", "commit": "4268535e1d33117a680a91160d845cd3833dfe28" },
"vim-spellsync": { "branch": "master", "commit": "27e103f2d283a1f6e24cc99dbdcd624713aff277" },
"vim-vsnip": { "branch": "master", "commit": "8dde8c0ef10bb1afdbb301e2bd7eb1c153dd558e" },
"which-key.nvim": { "branch": "main", "commit": "684e96c5e8477f1ee9b3f2e9a12d802fd12c5531" },
"zen-mode.nvim": { "branch": "main", "commit": "3c92f503823088862ca2a7809d1c7edc90fb92fa" },
"zettelkasten.nvim": { "branch": "main", "commit": "0e77624689b470410f5355b613d45219c9350264" }

View file

@ -1,95 +1,40 @@
local cmp = require 'cmp'
local lspkind = require 'lspkind'
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,
col)
:match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true),
mode, true)
end
vim.o.completeopt = "menu,menuone,noselect"
-- completion items
require('cmp').register_source('vCard', require('completion_vcard').setup_cmp(
'~/documents/contacts/myconts'))
vim.g.vsnip_snippet_dir = (vim.env.XDG_DATA_HOME or "~/.local/share") ..
"/nvim/snippets"
cmp.setup({
snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end },
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close()
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = false }),
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" })
local lsp = require("lsp-zero")
lsp.preset("recommended")
lsp.on_attach(function(client, bufnr)
require("lsp-format").on_attach(client, bufnr)
end)
lsp.nvim_workspace()
lsp.setup_nvim_cmp({
sources = {
{ name = 'path' }, { name = 'nvim_lsp', keyword_length = 2 },
{ name = 'buffer', keyword_length = 3 },
{ name = 'luasnip', keyword_length = 2 }, { name = 'tmux' },
{ name = 'otter' }, { name = 'latex_symbols' }, { name = 'vCard' },
{ name = 'nvim_lua' }, { name = 'buffer' }, { name = 'spell' }
},
formatting = {
format = lspkind.cmp_format({
with_text = false,
menu = ({
buffer = "B",
nvim_lua = "NLua",
tmux = "τ",
vCard = "VCARD"
})
})
},
sources = cmp.config.sources({
{ name = 'path' }, { name = 'nvim_lsp' }, { name = 'treesitter' },
{ name = 'tmux' }, { name = 'vsnip' }, { name = 'otter' },
{ name = 'latex_symbols' }, { name = 'vCard' }, { name = 'nvim_lua' }
}, { { name = 'buffer' }, { name = 'spell' } })
documentation = {
max_height = 50,
max_width = 90,
border = 'rounded',
col_offset = 0,
side_padding = 1,
winhighlight = 'Normal:Normal,FloatBorder:Normal,CursorLine:Visual,Search:None',
zindex = 1001
}
})
lsp.setup()
vim.diagnostic.config { virtual_text = true }
if vim.o.ft == 'clap_input' and vim.o.ft == 'guihua' and vim.o.ft ==
'guihua_rust' then require 'cmp'.setup.buffer { completion = { enable = false } } end
-- set up pandoc bibtex source generation
require 'cmp_pandoc'.setup()
-- Use buffer source for `/` search
local cmp = require 'cmp'
-- `/` cmdline setup.
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ { name = 'buffer' } })
sources = { { name = 'buffer' } }
})
-- Use cmdline & path source for ':' in vim
-- `:` cmdline setup.
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } })
sources = cmp.config.sources({ { name = 'path' } }, {
{ name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } }
})
})
require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol
.make_client_capabilities())

View file

@ -1,28 +1,28 @@
local writing_ft = {"quarto", "pandoc", "markdown", "text", "tex"}
local writing_ft = { "quarto", "pandoc", "markdown", "text", "tex" }
return {
-- vim plugs
-- essential
{'numToStr/Navigator.nvim', config = true}, -- allow seamless navigation between vim buffers and tmux/wezterm splits
{'jeffkreeftmeijer/vim-numbertoggle', event = "BufEnter"}, -- toggles numbers to absolute for all buffers but the current which is relative
{'ojroques/vim-oscyank', event = "VeryLazy"}, -- yank from *anywhere* (even ssh session) to clipboard, using :OSCYank
{'ggandor/lightspeed.nvim', event = "VeryLazy"}, -- jump between letters with improved fFtT quicksearch, mimics sneak
{ 'numToStr/Navigator.nvim', config = true }, -- allow seamless navigation between vim buffers and tmux/wezterm splits
{ 'jeffkreeftmeijer/vim-numbertoggle', event = "BufEnter" }, -- toggles numbers to absolute for all buffers but the current which is relative
{ 'ojroques/vim-oscyank', event = "VeryLazy" }, -- yank from *anywhere* (even ssh session) to clipboard, using :OSCYank
{ 'ggandor/lightspeed.nvim', event = "VeryLazy" }, -- jump between letters with improved fFtT quicksearch, mimics sneak
-- files
{'vifm/vifm.vim'}, -- integrate file manager
{ 'vifm/vifm.vim' }, -- integrate file manager
{
'lewis6991/gitsigns.nvim', -- show vcs changes on left-hand gutter
config = true,
event = "BufRead"
}, {
'norcalli/nvim-colorizer.lua', -- color hex, named colors in the correct preview scheme
config = true,
event = "VeryLazy"
}, {
'mhartington/formatter.nvim', -- auto formatting on save
config = function() require('plug._format') end,
event = "VeryLazy"
}, -- editing
{'kylechui/nvim-surround', version = '*', config = true, event = "VeryLazy"}, -- surround things with other things using ys/cs/ds
'norcalli/nvim-colorizer.lua', -- color hex, named colors in the correct preview scheme
config = true,
event = "VeryLazy"
}, {
'mhartington/formatter.nvim', -- auto formatting on save
config = function() require('plug._format') end,
event = "VeryLazy"
}, -- editing
{ 'kylechui/nvim-surround', version = '*', config = true, event = "VeryLazy" }, -- surround things with other things using ys/cs/ds
{
'monaqa/dial.nvim', -- extend the ^a / ^x possibilities to dates, hex, alphabets, markdown headers
config = function()
@ -39,61 +39,61 @@ return {
augend.constant.alias.bool, augend.semver.alias.semver,
augend.constant.alias.Alpha, augend.constant.alias.alpha,
augend.hexcolor.new { case = "lower" }, augend.constant.new {
elements = { "and", "or" },
word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc.
cyclic = true -- "or" is incremented into "and".
},
elements = { "and", "or" },
word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc.
cyclic = true -- "or" is incremented into "and".
},
augend.constant
.new {
elements = { "&&", "||" },
word = false,
cyclic = true
}
.new {
elements = { "&&", "||" },
word = false,
cyclic = true
}
}
}
end,
event = "VeryLazy"
}, {
'tommcdo/vim-exchange', -- adds exchange operator with cx. common use: cxiw . on 2 words to switch
event = "VeryLazy"
}, {
'junegunn/vim-easy-align', -- Align tables and other alignable things
event = "VeryLazy"
}, -- colorschemes
{'norcalli/nvim-base16.lua'}, --
'tommcdo/vim-exchange', -- adds exchange operator with cx. common use: cxiw . on 2 words to switch
event = "VeryLazy"
}, {
'junegunn/vim-easy-align', -- Align tables and other alignable things
event = "VeryLazy"
}, -- colorschemes
{ 'norcalli/nvim-base16.lua' }, --
-- statusline
{
'nvim-lualine/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true},
requires = { 'kyazdani42/nvim-web-devicons', opt = true },
config = function() require('plug._lualine') end
}, -- writing
{'vim-pandoc/vim-pandoc-syntax', ft = writing_ft},
{'vim-pandoc/vim-pandoc', ft = writing_ft},
{'vim-pandoc/vim-criticmarkup', ft = writing_ft}, {
'quarto-dev/quarto-nvim',
dependencies = {'jmbuhr/otter.nvim', 'neovim/nvim-lspconfig'},
config = function()
require'quarto'.setup {
lspFeatures = {
enabled = true,
languages = {'r', 'python', 'julia'},
diagnostics = {enabled = true, triggers = {"BufWrite"}},
completion = {enabled = true}
}
{ 'vim-pandoc/vim-pandoc-syntax', ft = writing_ft },
{ 'vim-pandoc/vim-pandoc', ft = writing_ft },
{ 'vim-pandoc/vim-criticmarkup', ft = writing_ft }, {
'quarto-dev/quarto-nvim',
dependencies = { 'jmbuhr/otter.nvim', 'neovim/nvim-lspconfig' },
config = function()
require 'quarto'.setup {
lspFeatures = {
enabled = true,
languages = { 'r', 'python', 'julia' },
diagnostics = { enabled = true, triggers = { "BufWrite" } },
completion = { enabled = true }
}
end,
ft = writing_ft
}, {'micarmst/vim-spellsync', event = "VeryLazy"}, -- personal dict improvements for git sync
{'folke/zen-mode.nvim', config = true, event = "VeryLazy"}, -- provide distraction free writing
{'folke/twilight.nvim', event = "VeryLazy"}, -- provide even distraction free-er writing (lowlight paragraphs)
{'marty-oehme/zettelkasten.nvim', ft = writing_ft, event = "VeryLazy"}, -- simple static markdown linking
}
end,
ft = writing_ft
}, { 'micarmst/vim-spellsync', event = "VeryLazy" }, -- personal dict improvements for git sync
{ 'folke/zen-mode.nvim', config = true, event = "VeryLazy" }, -- provide distraction free writing
{ 'folke/twilight.nvim', event = "VeryLazy" }, -- provide even distraction free-er writing (lowlight paragraphs)
{ 'marty-oehme/zettelkasten.nvim', ft = writing_ft, event = "VeryLazy" }, -- simple static markdown linking
{
"iamcco/markdown-preview.nvim", -- generate an auto-updating html preview for md files
build = function() vim.fn["mkdp#util#install"]() end,
ft = writing_ft
}, -- languages
{'euclidianAce/BetterLua.vim', ft = 'lua'}, -- better syntax highlighting for lua
{'aliou/bats.vim', ft = {"bash", "sh", "zsh", "bats"}}, -- enable syntax for bats shell-code testing library
{ 'euclidianAce/BetterLua.vim', ft = 'lua' }, -- better syntax highlighting for lua
{ 'aliou/bats.vim', ft = { "bash", "sh", "zsh", "bats" } }, -- enable syntax for bats shell-code testing library
-- REPL work
{
@ -108,41 +108,37 @@ return {
'echasnovski/mini.nvim',
version = '*',
config = function() require('plug._mini') end
},
{
"akinsho/nvim-toggleterm.lua", -- simpler, programmable and multiple terminal toggling for nvim
config = function() require('plug._toggleterm') end,
event = "BufWinEnter"
},
}, {
"akinsho/nvim-toggleterm.lua", -- simpler, programmable and multiple terminal toggling for nvim
config = function() require('plug._toggleterm') end,
event = "BufWinEnter"
},
{
"folke/which-key.nvim",
config = function() require("which-key").setup {} end
}, {
"nvim-neorg/neorg",
config = function() require("plug._neorg") end,
dependencies = {"nvim-lua/plenary.nvim"},
version = "*",
ft = "norg"
}, -- extensive organization plugin mimicking orgmode
"nvim-neorg/neorg",
config = function() require("plug._neorg") end,
dependencies = { "nvim-lua/plenary.nvim" },
version = "*",
ft = "norg"
}, -- extensive organization plugin mimicking orgmode
-- fuzzy matching
{"nvim-telescope/telescope-fzf-native.nvim", build = 'make'}, {
"nvim-telescope/telescope.nvim",
dependencies = {"nvim-lua/popup.nvim", "nvim-lua/plenary.nvim"},
config = function() require('plug._telescope') end
}, -- snippeting
{"hrsh7th/vim-vsnip", event = "InsertEnter"}, -- snippet engine
{"rafamadriz/friendly-snippets", event = "InsertEnter"}, -- many snippets
-- treesitter
{ "nvim-telescope/telescope-fzf-native.nvim", build = 'make' }, {
"nvim-telescope/telescope.nvim",
dependencies = { "nvim-lua/popup.nvim", "nvim-lua/plenary.nvim" },
config = function() require('plug._telescope') end
}, -- treesitter
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
config = function() require('plug._treesitter') end
}, {'nvim-treesitter/playground', cmd = "TSPlaygroundToggle"}, -- interactively view and query the treesitter tree
{'romgrk/nvim-treesitter-context', event = "BufReadPre", config = true}, -- show current cursor context at top of buffer
}, { 'nvim-treesitter/playground', cmd = "TSPlaygroundToggle" }, -- interactively view and query the treesitter tree
{ 'romgrk/nvim-treesitter-context', event = "BufReadPre", config = true }, -- show current cursor context at top of buffer
{
'RRethy/nvim-treesitter-textsubjects', -- allows using . and ; to target treesitter branches
config = function()
require'nvim-treesitter.configs'.setup {
require 'nvim-treesitter.configs'.setup {
textsubjects = {
enable = true,
keymaps = {
@ -153,49 +149,47 @@ return {
}
end,
event = "BufReadPre"
}, {'p00f/nvim-ts-rainbow', event = "BufReadPre"}, -- rainbow brackets using treesitter
{'JoosepAlviste/nvim-ts-context-commentstring', event = "BufReadPre"}, -- improves commenting plugin above by using ts
}, { 'p00f/nvim-ts-rainbow', event = "BufReadPre" }, -- rainbow brackets using treesitter
{ 'JoosepAlviste/nvim-ts-context-commentstring', event = "BufReadPre" }, -- improves commenting plugin above by using ts
{
'lewis6991/spellsitter.nvim', -- uses treesitter to highlight spelling errors
config = function() require('spellsitter').setup() end,
event = "BufReadPre"
}, -- lsp
{'neovim/nvim-lspconfig', event = "VeryLazy"}, -- some common language server configurations
{
'simrat39/symbols-outline.nvim',
config = function() require('symbols-outline').setup() end,
event = "VeryLazy"
}, -- vista-like outline view for code
{'ray-x/lsp_signature.nvim', event = "VeryLazy"},
{'ray-x/guihua.lua', build = 'cd lua/fzy && make', event = "VeryLazy"}, {
'ray-x/navigator.lua',
config = function() require('plug._lsp') end,
event = "VeryLazy"
}, -- and completion
{
'hrsh7th/nvim-cmp', -- simple completion engine built specifically for nvim and lsp
"VonHeikemen/lsp-zero.nvim",
dependencies = {
'onsails/lspkind-nvim', 'andersevenrud/cmp-tmux', -- completion source from adjacent tmux panes
'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-vsnip', 'hrsh7th/cmp-nvim-lua',
'kdheepak/cmp-latex-symbols', 'ray-x/cmp-treesitter',
'f3fora/cmp-spell', 'cbarrete/completion-vcard'
"neovim/nvim-lspconfig", "williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim", "hrsh7th/nvim-cmp",
"hrsh7th/cmp-buffer", "hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua", "L3MON4D3/LuaSnip",
"rafamadriz/friendly-snippets", "andersevenrud/cmp-tmux",
"hrsh7th/cmp-nvim-lsp", "kdheepak/cmp-latex-symbols",
"ray-x/cmp-treesitter", "f3fora/cmp-spell", "hrsh7th/cmp-cmdline",
"cbarrete/completion-vcard", {
'aspeddro/cmp-pandoc.nvim',
dependencies = { 'nvim-lua/plenary.nvim', 'jbyuki/nabla.nvim' },
event = "InsertEnter"
}, { "lukas-reineke/lsp-format.nvim", config = true }
},
event = "VeryLazy",
config = function() require('plug._cmp') end
}, {
'aspeddro/cmp-pandoc.nvim',
dependencies = {'nvim-lua/plenary.nvim', 'jbyuki/nabla.nvim'},
event = "VeryLazy"
}, {
}, { 'simrat39/symbols-outline.nvim', config = true, event = "VeryLazy" }, -- vista-like outline view for code
{ 'ray-x/lsp_signature.nvim', event = "VeryLazy" },
{ 'ray-x/guihua.lua', build = 'cd lua/fzy && make', event = "VeryLazy" }, {
'ray-x/navigator.lua',
config = function() require('plug._lsp') end,
event = "VeryLazy"
}, -- and completion
{
"jghauser/papis.nvim",
after = {"telescope.nvim", "nvim-cmp"},
after = { "telescope.nvim", "nvim-cmp" },
dependencies = {
"kkharji/sqlite.lua", "nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim", "nvim-treesitter/nvim-treesitter"
},
event = "VeryLazy",
rocks = {"lyaml"},
config = function() require("papis").setup({}) end
ft = writing_ft,
rocks = { "lyaml" },
config = true
}
}