Compare commits

..

6 commits

Author SHA1 Message Date
36d411dafa
nvim: Format files 2023-03-22 10:35:21 +01:00
22cfa037df
nvim: Add fidget.nvim
Added fidget plugin which shows the current loading status of LSPs. Only
works for a few LSP (so far), including lua and python. Should
automatically pick up new implementations on update. Will display a
small loading notification in the lower right corner, useful to display
status for those situations where LSP loading takes a long time (e.g.
rust compilation requirements or a large python environment).

FIXME Does not work for each python environment startup yet, and I am
not sure why - sometimes just does not display its loading startup.
2023-03-22 10:32:20 +01:00
643d282bac
nvim: Improve cmdline completion
When completing in command line I want the completion canditates to be
displayed, but *not* selected on confirmation. By doing so, it makes it
almost impossible to quickly quit with ':q' or write with ':w' for
example, as those always try to expand themselves automatically into
completion items.

This commit changes the default behavior for command mode to show
completions but not auto accept any on confirmation, instead simply
invoking whatever is currently on the command line (as if we had no
completion plugin running).
2023-03-22 10:31:37 +01:00
ce9f101024
nvim: Unify lsp mappings into local +l prefix
Whereas previously we had lsp-related mappings both on <localleader>l...
and g... mappings, they are now all unified under the <localleader>l
prefix group. Some mnemonics unfortunately had to give way to a weaker
version of themselves (definition becomes de[f]inition, implementation
becomes i[m]plementation) but overall I believe this to be much more
cohesive for my future lsp usage. With which-key enabled and everything
under the +l group we should be able to easily adapt to the new
mappings.

Additionally, some mappings will invoke the telescope version of their
lsp command if telescope is indeed installed, otherwise fall back to the
native neovim lsp implementation.
2023-03-22 10:28:13 +01:00
d1b0dfe112
nvim: Improve diagnostics gutter rendering 2023-03-22 10:21:52 +01:00
6b28e6417b
nvim: Prepare lsp-zero switch to v2 branch
Switched the configuration of lsp-zero to its less integrated v2
version. Switched back to manually configuring most of nvim-cmp.

Addded some manual formatting to cmp which displays completion kind as
icons not as text.
Manually add luasnip integration.
2023-03-22 08:30:04 +01:00
3 changed files with 233 additions and 80 deletions

View file

