From 4c9c54abf500f8500ad60891a18450bc33179256 Mon Sep 17 00:00:00 2001 From: Jonathan Bourdon Date: Wed, 6 May 2026 21:20:17 -0400 Subject: [PATCH] feat(nvim): accept completion suggestion with TAB --- nvim/.config/nvim/init.lua | 6 +- nvim/.config/nvim/lua/custom/dotnet.lua | 75 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 nvim/.config/nvim/lua/custom/dotnet.lua diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 67352ea..bffa1d0 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -218,6 +218,8 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +require('custom.dotnet').setup() + -- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes -- vim.keymap.set("n", "", "H", { desc = "Move window to the left" }) -- vim.keymap.set("n", "", "L", { desc = "Move window to the right" }) @@ -865,7 +867,7 @@ require('lazy').setup({ -- to accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. - -- 'super-tab' for tab to accept + -- 'super-tab' for tab to accept, with Up/Down selecting suggestions. -- 'enter' for enter to accept -- 'none' for no mappings -- @@ -882,7 +884,7 @@ require('lazy').setup({ -- : Toggle signature help -- -- See :h blink-cmp-config-keymap for defining your own keymap - preset = 'default', + preset = 'super-tab', -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps diff --git a/nvim/.config/nvim/lua/custom/dotnet.lua b/nvim/.config/nvim/lua/custom/dotnet.lua new file mode 100644 index 0000000..d446994 --- /dev/null +++ b/nvim/.config/nvim/lua/custom/dotnet.lua @@ -0,0 +1,75 @@ +local M = {} + +local dotnet_errorformat = { + [[%f(%l\,%c): %trror %m]], + [[%f(%l\,%c): %tarning %m]], + [[%f(%l): %trror %m]], + [[%f(%l): %tarning %m]], + [[%f : %trror %m]], + [[%f : %tarning %m]], + [[%-G%.%#]], +} + +function M.configure_buffer() + vim.opt_local.makeprg = 'dotnet build' + vim.opt_local.errorformat = dotnet_errorformat +end + +function M.build(args) + M.configure_buffer() + + local command = 'silent make!' + if args and args ~= '' then + command = command .. ' ' .. args + end + + vim.cmd(command) + vim.cmd.cwindow() + + local count = #vim.fn.getqflist() + if count == 0 then + vim.notify('dotnet build finished without quickfix entries', vim.log.levels.INFO) + else + vim.notify(('dotnet build populated %d quickfix item%s'):format(count, count == 1 and '' or 's'), vim.log.levels.INFO) + end +end + +function M.setup() + local group = vim.api.nvim_create_augroup('custom-dotnet', { clear = true }) + + vim.api.nvim_create_autocmd('FileType', { + group = group, + pattern = { 'cs', 'fsharp', 'vb' }, + callback = M.configure_buffer, + }) + + vim.api.nvim_create_autocmd({ 'BufReadPost', 'BufNewFile' }, { + group = group, + pattern = { '*.csproj', '*.fsproj', '*.vbproj', '*.sln', '*.slnx', '*.props', '*.targets' }, + callback = M.configure_buffer, + }) + + vim.api.nvim_create_user_command('DotnetBuild', function(opts) + M.build(opts.args) + end, { + nargs = '*', + complete = 'file', + desc = 'Build the current .NET solution/project into the quickfix list', + }) + + vim.keymap.set('n', 'mb', 'DotnetBuild', { desc = '[M]ake dotnet [B]uild' }) + vim.keymap.set('n', 'mq', 'copen', { desc = '[M]ake: Open [Q]uickfix' }) + vim.keymap.set('n', 'mc', 'cclose', { desc = '[M]ake: [C]lose quickfix' }) + vim.keymap.set('n', ']q', 'cnextzz', { desc = 'Next quickfix item' }) + vim.keymap.set('n', '[q', 'cpreviouszz', { desc = 'Previous quickfix item' }) + + vim.api.nvim_create_autocmd('FileType', { + group = group, + pattern = 'qf', + callback = function(event) + vim.keymap.set('n', 'q', 'cclose', { buffer = event.buf, desc = 'Close quickfix' }) + end, + }) +end + +return M