@ -4,13 +4,17 @@
"LuaSnip": { "branch": "master", "commit": "500981ff6cefc7343e3959ef0f939bd0bfd49ba9" },
"Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" },
"bats.vim": { "branch": "master", "commit": "6a5d2ef22b0ede503d867770afd02ebb1f97b709" },
"cmp-beancount": { "branch": "main", "commit": "da154ea94d598e6649d6ad01efa0a8611eff460d" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-calc": { "branch": "main", "commit": "50792f34a628ea6eb31d2c90e8df174671e4e7a0" },
"cmp-cmdline": { "branch": "main", "commit": "8fcc934a52af96120fe26358985c10c035984b53" },
"cmp-digraphs": { "branch": "master", "commit": "5efc1f0078d7c5f3ea1c8e3aad04da3fd6e081a9" },
"cmp-latex-symbols": { "branch": "main", "commit": "165fb66afdbd016eaa1570e41672c4c557b57124" },
"cmp-nvim-lsp": { "branch": "main", "commit": "0e6b2ed705ddcff9738ec4ea838141654f12eeef" },
"cmp-nvim-lua": { "branch": "main", "commit": "f3491638d123cfd2c8048aefaf66d246ff250ca6" },
"cmp-pandoc-references": { "branch": "master", "commit": "2c808dff631a783ddd2c554c4c6033907589baf6" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp-rg": { "branch": "master", "commit": "1cad8eb315643d0df13c37401c03d7986f891011" },
"cmp-spell": { "branch": "master", "commit": "60584cb75e5e8bba5a0c9e4c3ab0791e0698bffa" },
"cmp-tmux": { "branch": "main", "commit": "984772716f66d8ee88535a6bf3f94c4b4e1301f5" },
"cmp-treesitter": { "branch": "master", "commit": "b40178b780d547bcf131c684bc5fd41af17d05f2" },
@ -19,6 +23,7 @@
"dial.nvim": { "branch": "master", "commit": "54b503f906bc9e5ab85288414840a1b86d40769f" },
"dressing.nvim": { "branch": "master", "commit": "5f44f829481640be0f96759c965ae22a3bcaf7ce" },
"easyread.nvim": { "branch": "main", "commit": "73df5f4dc8fd38bef079b890b2a34412844c00b1" },
"fidget.nvim": { "branch": "main", "commit": "688b4fec4517650e29c3e63cfbb6e498b3112ba1" },
"formatter.nvim": { "branch": "master", "commit": "ed949c13e1a942db29ababa35e8c7864ced90eb6" },
"friendly-snippets": { "branch": "main", "commit": "25ddcd96540a2ce41d714bd7fea2e7f75fea8ead" },
"fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" },
@ -27,13 +32,13 @@
"lazy.nvim": { "branch": "main", "commit": "887eb75591520a01548134c4623617b639289d0b" },
"lightspeed.nvim": { "branch": "main", "commit": "299eefa6a9e2d881f1194587c573dad619fdb96f" },
"lsp-format.nvim": { "branch": "master", "commit": "ca0df5c8544e51517209ea7b86ecc522c98d4f0a" },
"lsp-zero.nvim": { "branch": "main", "commit": "5b68fbdc91102de41fb53da79f52752370d71a7e" },
"lsp-zero.nvim": { "branch": "v2.x", "commit": "7cb74b241c9d99b5d44f2111696cd9306848b25b" },
"lsp_signature.nvim": { "branch": "master", "commit": "4665921ff8e30601c7c1328625b3abc1427a6143" },
"lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" },
"magma-nvim-goose": { "branch": "main", "commit": "5d916c39c1852e09fcd39eab174b8e5bbdb25f8f" },
"markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "a31e011135a79d63c71254c250c9158e1056a1cb" },
"mason.nvim": { "branch": "main", "commit": "3ee3174e30e33c9d58fa07b0a73a6e180474b59c" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "2b811031febe5f743e07305738181ff367e1e452" },
"mason.nvim": { "branch": "main", "commit": "a192887fd0c29275cf2acb4a83bcbdf63399f8df" },
"mini.nvim": { "branch": "main", "commit": "427751024313e2270ca723eb16af7b218c83a7fc" },
"neural": { "branch": "main", "commit": "155618730b87a67655bdde373ee27bfce8b07ac9" },
"nui.nvim": { "branch": "main", "commit": "0dc148c6ec06577fcf06cbab3b7dac96d48ba6be" },
@ -45,7 +50,7 @@
"nvim-surround": { "branch": "main", "commit": "b98862527c4727c171f8626e04d8ae88ef6cb736" },
"nvim-toggleterm.lua": { "branch": "main", "commit": "a5638b2206c3930a16a24e5c184dddd572f8cd34" },
"nvim-treesitter": { "branch": "master", "commit": "c38646edf2bdfac157ca619697ecad9ea87fd469" },
"nvim-treesitter-context": { "branch": "master", "commit": "895ec44f5c89bc67ba5440aef3d1f2efa3d59a41" },
"nvim-treesitter-context": { "branch": "master", "commit": "88d1627285f7477883516ef60521601862dae7a1" },
"nvim-treesitter-textsubjects": { "branch": "master", "commit": "b913508f503527ff540f7fe2dcf1bf1d1f259887" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "729d83ecb990dc2b30272833c213cc6d49ed5214" },
"nvim-ts-rainbow2": { "branch": "master", "commit": "cee4601ff8aac73dee4afa1074814343bb5a0b80" },

View file

@ -1,14 +1,20 @@
local lsp = require("lsp-zero")
vim.diagnostic.config { virtual_text = true }
vim.fn.sign_define("DiagnosticSignError", { text = "", texthl = "DiagnosticSignError" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn" })
vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" })
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
lsp.preset({
name = "recommended",
set_lsp_keymaps = false,
suggest_lsp_servers = true
lsp.ensure_installed({
'arduino_language_server', 'bashls', 'beancount', 'clangd', 'dockerls',
'docker_compose_language_service', 'lua_ls', 'pyright', 'ruff_lsp', 'taplo',
'yamlls'
})
lsp.preset({ name = "recommended", set_lsp_keymaps = false })
lsp.on_attach(function(client, bufnr)
require("lsp-format").on_attach(client, bufnr)
local map = vim.keymap.set
map('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>',
{ buffer = bufnr, desc = 'Previous diagnostic' })
@ -31,8 +37,25 @@ lsp.on_attach(function(client, bufnr)
{ buffer = bufnr, desc = 'Codeactions' })
map('n', '<localleader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>',
{ buffer = bufnr, desc = 'Rename element' })
if vim.fn.exists(':Telescope') then
map('n', '<localleader>lr', '<cmd>Telescope lsp_references()<cr>',
{ buffer = bufnr, desc = 'References' })
map('n', '<localleader>lf', '<cmd>Telescope lsp_definitions<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', '<localleader>lt', '<cmd>Telescope lsp_type_definitions<cr>',
{ buffer = bufnr, desc = 'Type definition' })
map('n', '<localleader>lm', '<cmd>Telescope lsp_implementations<cr>',
{ buffer = bufnr, desc = 'Implementation' })
else
map('n', '<localleader>lr', '<cmd>lua vim.lsp.buf.references()<cr>',
{ buffer = bufnr, desc = 'References' })
map('n', '<localleader>lf', '<cmd>lua vim.lsp.buf.definition()<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', '<localleader>lt', '<cmd>lua vim.lsp.buf.type_definition()<cr>',
{ buffer = bufnr, desc = 'Type definition' })
map('n', '<localleader>lm', '<cmd>lua vim.lsp.buf.implementation()<cr>',
{ buffer = bufnr, desc = 'Implementation' })
end
if client.server_capabilities.document_formatting then
map('n', '<localleader>lf', "<cmd>lua vim.lsp.buf.formatting()<CR>",
{ buffer = bufnr, desc = 'Format document' })
@ -40,16 +63,10 @@ lsp.on_attach(function(client, bufnr)
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>',
{ buffer = bufnr, desc = 'Hover definition' })
map('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>',
{ buffer = bufnr, desc = 'Definition' })
map('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>',
map('n', '<localleader>lc', '<cmd>lua vim.lsp.buf.declaration()<cr>',
{ buffer = bufnr, desc = 'Declaration' })
map('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>',
map('n', '<localleader>ls', '<cmd>lua vim.lsp.buf.signature_help()<cr>',
{ buffer = bufnr, desc = 'Signature help' })
map('n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<cr>',
{ buffer = bufnr, desc = 'Implementation' })
map('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<cr>',
{ buffer = bufnr, desc = 'Type definition' })
end)
lsp.nvim_workspace()
-- ensure python virtualenv is determined automatically on lsp start
@ -62,29 +79,139 @@ lsp.configure("pyright", {
end
})
-- set up arduino with the help of arduino.nvim plugin
lsp.configure("arduino_language_server",
{ on_new_config = require('arduino').on_new_config })
lsp.setup_nvim_cmp({
sources = {
{ name = 'path' }, { name = 'nvim_lsp', keyword_length = 2 },
{ name = 'pandoc_references' }, { 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' }
},
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
}
require('lspconfig').arduino_language_server.setup({
on_new_config = require('arduino').on_new_config
})
require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls())
lsp.setup()
local luasnip = require("luasnip")
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 kind_icons = {
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = ""
}
local cmp = require 'cmp'
cmp.setup({
window = {
documentation = cmp.config.window.bordered()
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'otter' },
{ name = 'luasnip', keyword_length = 2 },
{ name = 'pandoc_references' },
{ name = 'nvim_lua' },
{
name = 'beancount',
option = {
account = vim.env["HOME"] .. '/documents/records/budget/main.beancount' -- TODO implement dynamically
}
},
{ name = 'calc' },
{ name = 'path' },
{ name = 'buffer', keyword_length = 3 },
{ name = 'digraphs' },
{ name = 'latex_symbols' },
{ name = 'spell', keyword_length = 3 },
{ name = 'tmux' },
{ name = 'rg', keyword_length = 5 },
{ name = 'vCard' },
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
["<CR>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), -- disable selection in cmd mode
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
-- Kind icons, removing kind text leaving only icon
-- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind)
vim_item.kind = string.format('%s', kind_icons[vim_item.kind])
-- Source
vim_item.menu = ({
buffer = "[Buf]",
calc = "[Cal]",
digraphs = "[Dig]",
latex_symbols = "[LaTeX]",
luasnip = "[Snip]",
nvim_lsp = "[Lsp]",
nvim_lua = "[Lua]",
pandoc_references = "[Bib]",
spell = "[Spl]",
vCard = "[vCrd]",
})[entry.source.name]
return vim_item
end
},
})
-- `/` cmdline setup.
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),

View file

@ -84,7 +84,8 @@ return {
'quarto-dev/quarto-nvim',
dependencies = {
'jmbuhr/otter.nvim', 'neovim/nvim-lspconfig',
'vim-pandoc/vim-pandoc-syntax'
'vim-pandoc/vim-pandoc-syntax', 'hrsh7th/nvim-cmp',
'nvim-treesitter/nvim-treesitter'
},
config = function()
require 'quarto'.setup {
@ -112,7 +113,12 @@ return {
}, { '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)
{ 'JellyApple102/easyread.nvim', config = true, ft = writing_ft, cmd = 'EasyreadToggle' }, -- enable 'speed-reading' mode (bionic reading)
{
'JellyApple102/easyread.nvim',
config = true,
ft = writing_ft,
cmd = 'EasyreadToggle'
}, -- enable 'speed-reading' mode (bionic reading)
{ '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
@ -194,22 +200,37 @@ return {
"VonHeikemen/lsp-zero.nvim",
dependencies = {
{ "neovim/nvim-lspconfig", branch = "master" },
"williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
{
"hrsh7th/nvim-cmp",
branch = "main",
dependencies = {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua", "andersevenrud/cmp-tmux",
"hrsh7th/cmp-nvim-lsp", "kdheepak/cmp-latex-symbols",
"ray-x/cmp-treesitter", "f3fora/cmp-spell",
"hrsh7th/cmp-cmdline", "cbarrete/completion-vcard",
"jc-doyle/cmp-pandoc-references"
"andersevenrud/cmp-tmux",
"cbarrete/completion-vcard",
"f3fora/cmp-spell",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-calc",
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-nvim-lua",
"dmitmel/cmp-digraphs",
"jc-doyle/cmp-pandoc-references",
"kdheepak/cmp-latex-symbols",
"lukas-reineke/cmp-rg",
"crispgm/cmp-beancount",
"ray-x/cmp-treesitter",
"saadparwaiz1/cmp_luasnip",
}
}, "L3MON4D3/LuaSnip", "rafamadriz/friendly-snippets",
{ "lukas-reineke/lsp-format.nvim", config = true }
},
config = function() require('plug._lsp') end
"L3MON4D3/LuaSnip",
"rafamadriz/friendly-snippets",
{ "lukas-reineke/lsp-format.nvim", config = true },
{ "j-hui/fidget.nvim", config = true } -- loading animations for some LSP
},
config = function() require('plug._lsp') end,
branch = "v2.x"
}, { 'simrat39/symbols-outline.nvim', config = true, event = "VeryLazy" }, -- vista-like outline view for code
{ 'ray-x/lsp_signature.nvim', config = true }, -- UI improvements
{ 'stevearc/dressing.nvim', config = true }, {