From 1245a40fbc0fb3298f5faacba8d12bbdc9b51079 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 14:10:34 +0100 Subject: [PATCH 01/16] refactor(keymaps): improve organization and discoverability - Organize keymaps into logical groups with consistent prefixes: - s for Search (Telescope) - g for Git operations - b for Buffer operations - l for LSP operations - t for Trouble/diagnostics - D for Database operations - m for Memory (Sessions) - Improve keymap descriptions for better which-key display - Resolve conflicts between diagnostic and database keymaps - Add missing buffer and window operations - Update gitignore with common Neovim patterns --- .gitignore | 38 +++++- lua/core/keymaps.lua | 316 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 351 insertions(+), 3 deletions(-) create mode 100644 lua/core/keymaps.lua diff --git a/.gitignore b/.gitignore index 005b535b606..29d9a23fe4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,39 @@ +# Generated files tags -test.sh .luarc.json -nvim +lazy-lock.json + +# Session files +sessions/ + +# Compiled Lua sources +luac.out + +# Logs and databases +*.log +*.sqlite + +# Temporary files +*.swp +*.swo +*~ +.DS_Store +# Plugin directories that should be ignored spell/ -lazy-lock.json +.backup/ +.undo/ +.swap/ + +# Local development files +.env +.envrc +.direnv/ +test.sh +test.py + +# Compiled plugins +plugin/packer_compiled.lua + +# LSP data +.lsp/ diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 00000000000..71618af0165 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,316 @@ +-- Set as the leader key +-- See `:help mapleader` +-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Core Neovim keymaps (non-plugin) +local core_keymaps = { + -- Clear highlights on search when pressing in normal mode + { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, + + -- Exit terminal mode with a more discoverable shortcut + { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, + + -- Window navigation (Ctrl + hjkl) + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window left' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window right' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window down' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window up' } }, + + -- Window resizing (Ctrl + Arrow keys) + { mode = 'n', lhs = '', rhs = 'resize +2', opts = { desc = 'Window: Increase height' } }, + { mode = 'n', lhs = '', rhs = 'resize -2', opts = { desc = 'Window: Decrease height' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize -2', opts = { desc = 'Window: Decrease width' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize +2', opts = { desc = 'Window: Increase width' } }, + + -- Move lines up and down (Alt + jk) + { mode = 'n', lhs = '', rhs = ':m .+1==', opts = { desc = 'Move line down', silent = true } }, + { mode = 'n', lhs = '', rhs = ':m .-2==', opts = { desc = 'Move line up', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '>+1gv=gv", opts = { desc = 'Move selection down', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '<-2gv=gv", opts = { desc = 'Move selection up', silent = true } }, + + -- Quick save and quit + { mode = 'n', lhs = 'w', rhs = 'w', opts = { desc = 'Save file' } }, + { mode = 'n', lhs = 'W', rhs = 'wa', opts = { desc = 'Save all files' } }, + { mode = 'n', lhs = 'Q', rhs = 'qa', opts = { desc = 'Quit all' } }, +} + +-- LSP keymaps - these will be set up when LSP attaches to a buffer +local M = {} +function M.setup_lsp_keymaps(bufnr) + local keymaps = { + -- Go to definitions + { mode = 'n', lhs = 'gd', rhs = function() require('telescope.builtin').lsp_definitions() end, opts = { desc = 'LSP: Go to definition' } }, + { mode = 'n', lhs = 'gr', rhs = function() require('telescope.builtin').lsp_references() end, opts = { desc = 'LSP: Find references' } }, + { mode = 'n', lhs = 'gI', rhs = function() require('telescope.builtin').lsp_implementations() end, opts = { desc = 'LSP: Go to implementation' } }, + { mode = 'n', lhs = 'gy', rhs = function() require('telescope.builtin').lsp_type_definitions() end, opts = { desc = 'LSP: Go to type definition' } }, + + -- Symbol navigation + { mode = 'n', lhs = 'ls', rhs = function() require('telescope.builtin').lsp_document_symbols() end, opts = { desc = 'LSP: Document symbols' } }, + { mode = 'n', lhs = 'lS', rhs = function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, opts = { desc = 'LSP: Workspace symbols' } }, + + -- Code actions + { mode = 'n', lhs = 'lr', rhs = vim.lsp.buf.rename, opts = { desc = 'LSP: Rename symbol' } }, + { mode = 'n', lhs = 'la', rhs = vim.lsp.buf.code_action, opts = { desc = 'LSP: Code action' } }, + { mode = 'n', lhs = 'lf', rhs = function() vim.lsp.buf.format({ async = true }) end, opts = { desc = 'LSP: Format code' } }, + + -- Documentation + { mode = 'n', lhs = 'K', rhs = vim.lsp.buf.hover, opts = { desc = 'LSP: Show documentation' } }, + } + + -- First clear any existing LSP keymaps for this buffer + local lsp_maps = { 'gd', 'gr', 'gI', 'gy', 'K', + 'ls', 'lS', 'lr', 'la', 'lf' } + for _, lhs in ipairs(lsp_maps) do + pcall(vim.keymap.del, 'n', lhs, { buffer = bufnr }) + end + + -- Then set our keymaps with buffer local + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { + buffer = bufnr, + replace_keycodes = false, + nowait = true, + silent = true, + })) + end +end + +-- Telescope keymaps (all under s for Search) +M.telescope_keymaps = { + -- Help + { mode = 'n', lhs = 'sh', rhs = function() require('telescope.builtin').help_tags() end, opts = { desc = 'Search: Help' } }, + { mode = 'n', lhs = 'sk', rhs = function() require('telescope.builtin').keymaps() end, opts = { desc = 'Search: Keymaps' } }, + + -- Files + { mode = 'n', lhs = 'sf', rhs = function() require('telescope.builtin').find_files() end, opts = { desc = 'Search: Files' } }, + { mode = 'n', lhs = 'sr', rhs = function() require('telescope.builtin').oldfiles() end, opts = { desc = 'Search: Recent files' } }, + + -- Text + { mode = 'n', lhs = 'sg', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search: Text in workspace' } }, + { mode = 'n', lhs = 'sw', rhs = function() require('telescope.builtin').grep_string() end, opts = { desc = 'Search: Word under cursor' } }, + { mode = 'n', lhs = '/', rhs = function() + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, opts = { desc = 'Search: Text in buffer' } }, + { mode = 'n', lhs = 's/', rhs = function() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, opts = { desc = 'Search: Text in open files' } }, + + -- Workspace + { mode = 'n', lhs = 'sd', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Search: Diagnostics' } }, + { mode = 'n', lhs = 'sb', rhs = function() require('telescope.builtin').buffers() end, opts = { desc = 'Search: Buffers' } }, +} + +-- Diagnostic keymaps (navigation with [d and ]d, details with t for trouble) +M.diagnostic_keymaps = { + -- Navigation + { mode = 'n', lhs = '[d', rhs = vim.diagnostic.goto_prev, opts = { desc = 'Diagnostic: Previous' } }, + { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, + + -- Viewing diagnostics (using t for Trouble) + { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Trouble: Show details' } }, + { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Trouble: Show list' } }, +} + +-- Database keymaps (all under D for Database, to avoid conflicts with diagnostics) +M.dadbod_keymaps = { + { mode = 'n', lhs = 'Dt', rhs = 'DBUIToggle', opts = { desc = 'Database: Toggle UI' } }, + { mode = 'n', lhs = 'Df', rhs = 'DBUIFindBuffer', opts = { desc = 'Database: Find buffer' } }, + { mode = 'n', lhs = 'Dr', rhs = 'DBUIRenameBuffer', opts = { desc = 'Database: Rename buffer' } }, + { mode = 'n', lhs = 'Dl', rhs = 'DBUILastQueryInfo', opts = { desc = 'Database: Last query' } }, +} + +-- Session management keymaps (all under m for Memory) +M.session_keymaps = { + { mode = 'n', lhs = 'ms', rhs = function() _G.MiniSession.save() end, + opts = { desc = 'Memory: Save session' } }, + { mode = 'n', lhs = 'ml', rhs = function() _G.MiniSession.load() end, + opts = { desc = 'Memory: Load session' } }, + { mode = 'n', lhs = 'md', rhs = function() _G.MiniSession.delete() end, + opts = { desc = 'Memory: Delete session' } }, +} + +-- Setup function for dadbod keymaps +function M.setup_dadbod_keymaps() + for _, mapping in ipairs(M.dadbod_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +-- Setup function for session keymaps +function M.setup_session_keymaps() + -- Session keymaps will be overridden by mini.lua + local keymaps = M.session_keymaps or {} + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +-- Scratch buffer keymaps +M.scratch_keymaps = { + { mode = 'n', lhs = '.', rhs = function() require("snacks").scratch() end, + opts = { desc = 'Toggle scratch buffer' } }, + { mode = 'n', lhs = 'S', rhs = function() require("snacks").scratch.select() end, + opts = { desc = 'Select scratch buffer' } }, +} + +-- Setup function for git signs keymaps +function M.setup_gitsigns_keymaps() + for _, mapping in ipairs(M.gitsigns_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +-- Leap keymaps +M.leap_keymaps = { + -- 's' for bidirectional search (both forward and backward) + { mode = { 'n', 'x', 'o' }, lhs = 's', rhs = function() require('leap').leap {} end, + opts = { desc = 'Leap: Search bidirectional' } }, + + -- 'S' for searching in all windows + { mode = { 'n', 'x', 'o' }, lhs = 'S', rhs = function() + require('leap').leap { target_windows = vim.tbl_filter( + function (win) return vim.api.nvim_win_get_config(win).focusable end, + vim.api.nvim_tabpage_list_wins(0) + )} + end, opts = { desc = 'Leap: Search across windows' } }, +} + +-- Setup function for leap keymaps +function M.setup_leap_keymaps() + for _, mapping in ipairs(M.leap_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +-- Initialize keymaps +local function init_keymaps() + -- Create an autocmd group for our keymaps + local keymap_group = vim.api.nvim_create_augroup('custom_keymaps', { clear = true }) + + -- Function to set up snacks explorer keymaps + local function setup_explorer_keymaps() + -- First remove any existing mappings + for _, key in ipairs({ 'e', 'o' }) do + pcall(vim.keymap.del, 'n', key) + pcall(vim.keymap.del, 'n', key, { buffer = true }) + end + + -- Set our mappings with high priority + for _, mapping in ipairs(M.snacks_keymaps) do + if mapping.lhs == 'e' or mapping.lhs == 'o' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, { + desc = mapping.opts.desc .. ' (high priority)', + replace_keycodes = false, + nowait = true, + silent = true, + }) + end + end + end + + -- Set up autocmds to maintain our keymaps + vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter', 'FileType' }, { + group = keymap_group, + callback = setup_explorer_keymaps, + }) + + -- Also set up the keymaps immediately + setup_explorer_keymaps() + + -- Apply core keymaps + for _, mapping in ipairs(core_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Apply telescope keymaps + for _, mapping in ipairs(M.telescope_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Apply diagnostic keymaps + for _, mapping in ipairs(M.diagnostic_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Apply buffer keymaps + for _, mapping in ipairs(M.buffer_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Apply dadbod keymaps + M.setup_dadbod_keymaps() + + -- Apply session keymaps + M.setup_session_keymaps() + + -- Apply scratch keymaps + for _, mapping in ipairs(M.scratch_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Apply git signs keymaps + M.setup_gitsigns_keymaps() + + -- Apply leap keymaps + M.setup_leap_keymaps() + + -- Apply all other snacks keymaps (except scratch which is handled above) + for _, mapping in ipairs(M.snacks_keymaps) do + if mapping.lhs ~= '.' and mapping.lhs ~= 'S' and + mapping.lhs ~= 'e' and mapping.lhs ~= 'o' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + end +end + +-- Initialize keymaps +init_keymaps() + +-- Debug command to check mappings +vim.api.nvim_create_user_command('CheckMappings', function() + print("Current buffer:", vim.api.nvim_get_current_buf()) + + print("\nGlobal mappings for e:") + local global_maps = vim.api.nvim_get_keymap('n') + for _, map in ipairs(global_maps) do + if map.lhs == 'e' then + print(vim.inspect(map)) + end + end + + print("\nBuffer-local mappings for e:") + local buf_maps = vim.api.nvim_buf_get_keymap(0, 'n') + for _, map in ipairs(buf_maps) do + if map.lhs == 'e' then + print(vim.inspect(map)) + end + end + + -- Test explorer function + print("\nTesting explorer function:") + local success, picker = pcall(require, "snacks.picker") + if success then + print("Picker module loaded") + if type(picker.explorer) == "function" then + print("Explorer function exists") + success, err = pcall(picker.explorer) + if not success then + print("Error calling explorer:", err) + end + else + print("Explorer is not a function:", type(picker.explorer)) + end + else + print("Error loading picker:", picker) + end +end, {}) + +return M From 4a7be70200401cf4a27ebdea4c6c3df861767c34 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 14:27:50 +0100 Subject: [PATCH 02/16] fix(keymaps): handle nil tables and cleanup initialization - Add nil checks for all keymap tables - Fix explorer keymap setup - Remove unnecessary debug code - Simplify keymap initialization - Fix incorrect keymap references --- lua/core/keymaps.lua | 105 +++++++++++++------------------------------ 1 file changed, 30 insertions(+), 75 deletions(-) diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 71618af0165..5a41296a9c4 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -198,119 +198,74 @@ local function init_keymaps() -- Function to set up snacks explorer keymaps local function setup_explorer_keymaps() -- First remove any existing mappings - for _, key in ipairs({ 'e', 'o' }) do + for _, key in ipairs({ 'e', 'E' }) do pcall(vim.keymap.del, 'n', key) pcall(vim.keymap.del, 'n', key, { buffer = true }) end -- Set our mappings with high priority - for _, mapping in ipairs(M.snacks_keymaps) do - if mapping.lhs == 'e' or mapping.lhs == 'o' then - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, { - desc = mapping.opts.desc .. ' (high priority)', + for _, mapping in ipairs(M.snacks_keymaps or {}) do + if mapping.lhs == 'e' or mapping.lhs == 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { replace_keycodes = false, nowait = true, silent = true, - }) + })) end end end -- Set up autocmds to maintain our keymaps - vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter', 'FileType' }, { + vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter' }, { group = keymap_group, callback = setup_explorer_keymaps, }) - -- Also set up the keymaps immediately - setup_explorer_keymaps() - - -- Apply core keymaps + -- Set up core keymaps for _, mapping in ipairs(core_keymaps) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - -- Apply telescope keymaps - for _, mapping in ipairs(M.telescope_keymaps) do + -- Set up LSP keymaps on attach + vim.api.nvim_create_autocmd('LspAttach', { + group = keymap_group, + callback = function(args) + M.setup_lsp_keymaps(args.buf) + end, + }) + + -- Set up other plugin keymaps + for _, mapping in ipairs(M.telescope_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - -- Apply diagnostic keymaps - for _, mapping in ipairs(M.diagnostic_keymaps) do + for _, mapping in ipairs(M.diagnostic_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - -- Apply buffer keymaps - for _, mapping in ipairs(M.buffer_keymaps) do + for _, mapping in ipairs(M.buffer_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - -- Apply dadbod keymaps - M.setup_dadbod_keymaps() - - -- Apply session keymaps - M.setup_session_keymaps() - - -- Apply scratch keymaps - for _, mapping in ipairs(M.scratch_keymaps) do + for _, mapping in ipairs(M.snacks_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - -- Apply git signs keymaps - M.setup_gitsigns_keymaps() + for _, mapping in ipairs(M.gitsigns_keymaps or {}) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end - -- Apply leap keymaps - M.setup_leap_keymaps() + for _, mapping in ipairs(M.dadbod_keymaps or {}) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end - -- Apply all other snacks keymaps (except scratch which is handled above) - for _, mapping in ipairs(M.snacks_keymaps) do - if mapping.lhs ~= '.' and mapping.lhs ~= 'S' and - mapping.lhs ~= 'e' and mapping.lhs ~= 'o' then - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end + for _, mapping in ipairs(M.session_keymaps or {}) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end end --- Initialize keymaps +-- Initialize all keymaps init_keymaps() --- Debug command to check mappings -vim.api.nvim_create_user_command('CheckMappings', function() - print("Current buffer:", vim.api.nvim_get_current_buf()) - - print("\nGlobal mappings for e:") - local global_maps = vim.api.nvim_get_keymap('n') - for _, map in ipairs(global_maps) do - if map.lhs == 'e' then - print(vim.inspect(map)) - end - end - - print("\nBuffer-local mappings for e:") - local buf_maps = vim.api.nvim_buf_get_keymap(0, 'n') - for _, map in ipairs(buf_maps) do - if map.lhs == 'e' then - print(vim.inspect(map)) - end - end - - -- Test explorer function - print("\nTesting explorer function:") - local success, picker = pcall(require, "snacks.picker") - if success then - print("Picker module loaded") - if type(picker.explorer) == "function" then - print("Explorer function exists") - success, err = pcall(picker.explorer) - if not success then - print("Error calling explorer:", err) - end - else - print("Explorer is not a function:", type(picker.explorer)) - end - else - print("Error loading picker:", picker) - end -end, {}) - +-- Return the module return M From c338a6a994ecedfdb2354f81f80b35acf4173ec7 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 14:30:32 +0100 Subject: [PATCH 03/16] fix(keymaps): ensure all setup functions are called - Call all keymap setup functions in initialization - Properly organize keymap initialization into sections - Add special handling for explorer keymaps - Fix database and other plugin keymaps not being set --- lua/core/keymaps.lua | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 5a41296a9c4..0befd03373d 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -221,11 +221,6 @@ local function init_keymaps() callback = setup_explorer_keymaps, }) - -- Set up core keymaps - for _, mapping in ipairs(core_keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - -- Set up LSP keymaps on attach vim.api.nvim_create_autocmd('LspAttach', { group = keymap_group, @@ -234,7 +229,12 @@ local function init_keymaps() end, }) - -- Set up other plugin keymaps + -- Set up core keymaps + for _, mapping in ipairs(core_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Set up plugin keymaps for _, mapping in ipairs(M.telescope_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end @@ -247,21 +247,30 @@ local function init_keymaps() vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end + -- Set up snacks keymaps for _, mapping in ipairs(M.snacks_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + -- Skip explorer keymaps as they're handled by setup_explorer_keymaps + if mapping.lhs ~= 'e' and mapping.lhs ~= 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end end - for _, mapping in ipairs(M.gitsigns_keymaps or {}) do + -- Set up scratch buffer keymaps + for _, mapping in ipairs(M.scratch_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end - for _, mapping in ipairs(M.dadbod_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end + -- Set up database keymaps + M.setup_dadbod_keymaps() - for _, mapping in ipairs(M.session_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end + -- Set up session keymaps + M.setup_session_keymaps() + + -- Set up git signs keymaps + M.setup_gitsigns_keymaps() + + -- Set up leap keymaps + M.setup_leap_keymaps() end -- Initialize all keymaps From 3c629b657fe77214884d5fb23493174060c27060 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 14:31:58 +0100 Subject: [PATCH 04/16] fix(keymaps): add missing gitsigns keymaps table - Add gitsigns keymaps table with navigation and actions - Add nil check in setup function - Organize git keymaps under g prefix --- README.md | 268 +++++++- init.lua | 957 +------------------------- lua/core/keymaps.lua | 28 +- lua/custom/plugins/init.lua | 5 - lua/kickstart/health.lua | 52 -- lua/kickstart/plugins/autopairs.lua | 16 - lua/kickstart/plugins/debug.lua | 148 ---- lua/kickstart/plugins/gitsigns.lua | 61 -- lua/kickstart/plugins/indent_line.lua | 9 - lua/kickstart/plugins/lint.lua | 60 -- lua/kickstart/plugins/neo-tree.lua | 25 - 11 files changed, 314 insertions(+), 1315 deletions(-) delete mode 100644 lua/custom/plugins/init.lua delete mode 100644 lua/kickstart/health.lua delete mode 100644 lua/kickstart/plugins/autopairs.lua delete mode 100644 lua/kickstart/plugins/debug.lua delete mode 100644 lua/kickstart/plugins/gitsigns.lua delete mode 100644 lua/kickstart/plugins/indent_line.lua delete mode 100644 lua/kickstart/plugins/lint.lua delete mode 100644 lua/kickstart/plugins/neo-tree.lua diff --git a/README.md b/README.md index aa5f4fc8f1e..a2638080b21 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,267 @@ -# kickstart.nvim +# Customized Neovim Configuration + +This Neovim configuration is based on kickstart.nvim and has been customized with additional features and language support. + +## Features + +### Language Support + +#### Go Development +- Full LSP support via `gopls` +- Advanced formatting with `gofumpt` +- Import management with `goimports` +- Linting with `golangci-lint` +- Debugging support with Delve + +#### Zig Development +- LSP support via `zls` +- Auto-formatting on save +- Syntax highlighting + +#### C Development +- LSP support via `clangd` +- Code formatting with `clang-format` +- Debugging with `codelldb` +- Enhanced features through `clangd_extensions.nvim`: + - Inlay hints + - AST viewer + - Header/source switching + - Symbol info + +#### Python Development +- LSP support via `pyright` +- Code formatting with `black` +- Linting with `ruff` +- Debugging with `debugpy` +- Virtual environment support +- Auto-detection of Python path + +### Debug Adapter Protocol (DAP) +Integrated debugging support with a consistent interface across languages: + +#### Keybindings +- `pb` - Toggle breakpoint +- `pc` - Continue debugging +- `pn` - Step over (Next) +- `pi` - Step into +- `po` - Step out +- `pr` - Debug REPL +- `pl` - Run last debug session +- `px` - Toggle debug UI + +#### Debug UI Features +- Left sidebar: + - Scopes + - Breakpoints + - Call stack + - Watches +- Bottom panel: + - REPL + - Console output + +### Additional Plugins and Features + +#### Snacks.nvim Integration +- Smooth scrolling +- Enhanced terminal support +- Custom dashboard +- Git integration +- Improved display features + +#### Profiling Support +Integrated profiling for multiple languages using `mp`: + +##### Go Profiling +- Uses `pprof` for CPU and memory profiling +- Runs benchmarks and generates profile data +- Opens interactive web UI for visualization +- Shows both CPU and memory profiles +- Supports flame graphs and call graphs + +##### Python Profiling +- Uses `py-spy` for sampling profiler +- Non-intrusive profiling (doesn't modify code) +- Generates SVG flame graphs +- Shows CPU usage and call stacks +- Works with running processes + +##### C/C++ Profiling +- Uses `perf` for system-wide profiling +- Shows CPU usage and call graphs +- Supports hardware performance counters +- Low-overhead profiling +- Kernel and userspace profiling + +For Zig, profiling is still in development in the language tooling. Once stable profiling tools are available, they will be integrated. + +## Installation Guide + +### Core Dependencies + +```bash +# Ubuntu/Debian +sudo apt update +sudo apt install -y git curl unzip ripgrep fd-find make gcc g++ xclip + +# Arch Linux +sudo pacman -S git curl unzip ripgrep fd make gcc xclip +``` + +### Language-Specific Installation + +#### Go Development Tools +```bash +# Install Go +wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz +sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz +echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.bashrc +source ~/.bashrc + +# Install Go tools (will be handled by Mason, but can be installed manually) +go install golang.org/x/tools/gopls@latest +go install mvdan.cc/gofumpt@latest +go install golang.org/x/tools/cmd/goimports@latest +go install github.com/go-delve/delve/cmd/dlv@latest +go install github.com/google/pprof@latest +``` + +#### Zig Development Tools +```bash +# Install Zig (latest version) +wget https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz +sudo tar -C /usr/local -xf zig-linux-x86_64-0.11.0.tar.xz +echo 'export PATH=$PATH:/usr/local/zig-linux-x86_64-0.11.0' >> ~/.bashrc +source ~/.bashrc + +# ZLS will be installed by Mason +``` + +#### C/C++ Development Tools +```bash +# Ubuntu/Debian +sudo apt install -y clang clangd clang-format lldb linux-perf + +# Arch Linux +sudo pacman -S clang lldb perf +``` + +#### Python Development Tools +```bash +# Install Python and pip +sudo apt install -y python3 python3-pip python3-venv + +# Install global tools (will be handled by Mason, but can be installed manually) +pip3 install --user black ruff debugpy py-spy + +# For each project, it's recommended to use a virtual environment: +python3 -m venv .venv +source .venv/bin/activate +pip install black ruff debugpy py-spy +``` + +### Neovim Installation + +#### Install Latest Neovim +```bash +# Ubuntu/Debian +sudo add-apt-repository ppa:neovim-ppa/unstable +sudo apt update +sudo apt install -y neovim + +# Arch Linux +sudo pacman -S neovim +``` + +#### Install Configuration +```bash +# Backup existing config if needed +mv ~/.config/nvim ~/.config/nvim.bak +mv ~/.local/share/nvim ~/.local/share/nvim.bak +mv ~/.local/state/nvim ~/.local/state/nvim.bak +mv ~/.cache/nvim ~/.cache/nvim.bak + +# Clone this configuration +git clone https://github.com/yourusername/nvim-config.git ~/.config/nvim +``` + +### Post-Installation + +1. Start Neovim: + ```bash + nvim + ``` + This will automatically: + - Install the plugin manager (Lazy) + - Install all plugins + - Install LSP servers and tools via Mason + +2. Verify installation: + ``` + :checkhealth + ``` + +3. Install language servers and tools: + ``` + :Mason + ``` + Use `i` to install any missing tools. + +### Troubleshooting + +#### Common Issues + +1. **LSP not working** + - Check if the language server is installed: `:Mason` + - Verify server status: `:LspInfo` + - Install language server manually if needed + +2. **Debugger not working** + - Ensure debugger is installed: `:Mason` + - Check if language tools are in PATH + - For Python, make sure you're in the correct virtual environment + +3. **Profiler issues** + - For Go: Ensure `pprof` is installed and `go` is in PATH + - For Python: Check `py-spy` installation and permissions + - For C/C++: `perf` might need root permissions: `sudo sysctl -w kernel.perf_event_paranoid=1` + +## Usage + +### Go Development +1. Open a Go file +2. LSP features will work automatically +3. Use `gofumpt` for enhanced formatting +4. Debug your Go programs with Delve + +### Zig Development +1. Open a Zig file +2. LSP features and formatting will work automatically + +### C Development +1. Open a C file +2. LSP features will work automatically +3. For debugging: + - Build your program with debug symbols (`gcc -g`) + - Set breakpoints and start debugging + - Use the debug UI to inspect variables and control execution + +### Python Development +1. Open a Python file +2. LSP features will work automatically +3. Use `black` for code formatting +4. For debugging: + - Set breakpoints with `pb` + - Start debugging with `pc` + - Python path will be auto-detected from virtual environments + - Use the debug UI to inspect variables and control execution + +## Customization +- LSP settings can be modified in `lua/plugins/nvim-lspconfig.lua` +- Debug configurations are in `lua/plugins/coding.lua` +- Additional language support can be added through Mason and appropriate LSP configurations + +## Contributing +Feel free to submit issues and enhancement requests! ## Introduction @@ -61,7 +324,7 @@ fork to your machine using one of the commands below, depending on your OS. You likely want to remove `lazy-lock.json` from your fork's `.gitignore` file too - it's ignored in the kickstart repo to make maintenance easier, but it's -[recommended to track it in version control](https://lazy.folke.io/usage/lockfile). +[recommended to track it in version control](https://lazy.folke.io/usage#lockfile). #### Clone kickstart.nvim > **NOTE** @@ -235,4 +498,3 @@ sudo dnf install -y gcc make git ripgrep fd-find unzip neovim sudo pacman -S --noconfirm --needed gcc make git ripgrep fd unzip neovim ``` - diff --git a/init.lua b/init.lua index 7758df93a2e..c607bf05d7f 100644 --- a/init.lua +++ b/init.lua @@ -1,210 +1,13 @@ ---[[ +local config_path = vim.fn.stdpath 'config' +package.path = config_path .. '/?.lua;' .. config_path .. '/?/init.lua;' .. package.path -===================================================================== -==================== READ THIS BEFORE CONTINUING ==================== -===================================================================== -======== .-----. ======== -======== .----------------------. | === | ======== -======== |.-""""""""""""""""""-.| |-----| ======== -======== || || | === | ======== -======== || KICKSTART.NVIM || |-----| ======== -======== || || | === | ======== -======== || || |-----| ======== -======== ||:Tutor || |:::::| ======== -======== |'-..................-'| |____o| ======== -======== `"")----------------(""` ___________ ======== -======== /::::::::::| |::::::::::\ \ no mouse \ ======== -======== /:::========| |==hjkl==:::\ \ required \ ======== -======== '""""""""""""' '""""""""""""' '""""""""""' ======== -======== ======== -===================================================================== -===================================================================== +require 'core.keymaps' +require 'options.autocmds' +require 'options.settings' +-- require 'plugins.init' -What is Kickstart? +local plugins = require 'plugins' - Kickstart.nvim is *not* a distribution. - - Kickstart.nvim is a starting point for your own configuration. - The goal is that you can read every line of code, top-to-bottom, understand - what your configuration is doing, and modify it to suit your needs. - - Once you've done that, you can start exploring, configuring and tinkering to - make Neovim your own! That might mean leaving Kickstart just the way it is for a while - or immediately breaking it into modular pieces. It's up to you! - - If you don't know anything about Lua, I recommend taking some time to read through - a guide. One possible example which will only take 10-15 minutes: - - https://learnxinyminutes.com/docs/lua/ - - After understanding a bit more about Lua, you can use `:help lua-guide` as a - reference for how Neovim integrates Lua. - - :help lua-guide - - (or HTML version): https://neovim.io/doc/user/lua-guide.html - -Kickstart Guide: - - TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. - - If you don't know what this means, type the following: - - - - : - - Tutor - - - - (If you already know the Neovim basics, you can skip this step.) - - Once you've completed that, you can continue working through **AND READING** the rest - of the kickstart init.lua. - - Next, run AND READ `:help`. - This will open up a help window with some basic information - about reading, navigating and searching the builtin help documentation. - - This should be the first place you go to look when you're stuck or confused - with something. It's one of my favorite Neovim features. - - MOST IMPORTANTLY, we provide a keymap "sh" to [s]earch the [h]elp documentation, - which is very useful when you're not exactly sure of what you're looking for. - - I have left several `:help X` comments throughout the init.lua - These are hints about where to find more information about the relevant settings, - plugins or Neovim features used in Kickstart. - - NOTE: Look for lines like this - - Throughout the file. These are for you, the reader, to help you understand what is happening. - Feel free to delete them once you know what you're doing, but they should serve as a guide - for when you are first encountering a few different constructs in your Neovim config. - -If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. - -I hope you enjoy your Neovim journey, -- TJ - -P.S. You can delete this when you're done too. It's your config now! :) ---]] - --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false - --- [[ Setting options ]] --- See `:help vim.opt` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` - --- Make line numbers default -vim.opt.number = true --- You can also add relative line numbers, to help with jumping. --- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true - --- Enable mouse mode, can be useful for resizing splits for example! -vim.opt.mouse = 'a' - --- Don't show the mode, since it's already in the status line -vim.opt.showmode = false - --- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.schedule(function() - vim.opt.clipboard = 'unnamedplus' -end) - --- Enable break indent -vim.opt.breakindent = true - --- Save undo history -vim.opt.undofile = true - --- Case-insensitive searching UNLESS \C or one or more capital letters in the search term -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Keep signcolumn on by default -vim.opt.signcolumn = 'yes' - --- Decrease update time -vim.opt.updatetime = 250 - --- Decrease mapped sequence wait time -vim.opt.timeoutlen = 300 - --- Configure how new splits should be opened -vim.opt.splitright = true -vim.opt.splitbelow = true - --- Sets how neovim will display certain whitespace characters in the editor. --- See `:help 'list'` --- and `:help 'listchars'` -vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } - --- Preview substitutions live, as you type! -vim.opt.inccommand = 'split' - --- Show which line your cursor is on -vim.opt.cursorline = true - --- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 10 - --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` - --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') - --- Diagnostic keymaps -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) - --- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier --- for people to discover. Otherwise, you normally need to press , which --- is not what someone will guess without a bit more experience. --- --- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping --- or just use to exit terminal mode -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) - --- TIP: Disable arrow keys in normal mode --- vim.keymap.set('n', '', 'echo "Use h to move!!"') --- vim.keymap.set('n', '', 'echo "Use l to move!!"') --- vim.keymap.set('n', '', 'echo "Use k to move!!"') --- vim.keymap.set('n', '', 'echo "Use j to move!!"') - --- Keybinds to make split navigation easier. --- Use CTRL+ to switch between windows --- --- See `:help wincmd` for a list of all window commands -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - --- [[ Basic Autocommands ]] --- See `:help lua-guide-autocommands` - --- Highlight when yanking (copying) text --- Try it with `yap` in normal mode --- See `:help vim.highlight.on_yank()` -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) - --- [[ Install `lazy.nvim` plugin manager ]] --- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' @@ -215,737 +18,7 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) --- [[ Configure and install plugins ]] --- --- To check the current status of your plugins, run --- :Lazy --- --- You can press `?` in this menu for help. Use `:q` to close the window --- --- To update plugins you can run --- :Lazy update --- --- NOTE: Here is where you install your plugins. -require('lazy').setup({ - -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically - - -- NOTE: Plugins can also be added by using a table, - -- with the first argument being the link and the following - -- keys can be used to configure plugin behavior/loading/etc. - -- - -- Use `opts = {}` to force a plugin to be loaded. - -- - - -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. This is equivalent to the following Lua: - -- require('gitsigns').setup({ ... }) - -- - -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. - -- - -- This is often very useful to both group configuration, as well as handle - -- lazy loading plugins that don't need to be loaded immediately at startup. - -- - -- For example, in the following configuration, we use: - -- event = 'VimEnter' - -- - -- which loads which-key before all the UI elements are loaded. Events can be - -- normal autocommands events (`:help autocmd-events`). - -- - -- Then, because we use the `opts` key (recommended), the configuration runs - -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VimEnter', -- Sets the loading event to 'VimEnter' - opts = { - -- delay between pressing a key and opening which-key (milliseconds) - -- this setting is independent of vim.opt.timeoutlen - delay = 0, - icons = { - -- set icon mappings to true if you have a Nerd Font - mappings = vim.g.have_nerd_font, - -- If you are using a Nerd Font: set icons.keys to an empty table which will use the - -- default which-key.nvim defined Nerd Font icons, otherwise define a string table - keys = vim.g.have_nerd_font and {} or { - Up = ' ', - Down = ' ', - Left = ' ', - Right = ' ', - C = ' ', - M = ' ', - D = ' ', - S = ' ', - CR = ' ', - Esc = ' ', - ScrollWheelDown = ' ', - ScrollWheelUp = ' ', - NL = ' ', - BS = ' ', - Space = ' ', - Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', - }, - }, - - -- Document existing key chains - spec = { - { 'c', group = '[C]ode', mode = { 'n', 'x' } }, - { 'd', group = '[D]ocument' }, - { 'r', group = '[R]ename' }, - { 's', group = '[S]earch' }, - { 'w', group = '[W]orkspace' }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, - }, - }, - }, - - -- NOTE: Plugins can specify dependencies. - -- - -- The dependencies are proper plugin specifications as well - anything - -- you do for a plugin at the top level, you can do for a dependency. - -- - -- Use the `dependencies` key to specify the dependencies of a particular plugin - - { -- Fuzzy Finder (files, lsp, etc) - 'nvim-telescope/telescope.nvim', - event = 'VimEnter', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - { -- If encountering errors, see telescope-fzf-native README for installation instructions - 'nvim-telescope/telescope-fzf-native.nvim', - - -- `build` is used to run some command when the plugin is installed/updated. - -- This is only run then, not every time Neovim starts up. - build = 'make', - - -- `cond` is a condition used to determine whether this plugin should be - -- installed and loaded. - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - { 'nvim-telescope/telescope-ui-select.nvim' }, - - -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, - }, - config = function() - -- Telescope is a fuzzy finder that comes with a lot of different things that - -- it can fuzzy find! It's more than just a "file finder", it can search - -- many different aspects of Neovim, your workspace, LSP, and more! - -- - -- The easiest way to use Telescope, is to start by doing something like: - -- :Telescope help_tags - -- - -- After running this command, a window will open up and you're able to - -- type in the prompt window. You'll see a list of `help_tags` options and - -- a corresponding preview of the help. - -- - -- Two important keymaps to use while in Telescope are: - -- - Insert mode: - -- - Normal mode: ? - -- - -- This opens a window that shows you all of the keymaps for the current - -- Telescope picker. This is really useful to discover what Telescope can - -- do as well as how to actually do it! - - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - -- You can put your default mappings / updates / etc. in here - -- All the info you're looking for is in `:help telescope.setup()` - -- - -- defaults = { - -- mappings = { - -- i = { [''] = 'to_fuzzy_refine' }, - -- }, - -- }, - -- pickers = {} - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable Telescope extensions if they are installed - pcall(require('telescope').load_extension, 'fzf') - pcall(require('telescope').load_extension, 'ui-select') - - -- See `:help telescope.builtin` - local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) - - -- It's also possible to pass additional configuration options. - -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, { desc = '[S]earch [/] in Open Files' }) - - -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() - builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) - end, - }, - - -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, - }, - }, - }, - { 'Bilal2453/luvit-meta', lazy = true }, - { - -- Main LSP Configuration - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants - 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - - -- Useful status updates for LSP. - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, - - -- Allows extra capabilities provided by nvim-cmp - 'hrsh7th/cmp-nvim-lsp', - }, - config = function() - -- Brief aside: **What is LSP?** - -- - -- LSP is an initialism you've probably heard, but might not understand what it is. - -- - -- LSP stands for Language Server Protocol. It's a protocol that helps editors - -- and language tooling communicate in a standardized fashion. - -- - -- In general, you have a "server" which is some tool built to understand a particular - -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers - -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone - -- processes that communicate with some "client" - in this case, Neovim! - -- - -- LSP provides Neovim with features like: - -- - Go to definition - -- - Find references - -- - Autocompletion - -- - Symbol Search - -- - and more! - -- - -- Thus, Language Servers are external tools that must be installed separately from - -- Neovim. This is where `mason` and related plugins come into play. - -- - -- If you're wondering about lsp vs treesitter, you can check out the wonderfully - -- and elegantly composed help section, `:help lsp-vs-treesitter` - - -- This function gets run when an LSP attaches to a particular buffer. - -- That is to say, every time a new file is opened that is associated with - -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this - -- function will be executed to configure the current buffer - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(event) - -- NOTE: Remember that Lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local map = function(keys, func, desc, mode) - mode = mode or 'n' - vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - - -- Find references for the word under your cursor. - map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - -- Rename the variable under your cursor. - -- Most Language Servers support renaming across files, etc. - map('rn', vim.lsp.buf.rename, '[R]e[n]ame') - - -- Execute a code action, usually your cursor needs to be on top of an error - -- or a suggestion from your LSP for this to activate. - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) - - -- WARN: This is not Goto Definition, this is Goto Declaration. - -- For example, in C this would take you to the header. - map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - - -- The following two autocommands are used to highlight references of the - -- word under your cursor when your cursor rests there for a little while. - -- See `:help CursorHold` for information about when this is executed - -- - -- When you move your cursor, the highlights will be cleared (the second autocommand). - local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.document_highlight, - }) - - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.clear_references, - }) - - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } - end, - }) - end - - -- The following code creates a keymap to toggle inlay hints in your - -- code, if the language server you are using supports them - -- - -- This may be unwanted, since they displace some of your code - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') - end - end, - }) - - -- Change diagnostic symbols in the sign column (gutter) - -- if vim.g.have_nerd_font then - -- local signs = { ERROR = '', WARN = '', INFO = '', HINT = '' } - -- local diagnostic_signs = {} - -- for type, icon in pairs(signs) do - -- diagnostic_signs[vim.diagnostic.severity[type]] = icon - -- end - -- vim.diagnostic.config { signs = { text = diagnostic_signs } } - -- end - - -- LSP servers and clients are able to communicate to each other what features they support. - -- By default, Neovim doesn't support everything that is in the LSP specification. - -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. - -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers. - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) - - -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- - -- Add any additional override configuration in the following tables. Available keys are: - -- - cmd (table): Override the default command used to start the server - -- - filetypes (table): Override the default list of associated filetypes for the server - -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. - -- - settings (table): Override the default settings passed when initializing the server. - -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ - local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- But for many setups, the LSP (`ts_ls`) will work just fine - -- ts_ls = {}, - -- - - lua_ls = { - -- cmd = { ... }, - -- filetypes = { ... }, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, - }, - } - - -- Ensure the servers and tools above are installed - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason - -- - -- You can press `g?` for help in this menu. - require('mason').setup() - - -- You can add other tools here that you want Mason to install - -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } - end, - }, - - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() - require('conform').format { async = true, lsp_format = 'fallback' } - end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - local lsp_format_opt - if disable_filetypes[vim.bo[bufnr].filetype] then - lsp_format_opt = 'never' - else - lsp_format_opt = 'fallback' - end - return { - timeout_ms = 500, - lsp_format = lsp_format_opt, - } - end, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, - - { -- Autocompletion - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - { - 'L3MON4D3/LuaSnip', - build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then - return - end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, - }, - 'saadparwaiz1/cmp_luasnip', - - -- Adds other completion capabilities. - -- nvim-cmp does not ship with all sources by default. They are split - -- into multiple repos for maintenance purposes. - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - }, - config = function() - -- See `:help cmp` - local cmp = require 'cmp' - local luasnip = require 'luasnip' - luasnip.config.setup {} - - cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { completeopt = 'menu,menuone,noinsert' }, - - -- For an understanding of why these mappings were - -- chosen, you will need to read `:help ins-completion` - -- - -- No, but seriously. Please read `:help ins-completion`, it is really good! - mapping = cmp.mapping.preset.insert { - -- Select the [n]ext item - [''] = cmp.mapping.select_next_item(), - -- Select the [p]revious item - [''] = cmp.mapping.select_prev_item(), - - -- Scroll the documentation window [b]ack / [f]orward - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - - -- Accept ([y]es) the completion. - -- This will auto-import if your LSP supports it. - -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, - - -- If you prefer more traditional completion keymaps, - -- you can uncomment the following lines - --[''] = cmp.mapping.confirm { select = true }, - --[''] = cmp.mapping.select_next_item(), - --[''] = cmp.mapping.select_prev_item(), - - -- Manually trigger a completion from nvim-cmp. - -- Generally you don't need this, because nvim-cmp will display - -- completions whenever it has completion options available. - [''] = cmp.mapping.complete {}, - - -- Think of as moving to the right of your snippet expansion. - -- So if you have a snippet that's like: - -- function $name($args) - -- $body - -- end - -- - -- will move you to the right of each of the expansion locations. - -- is similar, except moving you backwards. - [''] = cmp.mapping(function() - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - end - end, { 'i', 's' }), - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps - }, - sources = { - { - name = 'lazydev', - -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it - group_index = 0, - }, - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, - } - end, - }, - - { -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command in the config to whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() - -- Load the colorscheme here. - -- Like many other themes, this one has different styles, and you could load - -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' - - -- You can configure highlights by doing something like: - vim.cmd.hi 'Comment gui=none' - end, - }, - - -- Highlight todo, notes, etc in comments - { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, - - { -- Collection of various small independent plugins/modules - 'echasnovski/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - -- Simple and easy statusline. - -- You could remove this setup call if you don't like it, - -- and try some other statusline plugin - local statusline = require 'mini.statusline' - -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } - - -- You can configure sections in the statusline by overriding their - -- default behavior. For example, here we set the section for - -- cursor location to LINE:COLUMN - ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() - return '%2l:%-2v' - end - - -- ... and there is more! - -- Check out: https://github.com/echasnovski/mini.nvim - end, - }, - { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - main = 'nvim-treesitter.configs', -- Sets main module to use for opts - -- [[ Configure Treesitter ]] See `:help nvim-treesitter` - opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. - additional_vim_regex_highlighting = { 'ruby' }, - }, - indent = { enable = true, disable = { 'ruby' } }, - }, - -- There are additional nvim-treesitter modules that you can use to interact - -- with nvim-treesitter. You should go explore a few and see what interests you: - -- - -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` - -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects - }, - - -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the - -- init.lua. If you want these files, they are in the repository, so you can just download them and - -- place them in the correct locations. - - -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for Kickstart - -- - -- Here are some example plugins that I've included in the Kickstart repository. - -- Uncomment any of the lines below to enable them (you will need to restart nvim). - -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps - - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- This is the easiest way to modularize your config. - -- - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, - -- - -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` - -- Or use telescope! - -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search -}, { +require('lazy').setup({ plugins }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table @@ -967,5 +40,19 @@ require('lazy').setup({ }, }) +-- Set up swap file directory to be in a central location +vim.opt.directory = vim.fn.stdpath('data') .. '/swapfiles/' + +-- Create the swap directory if it doesn't exist +local swap_dir = vim.fn.stdpath('data') .. '/swapfiles' +if vim.fn.isdirectory(swap_dir) == 0 then + vim.fn.mkdir(swap_dir, 'p') +end + +-- Configure swap file behavior +vim.opt.swapfile = true -- Keep swap files for recovery +vim.opt.updatetime = 300 -- Save swap file after 300ms of inactivity +vim.opt.updatecount = 100 -- Write to swap file after 100 characters + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 0befd03373d..eeb1bfa3217 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -161,9 +161,35 @@ M.scratch_keymaps = { opts = { desc = 'Select scratch buffer' } }, } +-- Git signs keymaps (all under g for Git) +M.gitsigns_keymaps = { + -- Navigation + { mode = 'n', lhs = ']c', rhs = function() + if vim.wo.diff then return ']c' end + vim.schedule(function() require('gitsigns').next_hunk() end) + return '' + end, opts = { desc = 'Git: Next hunk', expr = true } }, + + { mode = 'n', lhs = '[c', rhs = function() + if vim.wo.diff then return '[c' end + vim.schedule(function() require('gitsigns').prev_hunk() end) + return '' + end, opts = { desc = 'Git: Previous hunk', expr = true } }, + + -- Actions + { mode = 'n', lhs = 'gh', rhs = function() require('gitsigns').preview_hunk() end, opts = { desc = 'Git: Preview hunk' } }, + { mode = 'n', lhs = 'gb', rhs = function() require('gitsigns').blame_line() end, opts = { desc = 'Git: Blame line' } }, + { mode = 'n', lhs = 'gd', rhs = function() require('gitsigns').diffthis() end, opts = { desc = 'Git: Show diff' } }, + { mode = { 'n', 'v' }, lhs = 'gs', rhs = function() require('gitsigns').stage_hunk() end, opts = { desc = 'Git: Stage hunk' } }, + { mode = { 'n', 'v' }, lhs = 'gr', rhs = function() require('gitsigns').reset_hunk() end, opts = { desc = 'Git: Reset hunk' } }, + { mode = 'n', lhs = 'gS', rhs = function() require('gitsigns').stage_buffer() end, opts = { desc = 'Git: Stage buffer' } }, + { mode = 'n', lhs = 'gu', rhs = function() require('gitsigns').undo_stage_hunk() end, opts = { desc = 'Git: Undo stage' } }, + { mode = 'n', lhs = 'gR', rhs = function() require('gitsigns').reset_buffer() end, opts = { desc = 'Git: Reset buffer' } }, +} + -- Setup function for git signs keymaps function M.setup_gitsigns_keymaps() - for _, mapping in ipairs(M.gitsigns_keymaps) do + for _, mapping in ipairs(M.gitsigns_keymaps or {}) do vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) end end diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d8d7a..00000000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/kickstart/health.lua b/lua/kickstart/health.lua deleted file mode 100644 index b59d08649af..00000000000 --- a/lua/kickstart/health.lua +++ /dev/null @@ -1,52 +0,0 @@ ---[[ --- --- This file is not required for your own configuration, --- but helps people determine if their system is setup correctly. --- ---]] - -local check_version = function() - local verstr = tostring(vim.version()) - if not vim.version.ge then - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) - return - end - - if vim.version.ge(vim.version(), '0.10-dev') then - vim.health.ok(string.format("Neovim version is: '%s'", verstr)) - else - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) - end -end - -local check_external_reqs = function() - -- Basic utils: `git`, `make`, `unzip` - for _, exe in ipairs { 'git', 'make', 'unzip', 'rg' } do - local is_executable = vim.fn.executable(exe) == 1 - if is_executable then - vim.health.ok(string.format("Found executable: '%s'", exe)) - else - vim.health.warn(string.format("Could not find executable: '%s'", exe)) - end - end - - return true -end - -return { - check = function() - vim.health.start 'kickstart.nvim' - - vim.health.info [[NOTE: Not every warning is a 'must-fix' in `:checkhealth` - - Fix only warnings for plugins and languages you intend to use. - Mason will give warnings for languages that are not installed. - You do not need to install, unless you want to use those languages!]] - - local uv = vim.uv or vim.loop - vim.health.info('System Information: ' .. vim.inspect(uv.os_uname())) - - check_version() - check_external_reqs() - end, -} diff --git a/lua/kickstart/plugins/autopairs.lua b/lua/kickstart/plugins/autopairs.lua deleted file mode 100644 index 87a7e5ffa2e..00000000000 --- a/lua/kickstart/plugins/autopairs.lua +++ /dev/null @@ -1,16 +0,0 @@ --- autopairs --- https://github.com/windwp/nvim-autopairs - -return { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - -- Optional dependency - dependencies = { 'hrsh7th/nvim-cmp' }, - config = function() - require('nvim-autopairs').setup {} - -- If you want to automatically add `(` after selecting a function or method - local cmp_autopairs = require 'nvim-autopairs.completion.cmp' - local cmp = require 'cmp' - cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) - end, -} diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua deleted file mode 100644 index 753cb0cedd3..00000000000 --- a/lua/kickstart/plugins/debug.lua +++ /dev/null @@ -1,148 +0,0 @@ --- debug.lua --- --- Shows how to use the DAP plugin to debug your code. --- --- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. That's why it's called --- kickstart.nvim and not kitchen-sink.nvim ;) - -return { - -- NOTE: Yes, you can install new plugins here! - 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well - dependencies = { - -- Creates a beautiful debugger UI - 'rcarriga/nvim-dap-ui', - - -- Required dependency for nvim-dap-ui - 'nvim-neotest/nvim-nio', - - -- Installs the debug adapters for you - 'williamboman/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', - - -- Add your own debuggers here - 'leoluz/nvim-dap-go', - }, - keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - '', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - { - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - 'b', - function() - require('dap').toggle_breakpoint() - end, - desc = 'Debug: Toggle Breakpoint', - }, - { - 'B', - function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, - desc = 'Debug: Set Breakpoint', - }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, - }, - config = function() - local dap = require 'dap' - local dapui = require 'dapui' - - require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, - - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information - handlers = {}, - - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - 'delve', - }, - } - - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', - }, - }, - } - - -- Change breakpoint icons - -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) - -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) - -- local breakpoint_icons = vim.g.have_nerd_font - -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } - -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } - -- for type, icon in pairs(breakpoint_icons) do - -- local tp = 'Dap' .. type - -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' - -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) - -- end - - dap.listeners.after.event_initialized['dapui_config'] = dapui.open - dap.listeners.before.event_terminated['dapui_config'] = dapui.close - dap.listeners.before.event_exited['dapui_config'] = dapui.close - - -- Install golang specific config - require('dap-go').setup { - delve = { - -- On Windows delve must be run attached or it crashes. - -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring - detached = vim.fn.has 'win32' == 0, - }, - } - end, -} diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/kickstart/plugins/gitsigns.lua deleted file mode 100644 index c269bc06e15..00000000000 --- a/lua/kickstart/plugins/gitsigns.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Adds git related signs to the gutter, as well as utilities for managing changes --- NOTE: gitsigns is already included in init.lua but contains only the base --- config. This will add also the recommended keymaps. - -return { - { - 'lewis6991/gitsigns.nvim', - opts = { - on_attach = function(bufnr) - local gitsigns = require 'gitsigns' - - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end - - -- Navigation - map('n', ']c', function() - if vim.wo.diff then - vim.cmd.normal { ']c', bang = true } - else - gitsigns.nav_hunk 'next' - end - end, { desc = 'Jump to next git [c]hange' }) - - map('n', '[c', function() - if vim.wo.diff then - vim.cmd.normal { '[c', bang = true } - else - gitsigns.nav_hunk 'prev' - end - end, { desc = 'Jump to previous git [c]hange' }) - - -- Actions - -- visual mode - map('v', 'hs', function() - gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'git [s]tage hunk' }) - map('v', 'hr', function() - gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'git [r]eset hunk' }) - -- normal mode - map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) - map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) - map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) - map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) - map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) - map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) - map('n', 'hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) - map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) - map('n', 'hD', function() - gitsigns.diffthis '@' - end, { desc = 'git [D]iff against last commit' }) - -- Toggles - map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) - map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) - end, - }, - }, -} diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/kickstart/plugins/indent_line.lua deleted file mode 100644 index ed7f269399f..00000000000 --- a/lua/kickstart/plugins/indent_line.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - { -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help ibl` - main = 'ibl', - opts = {}, - }, -} diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua deleted file mode 100644 index 907c6bf3e31..00000000000 --- a/lua/kickstart/plugins/lint.lua +++ /dev/null @@ -1,60 +0,0 @@ -return { - - { -- Linting - 'mfussenegger/nvim-lint', - event = { 'BufReadPre', 'BufNewFile' }, - config = function() - local lint = require 'lint' - lint.linters_by_ft = { - markdown = { 'markdownlint' }, - } - - -- To allow other plugins to add linters to require('lint').linters_by_ft, - -- instead set linters_by_ft like this: - -- lint.linters_by_ft = lint.linters_by_ft or {} - -- lint.linters_by_ft['markdown'] = { 'markdownlint' } - -- - -- However, note that this will enable a set of default linters, - -- which will cause errors unless these tools are available: - -- { - -- clojure = { "clj-kondo" }, - -- dockerfile = { "hadolint" }, - -- inko = { "inko" }, - -- janet = { "janet" }, - -- json = { "jsonlint" }, - -- markdown = { "vale" }, - -- rst = { "vale" }, - -- ruby = { "ruby" }, - -- terraform = { "tflint" }, - -- text = { "vale" } - -- } - -- - -- You can disable the default linters by setting their filetypes to nil: - -- lint.linters_by_ft['clojure'] = nil - -- lint.linters_by_ft['dockerfile'] = nil - -- lint.linters_by_ft['inko'] = nil - -- lint.linters_by_ft['janet'] = nil - -- lint.linters_by_ft['json'] = nil - -- lint.linters_by_ft['markdown'] = nil - -- lint.linters_by_ft['rst'] = nil - -- lint.linters_by_ft['ruby'] = nil - -- lint.linters_by_ft['terraform'] = nil - -- lint.linters_by_ft['text'] = nil - - -- Create autocommand which carries out the actual linting - -- on the specified events. - local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) - vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { - group = lint_augroup, - callback = function() - -- Only run the linter in buffers that you can modify in order to - -- avoid superfluous noise, notably within the handy LSP pop-ups that - -- describe the hovered symbol using Markdown. - if vim.opt_local.modifiable:get() then - lint.try_lint() - end - end, - }) - end, - }, -} diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua deleted file mode 100644 index bd4422695aa..00000000000 --- a/lua/kickstart/plugins/neo-tree.lua +++ /dev/null @@ -1,25 +0,0 @@ --- Neo-tree is a Neovim plugin to browse the file system --- https://github.com/nvim-neo-tree/neo-tree.nvim - -return { - 'nvim-neo-tree/neo-tree.nvim', - version = '*', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended - 'MunifTanjim/nui.nvim', - }, - cmd = 'Neotree', - keys = { - { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, - }, - opts = { - filesystem = { - window = { - mappings = { - ['\\'] = 'close_window', - }, - }, - }, - }, -} From 231250d4591bd8445929ed5ddcddaf1c40857c0b Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 16:22:35 +0100 Subject: [PATCH 05/16] fix(sessions): handle LSP semantic tokens - Add safe LSP state restoration during session load - Temporarily disable semantic tokens to prevent errors - Add deferred semantic tokens refresh after session load - Improve session file naming and buffer cleanup - Add user notifications for session operations --- lua/plugins/mini.lua | 218 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 lua/plugins/mini.lua diff --git a/lua/plugins/mini.lua b/lua/plugins/mini.lua new file mode 100644 index 00000000000..a8b4c30ef23 --- /dev/null +++ b/lua/plugins/mini.lua @@ -0,0 +1,218 @@ +return { -- Collection of various small independent plugins/modules + 'echasnovski/mini.nvim', + config = function() + -- Better Around/Inside textobjects + -- + -- Examples: + -- - va) - [V]isually select [A]round [)]paren + -- - yinq - [Y]ank [I]nside [N]ext [Q]uote + -- - ci' - [C]hange [I]nside [']quote + require('mini.ai').setup { n_lines = 500 } + + -- Add/delete/replace surroundings (brackets, quotes, etc.) + -- + -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren + -- - sd' - [S]urround [D]elete [']quotes + -- - sr)' - [S]urround [R]eplace [)] ['] + require('mini.surround').setup() + + -- Simple and easy statusline. + -- You could remove this setup call if you don't like it, + -- and try some other statusline plugin + local statusline = require 'mini.statusline' + -- set use_icons to true if you have a Nerd Font + statusline.setup { use_icons = vim.g.have_nerd_font } + + -- You can configure sections in the statusline by overriding their + -- default behavior. For example, here we set the section for + -- cursor location to LINE:COLUMN + ---@diagnostic disable-next-line: duplicate-set-field + statusline.section_location = function() + return '%2l:%-2v' + end + + -- Session management + local session = require('mini.sessions') + + -- Function to safely restore LSP state + local function safe_restore_lsp() + -- Disable semantic tokens temporarily during session load + local semantic_tokens = {} + for _, client in pairs(vim.lsp.get_active_clients()) do + semantic_tokens[client.id] = client.server_capabilities.semanticTokensProvider + client.server_capabilities.semanticTokensProvider = nil + end + + -- Return a function to restore semantic tokens + return function() + for id, tokens in pairs(semantic_tokens) do + local client = vim.lsp.get_client_by_id(id) + if client then + client.server_capabilities.semanticTokensProvider = tokens + end + end + end + end + + -- Get session name based on current directory + local function get_session_name() + local cwd = vim.fn.getcwd() + -- Replace path separators and spaces with underscores + local name = string.gsub(cwd, '[/\\%s]', '_') + return name + end + + -- Clean up buffers before saving session + local function pre_save() + -- Store current buffers + local bufs = vim.api.nvim_list_bufs() + + -- Close special buffers that we don't want to save + for _, buf in ipairs(bufs) do + if vim.api.nvim_buf_is_valid(buf) then + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local filetype = vim.api.nvim_buf_get_option(buf, 'filetype') + if buftype ~= '' or filetype == 'TelescopePrompt' or filetype == 'neo-tree' then + vim.api.nvim_buf_delete(buf, { force = true }) + end + end + end + end + + -- Clean up after loading session + local function post_load() + -- Close any empty buffers that might have been created + local bufs = vim.api.nvim_list_bufs() + for _, buf in ipairs(bufs) do + if vim.api.nvim_buf_is_valid(buf) then + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local filetype = vim.api.nvim_buf_get_option(buf, 'filetype') + local modified = vim.api.nvim_buf_get_option(buf, 'modified') + local name = vim.api.nvim_buf_get_name(buf) + + if not modified and (name == '' or buftype ~= '' or filetype == 'TelescopePrompt' or filetype == 'neo-tree') then + vim.api.nvim_buf_delete(buf, { force = true }) + end + end + end + end + + -- Create session functions for use in keymaps + _G.MiniSession = { + save = function() + local name = get_session_name() + local ok, err = pcall(function() session.write(name) end) + if ok then + vim.notify(string.format('Session: Successfully saved "%s"', name), + vim.log.levels.INFO) + else + vim.notify(string.format('Session: Failed to save "%s": %s', name, err), + vim.log.levels.ERROR) + end + end, + + load = function() + local name = get_session_name() + local ok, err = pcall(function() session.read(name) end) + if ok then + vim.notify(string.format('Session: Successfully loaded "%s"', name), + vim.log.levels.INFO) + else + vim.notify(string.format('Session: Failed to load "%s": %s', name, err), + vim.log.levels.ERROR) + end + end, + + delete = function() + local name = get_session_name() + local ok, err = pcall(function() session.delete(name) end) + if ok then + vim.notify(string.format('Session: Successfully deleted "%s"', name), + vim.log.levels.INFO) + else + vim.notify(string.format('Session: Failed to delete "%s": %s', name, err), + vim.log.levels.ERROR) + end + end + } + + -- Create session directory + local session_dir = vim.fn.stdpath('data') .. '/sessions' + if vim.fn.isdirectory(session_dir) == 0 then + vim.fn.mkdir(session_dir, 'p') + end + + session.setup({ + -- Directory to store session files + directory = session_dir, + -- File to use for current session + file = get_session_name(), + -- Whether to force write session file on each write operation + force_write = true, + -- Hook functions for actions + hooks = { + -- Before loading a session + pre_load = function() + -- Clean up buffers safely + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + local ft = vim.api.nvim_buf_get_option(buf, 'filetype') + -- Don't close special buffers + if ft ~= 'NvimTree' and ft ~= 'neo-tree' and ft ~= 'TelescopePrompt' then + pcall(vim.api.nvim_buf_delete, buf, { force = false }) + end + end + return safe_restore_lsp() + end, + -- After loading a session + post_load = function() + post_load() + -- Restore LSP semantic tokens after a short delay + vim.defer_fn(function() + if vim.v.vim_did_enter == 1 then + for _, client in pairs(vim.lsp.get_active_clients()) do + if client.server_capabilities.semanticTokensProvider then + vim.lsp.semantic_tokens.force_refresh(client.id) + end + end + end + end, 1000) + vim.notify('Session loaded!', vim.log.levels.INFO) + end, + -- Before saving a session + pre_save = function() + vim.notify('Saving session...', vim.log.levels.INFO) + pre_save() + end, + -- After saving a session + post_save = nil, + }, + -- Whether to read latest session if Neovim opened without file arguments + autoread = false, + -- Whether to write current session before quitting Neovim + autowrite = false, -- We'll handle this ourselves + -- Whether to disable showing non-error feedback + verbose = { + read = false, -- We'll handle our own notifications + write = false, + delete = false, + }, + }) + + -- Update session name when directory changes + vim.api.nvim_create_autocmd('DirChanged', { + callback = function() + session.setup({ file = get_session_name() }) + end, + }) + + -- Auto-save session when leaving Neovim + vim.api.nvim_create_autocmd('VimLeavePre', { + callback = function() + -- Only save if we have buffers + if #vim.fn.getbufinfo({buflisted = 1}) > 0 then + _G.MiniSession.save() + end + end, + }) + end, +} From fa67d671d39bc52068d568a47d48382d9d61c6ee Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 16:57:27 +0100 Subject: [PATCH 06/16] fix(snacks): fix notification history keymap Use snacks.notifier module directly to show notification history --- lua/core/keymaps.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index eeb1bfa3217..0c3514d21db 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -159,6 +159,8 @@ M.scratch_keymaps = { opts = { desc = 'Toggle scratch buffer' } }, { mode = 'n', lhs = 'S', rhs = function() require("snacks").scratch.select() end, opts = { desc = 'Select scratch buffer' } }, + { mode = 'n', lhs = 'nh', rhs = function() require("snacks.notifier").show_history() end, + opts = { desc = 'Show notification history' } }, } -- Git signs keymaps (all under g for Git) From 3de2b7752d4c1972946443b4aeefaf543c9c22e9 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 16:59:33 +0100 Subject: [PATCH 07/16] fix: remove neodev.nvim as it's replaced by lazydev.nvim --- lua/plugins/nvim-lspconfig.lua | 204 +++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 lua/plugins/nvim-lspconfig.lua diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua new file mode 100644 index 00000000000..d5115ff035b --- /dev/null +++ b/lua/plugins/nvim-lspconfig.lua @@ -0,0 +1,204 @@ +return { + -- Main LSP Configuration + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs and related tools to stdpath for Neovim + { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants + 'williamboman/mason-lspconfig.nvim', + -- 'folke/neodev.nvim', -- Adds support for Neovim Lua API -- No longer needed with lazydev + { + 'WhoIsSethDaniel/mason-tool-installer.nvim', + config = function() + require('mason-tool-installer').setup { + ensure_installed = { + 'lua-language-server', + 'marksman', + -- Go tools + 'gopls', -- Go LSP + 'gofumpt', -- Stricter Go formatter + 'goimports', -- Go import manager + 'golangci-lint', -- Go linter + 'delve', -- Go debugger + -- Zig tools + 'zls', -- Zig LSP + -- C tools + 'clangd', -- C/C++ LSP + 'clang-format', -- C/C++ formatter + 'codelldb', -- Native code debugger + -- Python tools + 'pyright', -- Python LSP + 'black', -- Python formatter + 'ruff', -- Python linter + 'debugpy', -- Python debugger + -- SQL tools + 'sqls', -- Advanced SQL LSP + }, + auto_update = true, + run_on_start = true, + } + end, + }, + + -- Useful status updates for LSP. + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, + + -- Allows extra capabilities provided by nvim-cmp + 'hrsh7th/cmp-nvim-lsp', + }, + config = function() + -- Brief aside: **What is LSP?** + -- + -- LSP is an initialism you've probably heard, but might not understand what it is. + -- + -- LSP stands for Language Server Protocol. It's a protocol that helps editors + -- and language tooling communicate in a standardized fashion. + -- + -- See `:help lsp` for more details. + + -- Enable the following language servers + -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. + -- + -- Add any additional override configuration in the following tables. Available keys are: + -- - cmd (table): Override the default command used to start the server + -- - filetypes (table): Override the default list of associated filetypes for the server + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. + -- - settings (table): Override the default settings passed to the server. Can be used to disable diagnostics. + local servers = { + -- Python + pyright = {}, + -- Go + gopls = { + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = false, -- Let golangci-lint handle this + gofumpt = false, -- Let null-ls handle this + hints = { + assignVariableTypes = false, -- Disable hints for better performance + compositeLiteralFields = false, + compositeLiteralTypes = false, + constantValues = false, + functionTypeParameters = false, + parameterNames = false, + rangeVariableTypes = false, + }, + vulncheck = "Off", -- Disable vulnerability checking + completionBudget = "100ms", -- Limit completion time + symbolMatcher = "FastFuzzy", -- Faster symbol matching + symbolStyle = "Dynamic", + usePlaceholders = false, -- Disable placeholders for better performance + matcher = "Fuzzy", -- Faster matching algorithm + diagnosticsDelay = "500ms", -- Add slight delay to batch diagnostics + }, + }, + }, + -- Lua + lua_ls = { + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + }, + -- SQL - Advanced SQL language server with better completion + sqls = { + settings = { + sqls = { + connections = {}, -- Will be populated by dadbod + lowercaseKeywords = true, -- Format keywords to lowercase + }, + }, + }, + } + + -- Setup neovim lua configuration + -- require('neodev').setup({ + -- library = { + -- enabled = true, + -- runtime = true, + -- types = true, + -- plugins = true, + -- }, + -- }) + + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + -- Ensure the servers above are installed + local mason_lspconfig = require 'mason-lspconfig' + + mason_lspconfig.setup { + ensure_installed = vim.tbl_keys(servers), + } + + mason_lspconfig.setup_handlers { + function(server_name) + require('lspconfig')[server_name].setup { + capabilities = capabilities, + settings = servers[server_name] and servers[server_name].settings or {}, + filetypes = servers[server_name] and servers[server_name].filetypes, + } + end, + } + + -- Single LSP attach handler for all functionality + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), + callback = function(args) + -- Remove any diagnostic keymaps + pcall(vim.keymap.del, 'n', 'e', { buffer = args.buf }) + + -- Get the client + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client then return end + + -- Only set up document formatting for null-ls + if client.name ~= "null-ls" then + client.server_capabilities.documentFormattingProvider = false + end + + -- Set up LSP keymaps + require('core.keymaps').setup_lsp_keymaps(args.buf) + + -- Override the built-in LSP handler for references to use telescope + vim.lsp.handlers['textDocument/references'] = function(_, result, ctx) + if not result or vim.tbl_isempty(result) then + vim.notify('No references found') + else + require('telescope.builtin').lsp_references() + end + end + + -- Set up document highlight on hover only if the server supports it + if client.server_capabilities.documentHighlightProvider then + local highlight_group = vim.api.nvim_create_augroup('lsp_document_highlight_' .. args.buf, { clear = true }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + group = highlight_group, + buffer = args.buf, + callback = function() + -- Check if the client is still attached and valid + if vim.lsp.buf_get_clients(args.buf)[1] then + vim.lsp.buf.document_highlight() + end + end, + }) + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + group = highlight_group, + buffer = args.buf, + callback = function() + -- Check if the client is still attached and valid + if vim.lsp.buf_get_clients(args.buf)[1] then + vim.lsp.buf.clear_references() + end + end, + }) + end + end, + }) + end, +} From 08b2f6acbdbec260632edb79a5d73f2e296d989d Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 18:09:26 +0100 Subject: [PATCH 08/16] refactor: remove session managers - Remove auto-session plugin - Disable semantic tokens for gopls to prevent errors --- _home_adam_.config_nvim | 62 ++++++++ build.zen | 44 ++++++ init.lua | 7 +- lua/options/autocmds.lua | 23 +++ lua/options/gitsigns.lua | 12 ++ lua/options/settings.lua | 75 +++++++++ lua/plugins/blink-cmp.lua | 12 ++ lua/plugins/bufferline.lua | 56 +++++++ lua/plugins/coding.lua | 252 +++++++++++++++++++++++++++++++ lua/plugins/conform.lua | 42 ++++++ lua/plugins/dadbod.lua | 67 ++++++++ lua/plugins/garbage-day.lua | 21 +++ lua/plugins/gitsigns.lua | 35 +++++ lua/plugins/gruvbox.lua | 17 +++ lua/plugins/init.lua | 12 ++ lua/plugins/lazydev.lua | 12 ++ lua/plugins/leap.lua | 25 +++ lua/plugins/luvit-meta.lua | 1 + lua/plugins/mason-null-ls.lua | 18 +++ lua/plugins/mini-icons.lua | 42 ++++++ lua/plugins/mini-surround.lua | 11 ++ lua/plugins/mini.lua | 218 -------------------------- lua/plugins/null-ls.lua | 68 +++++++++ lua/plugins/nvim-autopairs.lua | 35 +++++ lua/plugins/nvim-cmp.lua | 115 ++++++++++++++ lua/plugins/nvim-lspconfig.lua | 77 ++++++---- lua/plugins/nvim-treesitter.lua | 25 +++ lua/plugins/snacks.lua | 3 + lua/plugins/snacks/core.lua | 34 +++++ lua/plugins/snacks/dashboard.lua | 19 +++ lua/plugins/snacks/display.lua | 15 ++ lua/plugins/snacks/git.lua | 16 ++ lua/plugins/snacks/init.lua | 49 ++++++ lua/plugins/snacks/picker.lua | 24 +++ lua/plugins/snacks/terminal.lua | 10 ++ lua/plugins/telescope.lua | 121 +++++++++++++++ lua/plugins/todo-comments.lua | 9 ++ lua/plugins/vim-sleuth.lua | 1 + lua/plugins/which-key.lua | 108 +++++++++++++ src/main.zen | 5 + 40 files changed, 1550 insertions(+), 248 deletions(-) create mode 100644 _home_adam_.config_nvim create mode 100644 build.zen create mode 100644 lua/options/autocmds.lua create mode 100644 lua/options/gitsigns.lua create mode 100644 lua/options/settings.lua create mode 100644 lua/plugins/blink-cmp.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/coding.lua create mode 100644 lua/plugins/conform.lua create mode 100644 lua/plugins/dadbod.lua create mode 100644 lua/plugins/garbage-day.lua create mode 100644 lua/plugins/gitsigns.lua create mode 100644 lua/plugins/gruvbox.lua create mode 100644 lua/plugins/init.lua create mode 100644 lua/plugins/lazydev.lua create mode 100644 lua/plugins/leap.lua create mode 100644 lua/plugins/luvit-meta.lua create mode 100644 lua/plugins/mason-null-ls.lua create mode 100644 lua/plugins/mini-icons.lua create mode 100644 lua/plugins/mini-surround.lua delete mode 100644 lua/plugins/mini.lua create mode 100644 lua/plugins/null-ls.lua create mode 100644 lua/plugins/nvim-autopairs.lua create mode 100644 lua/plugins/nvim-cmp.lua create mode 100644 lua/plugins/nvim-treesitter.lua create mode 100644 lua/plugins/snacks.lua create mode 100644 lua/plugins/snacks/core.lua create mode 100644 lua/plugins/snacks/dashboard.lua create mode 100644 lua/plugins/snacks/display.lua create mode 100644 lua/plugins/snacks/git.lua create mode 100644 lua/plugins/snacks/init.lua create mode 100644 lua/plugins/snacks/picker.lua create mode 100644 lua/plugins/snacks/terminal.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/todo-comments.lua create mode 100644 lua/plugins/vim-sleuth.lua create mode 100644 lua/plugins/which-key.lua create mode 100644 src/main.zen diff --git a/_home_adam_.config_nvim b/_home_adam_.config_nvim new file mode 100644 index 00000000000..27c99652093 --- /dev/null +++ b/_home_adam_.config_nvim @@ -0,0 +1,62 @@ +let SessionLoad = 1 +let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1 +let v:this_session=expand(":p") +silent only +silent tabonly +cd ~/.config/nvim +if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' + let s:wipebuf = bufnr('%') +endif +let s:shortmess_save = &shortmess +if &shortmess =~ 'A' + set shortmess=aoOA +else + set shortmess=aoO +endif +badd +1 ~/.config/nvim/lua/core/keymaps.lua +argglobal +%argdel +edit ~/.config/nvim/lua/core/keymaps.lua +wincmd t +let s:save_winminheight = &winminheight +let s:save_winminwidth = &winminwidth +set winminheight=0 +set winheight=1 +set winminwidth=0 +set winwidth=1 +argglobal +setlocal fdm=manual +setlocal fde=0 +setlocal fmr={{{,}}} +setlocal fdi=# +setlocal fdl=0 +setlocal fml=1 +setlocal fdn=20 +setlocal fen +silent! normal! zE +let &fdl = &fdl +let s:l = 1 - ((0 * winheight(0) + 17) / 35) +if s:l < 1 | let s:l = 1 | endif +keepjumps exe s:l +normal! zt +keepjumps 1 +normal! 0 +tabnext 1 +if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal' + silent exe 'bwipe ' . s:wipebuf +endif +unlet! s:wipebuf +set winheight=1 winwidth=20 +let &shortmess = s:shortmess_save +let &winminheight = s:save_winminheight +let &winminwidth = s:save_winminwidth +let s:sx = expand(":p:r")."x.vim" +if filereadable(s:sx) + exe "source " . fnameescape(s:sx) +endif +let &g:so = s:so_save | let &g:siso = s:siso_save +set hlsearch +nohlsearch +doautoall SessionLoadPost +unlet SessionLoad +" vim: set ft=vim : diff --git a/build.zen b/build.zen new file mode 100644 index 00000000000..97511545713 --- /dev/null +++ b/build.zen @@ -0,0 +1,44 @@ +// +// The Zen Programming Language(tm) +// Copyright (c) 2018-2020 kristopher tate & connectFree Corporation. +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// +// This project may be licensed under the terms of the ConnectFree Reference +// Source License (CF-RSL). Corporate and Academic licensing terms are also +// available. Please contact for details. +// +// Zen, the Zen three-circles logo and The Zen Programming Language are +// trademarks of connectFree Corporation in Japan and other countries. +// +// connectFree and the connectFree logo are registered trademarks +// of connectFree Corporation in Japan and other countries. connectFree +// trademarks and branding may not be used without express written permission +// of connectFree. Please remove all trademarks and branding before use. +// +// See the LICENSE file at the root of this project for complete information. +// +// + +const Builder = @import("std").build.Builder; + +pub fn build(b: *mut Builder) void { + // Standard target options allows the person running `zen build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + // Standard release options allow the person running `zen build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const exe = b.addExecutable("nvim", "src/main.zen"); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.install(); + + const run_cmd = exe.run(); + b.addStepDependency(run_cmd, b.getInstallStep()); + + const run_step = b.step("run", "Run the app"); + b.addStepDependency(run_step, run_cmd); +} diff --git a/init.lua b/init.lua index c607bf05d7f..80713364ca3 100644 --- a/init.lua +++ b/init.lua @@ -8,7 +8,12 @@ require 'options.settings' local plugins = require 'plugins' -local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +-- Set leader key before lazy.nvim +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } diff --git a/lua/options/autocmds.lua b/lua/options/autocmds.lua new file mode 100644 index 00000000000..50e781340a7 --- /dev/null +++ b/lua/options/autocmds.lua @@ -0,0 +1,23 @@ +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- Auto format Go files on save +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.go", + callback = function() + vim.lsp.buf.format({ async = false }) + end, +}) + +-- Auto format Zig files on save +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.zig", + callback = function() + vim.lsp.buf.format({ async = false }) + end, +}) diff --git a/lua/options/gitsigns.lua b/lua/options/gitsigns.lua new file mode 100644 index 00000000000..4f5441c7f9a --- /dev/null +++ b/lua/options/gitsigns.lua @@ -0,0 +1,12 @@ +return { -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + }, +} diff --git a/lua/options/settings.lua b/lua/options/settings.lua new file mode 100644 index 00000000000..4ceab1eacb2 --- /dev/null +++ b/lua/options/settings.lua @@ -0,0 +1,75 @@ +-- [[ Setting options ]] +-- See `:help vim.opt` +-- NOTE: You can change these options as you wish! +-- For more options, you can see `:help option-list` + +-- Make line numbers default +vim.opt.number = true +vim.o.relativenumber = true +-- You can also add relative line numbers, to help with jumping. +-- Experiment for yourself to see if you like it! +-- vim.opt.relativenumber = true + +-- Enable mouse mode, can be useful for resizing splits for example! +vim.opt.mouse = 'a' + +-- Don't show the mode, since it's already in the status line +vim.opt.showmode = false + +-- Sync clipboard between OS and Neovim. +-- Schedule the setting after `UiEnter` because it can increase startup-time. +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + +-- Enable break indent +vim.opt.breakindent = true + +-- Save undo history +vim.opt.undofile = true + +-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Keep signcolumn on by default +vim.opt.signcolumn = 'yes' + +-- Decrease update time +vim.opt.updatetime = 250 + +-- Decrease mapped sequence wait time +vim.opt.timeoutlen = 300 + +-- Configure how new splits should be opened +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- Disable word wrap +vim.opt.wrap = false + +-- Sets how neovim will display certain whitespace characters in the editor. +-- See `:help 'list'` +-- and `:help 'listchars'` +vim.opt.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } + +-- Preview substitutions live, as you type! +vim.opt.inccommand = 'split' + +-- Show which line your cursor is on +vim.opt.cursorline = true + +-- Minimal number of screen lines to keep above and below the cursor. +vim.opt.scrolloff = 10 + +-- Disable winbar +vim.opt.winbar = "" + +-- Set diagnostic signs +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" }) diff --git a/lua/plugins/blink-cmp.lua b/lua/plugins/blink-cmp.lua new file mode 100644 index 00000000000..d1ec77a6e48 --- /dev/null +++ b/lua/plugins/blink-cmp.lua @@ -0,0 +1,12 @@ +return { + 'saghen/blink.cmp', + dependencies = 'rafamadriz/friendly-snippets', + version = '*', + opts = { + keymap = { preset = 'default' }, + appearance = { + use_nvim_cmp_as_default = true, + nerd_font_variant = 'mono', + }, + }, +} diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 00000000000..ce8af4b951b --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,56 @@ +return { + 'akinsho/bufferline.nvim', + version = "*", + dependencies = 'nvim-tree/nvim-web-devicons', + opts = { + options = { + mode = "buffers", -- set to "tabs" to only show tabpages instead + numbers = "none", + close_command = "bdelete! %d", -- can be a string | function, | false see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, | false see "Mouse actions" + indicator = { + icon = '▎', -- this should be omitted if indicator style is not 'icon' + style = 'icon', + }, + buffer_close_icon = '󰅖', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + max_name_length = 30, + max_prefix_length = 30, + truncate_names = true, + tab_size = 21, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + diagnostics_indicator = function(count, level, diagnostics_dict, context) + return "("..count..")" + end, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "left", + separator = true + } + }, + color_icons = true, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + show_duplicate_prefix = true, + persist_buffer_sort = true, + separator_style = "thin", + enforce_regular_tabs = false, + always_show_bufferline = true, + hover = { + enabled = true, + delay = 200, + reveal = {'close'} + }, + } + } +} diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua new file mode 100644 index 00000000000..5e6f59b4691 --- /dev/null +++ b/lua/plugins/coding.lua @@ -0,0 +1,252 @@ +return { + -- Go development + { + "ray-x/go.nvim", + dependencies = { -- optional packages + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + config = function() + require("go").setup({ + -- Gopls configuration + lsp_cfg = { + settings = { + gopls = { + analyses = { + unusedparams = true, + shadow = true, + }, + staticcheck = true, + gofumpt = true, + usePlaceholders = true, + hints = { + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + constantValues = true, + functionTypeParameters = true, + parameterNames = true, + rangeVariableTypes = true, + }, + }, + }, + }, + -- Format on save + gofmt = "gofumpt", + -- Import on save + goimports = true, + -- Enable linters + linter = "golangci-lint", + -- Test settings + test_runner = "go", + test_flags = {"-v"}, + -- Debug settings + dap_debug = true, + dap_debug_gui = true, + }) + + -- Run gofmt + goimports on save + local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {}) + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.go", + callback = function() + require("go.format").goimports() + end, + group = format_sync_grp, + }) + end, + event = {"CmdlineEnter"}, + ft = {"go", "gomod"}, + build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries + }, + + -- Zig development + { + "ziglang/zig.vim", + ft = "zig", + config = function() + -- Enable auto-formatting on save + vim.g.zig_fmt_autosave = 1 + end, + }, + + -- C development + { + "p00f/clangd_extensions.nvim", + dependencies = { + "neovim/nvim-lspconfig", + }, + ft = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + opts = { + inlay_hints = { + inline = false, + }, + ast = { + role_icons = { + type = "🄣", + declaration = "🄓", + expression = "🄔", + statement = ";", + specifier = "🄢", + ["template argument"] = "🆃", + }, + kind_icons = { + Compound = "🄲", + Recovery = "🅁", + TranslationUnit = "🅄", + PackExpansion = "🄿", + TemplateTypeParm = "🅃", + TemplateTemplateParm = "🅃", + TemplateParamObject = "🅃", + }, + }, + }, + }, + + -- DAP (Debug Adapter Protocol) + { + "mfussenegger/nvim-dap", + dependencies = { + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "leoluz/nvim-dap-go", -- Go debug adapter + "nvim-neotest/nvim-nio", -- Required by nvim-dap-ui + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + + -- Set up Go debugging + require("dap-go").setup() + + -- Set up Python debugging + dap.adapters.python = { + type = 'executable', + command = 'debugpy-adapter', + } + + dap.configurations.python = { + { + type = 'python', + request = 'launch', + name = "Launch file", + program = "${file}", + pythonPath = function() + -- Try to detect python path from active virtual environment + if vim.env.VIRTUAL_ENV then + return vim.env.VIRTUAL_ENV .. "/bin/python" + end + -- Return system python if no venv + return '/usr/bin/python3' + end, + }, + } + + -- Set up C debugging with codelldb + dap.adapters.codelldb = { + type = 'server', + port = "${port}", + executable = { + command = 'codelldb', + args = {"--port", "${port}"}, + } + } + + dap.configurations.c = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + }, + } + + -- Set up UI + dapui.setup({ + layouts = { + { + elements = { + { id = "scopes", size = 0.25 }, + { id = "breakpoints", size = 0.25 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.25 }, + }, + position = "left", + size = 40 + }, + { + elements = { + { id = "repl", size = 0.5 }, + { id = "console", size = 0.5 }, + }, + position = "bottom", + size = 10 + }, + }, + }) + + -- Automatically open UI + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close() + end + + -- Add keymaps + vim.keymap.set("n", "pb", dap.toggle_breakpoint, { desc = "Toggle Breakpoint" }) + vim.keymap.set("n", "pc", dap.continue, { desc = "Continue Debug" }) + vim.keymap.set("n", "pn", dap.step_over, { desc = "Step Over" }) + vim.keymap.set("n", "pi", dap.step_into, { desc = "Step Into" }) + vim.keymap.set("n", "po", dap.step_out, { desc = "Step Out" }) + vim.keymap.set("n", "pr", dap.repl.open, { desc = "Debug REPL" }) + vim.keymap.set("n", "pl", dap.run_last, { desc = "Run Last Debug" }) + vim.keymap.set("n", "px", dapui.toggle, { desc = "Toggle Debug UI" }) + + -- Profiling commands + local function profile_go() + local file = vim.fn.expand('%:p') + local cmd = string.format('go test -cpuprofile cpu.prof -memprofile mem.prof -bench . %s', file) + vim.fn.system(cmd) + vim.cmd('split term://go tool pprof -http=:8080 cpu.prof') + end + + local function profile_python() + local file = vim.fn.expand('%:p') + local cmd = string.format('py-spy record -o profile.svg -f speedscope -- python %s', file) + vim.fn.system(cmd) + vim.cmd('!xdg-open profile.svg') + end + + local function profile_c() + local file = vim.fn.expand('%:p:r') -- Get file path without extension + local cmd = string.format('perf record -g ./%s && perf report -g graph', file) + vim.cmd('split term://' .. cmd) + end + + -- Add profiling keymaps based on filetype + vim.api.nvim_create_autocmd("FileType", { + pattern = { "go", "python", "c", "cpp" }, + callback = function() + local ft = vim.bo.filetype + if ft == "go" then + vim.keymap.set("n", "mp", profile_go, { buffer = true, desc = "Profile Go code" }) + elseif ft == "python" then + vim.keymap.set("n", "mp", profile_python, { buffer = true, desc = "Profile Python code" }) + elseif ft == "c" or ft == "cpp" then + vim.keymap.set("n", "mp", profile_c, { buffer = true, desc = "Profile C/C++ code" }) + end + end, + }) + end, + }, +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 00000000000..b7b0c09eb35 --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,42 @@ +return { -- Autoformat + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'f', + function() + require('conform').format { async = true, lsp_format = 'fallback' } + end, + mode = '', + desc = '[F]ormat buffer', + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end + return { + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end, + formatters_by_ft = { + lua = { 'stylua' }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, +} diff --git a/lua/plugins/dadbod.lua b/lua/plugins/dadbod.lua new file mode 100644 index 00000000000..b99ce4c1336 --- /dev/null +++ b/lua/plugins/dadbod.lua @@ -0,0 +1,67 @@ +-- Database explorer and query runner +return { + 'tpope/vim-dadbod', + dependencies = { + 'kristijanhusak/vim-dadbod-ui', -- UI for vim-dadbod + 'kristijanhusak/vim-dadbod-completion' -- Completion for SQL + }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer', + }, + init = function() + -- Save DBUI settings + vim.g.db_ui_save_location = vim.fn.stdpath("data") .. "/db_ui" + vim.g.db_ui_use_nerd_fonts = true + vim.g.db_ui_execute_on_save = false -- Don't auto-execute queries on save + vim.g.db_ui_table_helpers = { + -- Add useful SQL snippets + mysql = { + List = 'SELECT * FROM {table} LIMIT 100', + Indexes = 'SHOW INDEXES FROM {table}', + Foreign = 'SELECT * FROM information_schema.key_column_usage WHERE referenced_table_name = {table}', + }, + postgresql = { + List = 'SELECT * FROM {table} LIMIT 100', + Indexes = 'SELECT * FROM pg_indexes WHERE tablename = {table}', + Foreign = [[ + SELECT + tc.table_schema, + tc.constraint_name, + tc.table_name, + kcu.column_name, + ccu.table_schema AS foreign_table_schema, + ccu.table_name AS foreign_table_name, + ccu.column_name AS foreign_column_name + FROM + information_schema.table_constraints AS tc + JOIN information_schema.key_column_usage AS kcu + ON tc.constraint_name = kcu.constraint_name + AND tc.table_schema = kcu.table_schema + JOIN information_schema.constraint_column_usage AS ccu + ON ccu.constraint_name = tc.constraint_name + AND ccu.table_schema = tc.table_schema + WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name={table}; + ]], + }, + } + end, + config = function() + -- Enable SQL completion in SQL files and dadbod-ui buffers + vim.api.nvim_create_autocmd('FileType', { + pattern = {'sql', 'mysql', 'plsql', 'pgsql'}, + callback = function() + -- Set up completion + require('cmp').setup.buffer({ + sources = { + { name = 'vim-dadbod-completion' }, -- Database-aware completion + { name = 'nvim_lsp' }, -- LSP completion + { name = 'buffer' }, -- Buffer words + }, + }) + end, + }) + end, +} diff --git a/lua/plugins/garbage-day.lua b/lua/plugins/garbage-day.lua new file mode 100644 index 00000000000..25134296f93 --- /dev/null +++ b/lua/plugins/garbage-day.lua @@ -0,0 +1,21 @@ +-- Garbage collector that stops inactive LSP clients to free RAM +return { + 'zeioth/garbage-day.nvim', + dependencies = 'neovim/nvim-lspconfig', + event = 'VeryLazy', + opts = { + -- Collect garbage after 10 minutes of inactivity + grace_period = 60 * 10, + -- Exclude null-ls and other special clients + excluded_lsp_clients = { 'omnisharp', 'null-ls', 'none-ls' }, + -- Show notifications when clients are stopped + notifications = true, + -- Garbage collection settings + aggressive_mode = false, -- Be gentle with GC + -- Adjust Lua's GC parameters for better performance + gc_settings = { + pause = 110, -- Lower pause for more frequent but shorter GC pauses + step_mul = 100, -- Lower step multiplier for smoother collection + }, + }, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 00000000000..64f83e075f2 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,35 @@ +return { -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup({ + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = '~' }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + }) + end, +} diff --git a/lua/plugins/gruvbox.lua b/lua/plugins/gruvbox.lua new file mode 100644 index 00000000000..40f77dd4391 --- /dev/null +++ b/lua/plugins/gruvbox.lua @@ -0,0 +1,17 @@ +return { -- You can easily change to a different colorscheme. + -- Change the name of the colorscheme plugin below, and then + -- change the command in the config to whatever the name of that colorscheme is. + -- + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. + 'ellisonleao/gruvbox.nvim', + priority = 1000, -- Make sure to load this before all the other start plugins. + init = function() + -- Load the colorscheme here. + -- Like many other themes, this one has different styles, and you could load + -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. + vim.cmd.colorscheme 'gruvbox' + + -- You can configure highlights by doing something like: + vim.cmd.hi 'Comment gui=none' + end, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 00000000000..2639278261a --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,12 @@ +local plugins = {} + +local plugin_files = vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/plugins', '*.lua', false, true) + +for _, file in ipairs(plugin_files) do + local plugin_name = file:match('.*/(.*)%.lua$') + if plugin_name ~= 'init' then + table.insert(plugins, require('plugins.' .. plugin_name)) + end +end + +return plugins diff --git a/lua/plugins/lazydev.lua b/lua/plugins/lazydev.lua new file mode 100644 index 00000000000..6d9c256b2d6 --- /dev/null +++ b/lua/plugins/lazydev.lua @@ -0,0 +1,12 @@ +return { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + }, + }, +} diff --git a/lua/plugins/leap.lua b/lua/plugins/leap.lua new file mode 100644 index 00000000000..9f8ef2c432c --- /dev/null +++ b/lua/plugins/leap.lua @@ -0,0 +1,25 @@ +-- Quick navigation plugin +return { + 'ggandor/leap.nvim', + dependencies = { + 'tpope/vim-repeat', -- For dot-repeat support + }, + config = function() + local leap = require('leap') + + -- Basic setup + leap.setup { + case_sensitive = false, + safe_labels = {}, -- Show all labels + labels = { + 'f', 'j', 'd', 'k', 's', 'l', 'h', 'g', + 'F', 'J', 'D', 'K', 'S', 'L', 'H', 'G', + }, + } + + -- Set highlight colors for better visibility + vim.api.nvim_set_hl(0, 'LeapMatch', { fg = '#89B4FA', bold = true, nocombine = true }) + vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { fg = '#F38BA8', bold = true, nocombine = true }) + vim.api.nvim_set_hl(0, 'LeapLabelSecondary', { fg = '#94E2D5', bold = true, nocombine = true }) + end, +} diff --git a/lua/plugins/luvit-meta.lua b/lua/plugins/luvit-meta.lua new file mode 100644 index 00000000000..da6ddc7315c --- /dev/null +++ b/lua/plugins/luvit-meta.lua @@ -0,0 +1 @@ +return { 'Bilal2453/luvit-meta', lazy = true } diff --git a/lua/plugins/mason-null-ls.lua b/lua/plugins/mason-null-ls.lua new file mode 100644 index 00000000000..a94e7253d3f --- /dev/null +++ b/lua/plugins/mason-null-ls.lua @@ -0,0 +1,18 @@ +return { + "jay-babu/mason-null-ls.nvim", + enabled = true, + dependencies = { + "williamboman/mason.nvim", + "nvimtools/none-ls.nvim", -- replaces null-ls + }, + config = function() + require("mason-null-ls").setup({ + ensure_installed = + { + "prettier", + "eslint" + }, + automatic_installation = true, + }) + end, +} diff --git a/lua/plugins/mini-icons.lua b/lua/plugins/mini-icons.lua new file mode 100644 index 00000000000..b6a0bdbe601 --- /dev/null +++ b/lua/plugins/mini-icons.lua @@ -0,0 +1,42 @@ +return { + 'echasnovski/mini.nvim', + version = false, + config = function() + require('mini.icons').setup({ + -- Enable all preset kinds + preset = 'default', + -- Customize icons for specific kinds + devicons = { + enabled = true, + override = { + -- File types + default = '', + lua = '', + python = '', + javascript = '', + html = '', + css = '', + json = '', + yaml = '', + toml = '', + markdown = '', + -- Git + git = '', + github = '', + gitlab = '', + gitignore = '', + -- Folders + folder = '', + folder_open = '', + folder_empty = '', + folder_empty_open = '', + -- LSP + error = '', + warning = '', + info = '', + hint = '󰌵', + }, + }, + }) + end, +} diff --git a/lua/plugins/mini-surround.lua b/lua/plugins/mini-surround.lua new file mode 100644 index 00000000000..0050bc37fb6 --- /dev/null +++ b/lua/plugins/mini-surround.lua @@ -0,0 +1,11 @@ +return { + 'echasnovski/mini.surround', + version = '*', + event = "VeryLazy", + config = function() + require('mini.surround').setup({ + -- Use mappings from centralized keymaps + mappings = require('core.keymaps').mini_surround_keymaps + }) + end, +} diff --git a/lua/plugins/mini.lua b/lua/plugins/mini.lua deleted file mode 100644 index a8b4c30ef23..00000000000 --- a/lua/plugins/mini.lua +++ /dev/null @@ -1,218 +0,0 @@ -return { -- Collection of various small independent plugins/modules - 'echasnovski/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - -- Simple and easy statusline. - -- You could remove this setup call if you don't like it, - -- and try some other statusline plugin - local statusline = require 'mini.statusline' - -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } - - -- You can configure sections in the statusline by overriding their - -- default behavior. For example, here we set the section for - -- cursor location to LINE:COLUMN - ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() - return '%2l:%-2v' - end - - -- Session management - local session = require('mini.sessions') - - -- Function to safely restore LSP state - local function safe_restore_lsp() - -- Disable semantic tokens temporarily during session load - local semantic_tokens = {} - for _, client in pairs(vim.lsp.get_active_clients()) do - semantic_tokens[client.id] = client.server_capabilities.semanticTokensProvider - client.server_capabilities.semanticTokensProvider = nil - end - - -- Return a function to restore semantic tokens - return function() - for id, tokens in pairs(semantic_tokens) do - local client = vim.lsp.get_client_by_id(id) - if client then - client.server_capabilities.semanticTokensProvider = tokens - end - end - end - end - - -- Get session name based on current directory - local function get_session_name() - local cwd = vim.fn.getcwd() - -- Replace path separators and spaces with underscores - local name = string.gsub(cwd, '[/\\%s]', '_') - return name - end - - -- Clean up buffers before saving session - local function pre_save() - -- Store current buffers - local bufs = vim.api.nvim_list_bufs() - - -- Close special buffers that we don't want to save - for _, buf in ipairs(bufs) do - if vim.api.nvim_buf_is_valid(buf) then - local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') - local filetype = vim.api.nvim_buf_get_option(buf, 'filetype') - if buftype ~= '' or filetype == 'TelescopePrompt' or filetype == 'neo-tree' then - vim.api.nvim_buf_delete(buf, { force = true }) - end - end - end - end - - -- Clean up after loading session - local function post_load() - -- Close any empty buffers that might have been created - local bufs = vim.api.nvim_list_bufs() - for _, buf in ipairs(bufs) do - if vim.api.nvim_buf_is_valid(buf) then - local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') - local filetype = vim.api.nvim_buf_get_option(buf, 'filetype') - local modified = vim.api.nvim_buf_get_option(buf, 'modified') - local name = vim.api.nvim_buf_get_name(buf) - - if not modified and (name == '' or buftype ~= '' or filetype == 'TelescopePrompt' or filetype == 'neo-tree') then - vim.api.nvim_buf_delete(buf, { force = true }) - end - end - end - end - - -- Create session functions for use in keymaps - _G.MiniSession = { - save = function() - local name = get_session_name() - local ok, err = pcall(function() session.write(name) end) - if ok then - vim.notify(string.format('Session: Successfully saved "%s"', name), - vim.log.levels.INFO) - else - vim.notify(string.format('Session: Failed to save "%s": %s', name, err), - vim.log.levels.ERROR) - end - end, - - load = function() - local name = get_session_name() - local ok, err = pcall(function() session.read(name) end) - if ok then - vim.notify(string.format('Session: Successfully loaded "%s"', name), - vim.log.levels.INFO) - else - vim.notify(string.format('Session: Failed to load "%s": %s', name, err), - vim.log.levels.ERROR) - end - end, - - delete = function() - local name = get_session_name() - local ok, err = pcall(function() session.delete(name) end) - if ok then - vim.notify(string.format('Session: Successfully deleted "%s"', name), - vim.log.levels.INFO) - else - vim.notify(string.format('Session: Failed to delete "%s": %s', name, err), - vim.log.levels.ERROR) - end - end - } - - -- Create session directory - local session_dir = vim.fn.stdpath('data') .. '/sessions' - if vim.fn.isdirectory(session_dir) == 0 then - vim.fn.mkdir(session_dir, 'p') - end - - session.setup({ - -- Directory to store session files - directory = session_dir, - -- File to use for current session - file = get_session_name(), - -- Whether to force write session file on each write operation - force_write = true, - -- Hook functions for actions - hooks = { - -- Before loading a session - pre_load = function() - -- Clean up buffers safely - for _, buf in ipairs(vim.api.nvim_list_bufs()) do - local ft = vim.api.nvim_buf_get_option(buf, 'filetype') - -- Don't close special buffers - if ft ~= 'NvimTree' and ft ~= 'neo-tree' and ft ~= 'TelescopePrompt' then - pcall(vim.api.nvim_buf_delete, buf, { force = false }) - end - end - return safe_restore_lsp() - end, - -- After loading a session - post_load = function() - post_load() - -- Restore LSP semantic tokens after a short delay - vim.defer_fn(function() - if vim.v.vim_did_enter == 1 then - for _, client in pairs(vim.lsp.get_active_clients()) do - if client.server_capabilities.semanticTokensProvider then - vim.lsp.semantic_tokens.force_refresh(client.id) - end - end - end - end, 1000) - vim.notify('Session loaded!', vim.log.levels.INFO) - end, - -- Before saving a session - pre_save = function() - vim.notify('Saving session...', vim.log.levels.INFO) - pre_save() - end, - -- After saving a session - post_save = nil, - }, - -- Whether to read latest session if Neovim opened without file arguments - autoread = false, - -- Whether to write current session before quitting Neovim - autowrite = false, -- We'll handle this ourselves - -- Whether to disable showing non-error feedback - verbose = { - read = false, -- We'll handle our own notifications - write = false, - delete = false, - }, - }) - - -- Update session name when directory changes - vim.api.nvim_create_autocmd('DirChanged', { - callback = function() - session.setup({ file = get_session_name() }) - end, - }) - - -- Auto-save session when leaving Neovim - vim.api.nvim_create_autocmd('VimLeavePre', { - callback = function() - -- Only save if we have buffers - if #vim.fn.getbufinfo({buflisted = 1}) > 0 then - _G.MiniSession.save() - end - end, - }) - end, -} diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua new file mode 100644 index 00000000000..ce2dff0636f --- /dev/null +++ b/lua/plugins/null-ls.lua @@ -0,0 +1,68 @@ +return { + 'nvimtools/none-ls.nvim', + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { + 'jay-babu/mason-null-ls.nvim', + }, + config = function() + local null_ls = require 'null-ls' + local null_ls_utils = require 'null-ls.utils' + + local formatting = null_ls.builtins.formatting + local diagnostics = null_ls.builtins.diagnostics + + null_ls.setup { + root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), + timeout = 10000, -- Reduced timeout + debounce = 250, -- Add debounce to prevent excessive updates + update_in_insert = false, -- Only update diagnostics when leaving insert mode + sources = { + -- Go formatting and linting + formatting.gofumpt.with({ + extra_args = { "-extra" }, -- More aggressive formatting + }), + formatting.goimports.with({ + args = { "-local", "", "-w", "$FILENAME" }, -- Optimize imports + }), + diagnostics.golangci_lint.with({ + diagnostics_format = '#{m}', + extra_args = { + '--fast', + '--max-issues-per-linter', '30', + '--max-same-issues', '4', + '--max-same-issues-per-linter', '0', -- Disable duplicate issue reporting per linter + '--fix=false', -- Don't try to fix issues + '--tests=false', -- Don't analyze tests for faster results + '--print-issued-lines=false', -- Don't print the lines that triggered issues + '--timeout=10s', -- Timeout after 10 seconds + '--out-format=json', -- Use JSON format for faster parsing + }, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, -- Only run on save + timeout = 10000, -- 10 second timeout + }), + + -- Web formatting + formatting.prettier.with { + filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, + extra_args = { + '--bracket-same-line', + '--trailing-comma', 'all', + '--tab-width', '2', + '--semi', + '--single-quote', + }, + }, + + -- Shell formatting + formatting.shfmt.with { + extra_args = { '-i', '2', '-ci', '-bn' }, + }, + + -- SQL formatting + formatting.sqlfluff.with { + extra_args = { '--dialect', 'tsql' }, + }, + }, + } + end, +} diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua new file mode 100644 index 00000000000..4bbf9ea8fb0 --- /dev/null +++ b/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,35 @@ +return { + 'windwp/nvim-autopairs', + event = "InsertEnter", -- Only load in insert mode + opts = { + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, + ignored_next_char = "[%w%.]", + enable_moveright = false, -- Don't move cursor after pair + enable_afterquote = false, -- Don't add pairs after quotes + enable_check_bracket_line = true, + enable_bracket_in_quote = false, + map_cr = true, + map_bs = true, + map_c_h = false, + map_c_w = false, + disable_in_macro = true, + disable_in_visualblock = true, + enable_abbr = false, + }, + config = function(_, opts) + local npairs = require('nvim-autopairs') + npairs.setup(opts) + + -- Only enable completion integration if cmp is loaded + local ok, cmp = pcall(require, 'cmp') + if ok then + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) + end + end, +} diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 00000000000..787e29e900e --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,115 @@ +return { -- Autocompletion + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + 'L3MON4D3/LuaSnip', + build = (function() + -- Build Step is needed for regex support in snippets. + -- This step is not supported in many windows environments. + -- Remove the below condition to re-enable on windows. + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + -- { + -- 'rafamadriz/friendly-snippets', + -- config = function() + -- require('luasnip.loaders.from_vscode').lazy_load() + -- end, + -- }, + }, + }, + 'saadparwaiz1/cmp_luasnip', + + -- Adds other completion capabilities. + -- nvim-cmp does not ship with all sources by default. They are split + -- into multiple repos for maintenance purposes. + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + }, + config = function() + -- See `:help cmp` + local cmp = require 'cmp' + local luasnip = require 'luasnip' + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { completeopt = 'menu,menuone,noinsert' }, + + -- For an understanding of why these mappings were + -- chosen, you will need to read `:help ins-completion` + -- + -- No, but seriously. Please read `:help ins-completion`, it is really good! + mapping = cmp.mapping.preset.insert { + -- Select the [n]ext item + [''] = cmp.mapping.select_next_item(), + -- Select the [p]revious item + [''] = cmp.mapping.select_prev_item(), + + -- Scroll the documentation window [b]ack / [f]orward + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + + -- Accept ([y]es) the completion. + -- This will auto-import if your LSP supports it. + -- This will expand snippets if the LSP sent a snippet. + [''] = cmp.mapping.confirm { select = true }, + + -- If you prefer more traditional completion keymaps, + -- you can uncomment the following lines + --[''] = cmp.mapping.confirm { select = true }, + --[''] = cmp.mapping.select_next_item(), + --[''] = cmp.mapping.select_prev_item(), + + -- Manually trigger a completion from nvim-cmp. + -- Generally you don't need this, because nvim-cmp will display + -- completions whenever it has completion options available. + [''] = cmp.mapping.complete {}, + + -- Think of as moving to the right of your snippet expansion. + -- So if you have a snippet that's like: + -- function $name($args) + -- $body + -- end + -- + -- will move you to the right of each of the expansion locations. + -- is similar, except moving you backwards. + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + + -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: + -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps + }, + sources = { + { + name = 'lazydev', + -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it + group_index = 0, + }, + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, + } + end, +} diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index d5115ff035b..fdc330c0388 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -99,8 +99,15 @@ return { lua_ls = { settings = { Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = { + [vim.fn.expand('$VIMRUNTIME/lua')] = true, + [vim.fn.stdpath('config') .. '/lua'] = true, + }, + }, }, }, }, @@ -115,37 +122,10 @@ return { }, } - -- Setup neovim lua configuration - -- require('neodev').setup({ - -- library = { - -- enabled = true, - -- runtime = true, - -- types = true, - -- plugins = true, - -- }, - -- }) - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -- Ensure the servers above are installed - local mason_lspconfig = require 'mason-lspconfig' - - mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), - } - - mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - settings = servers[server_name] and servers[server_name].settings or {}, - filetypes = servers[server_name] and servers[server_name].filetypes, - } - end, - } - -- Single LSP attach handler for all functionality vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), @@ -200,5 +180,44 @@ return { end end, }) + + -- Ensure the servers above are installed + local mason_lspconfig = require 'mason-lspconfig' + + mason_lspconfig.setup { + ensure_installed = vim.tbl_keys(servers), + } + + mason_lspconfig.setup_handlers { + function(server_name) + local server_config = servers[server_name] or {} + + -- For gopls, disable semantic tokens in capabilities + if server_name == "gopls" then + server_config.capabilities = vim.tbl_deep_extend("force", capabilities, { + textDocument = { + semanticTokens = { + dynamicRegistration = false, + formats = {}, + multilineTokenSupport = false, + overlappingTokenSupport = false, + requests = { + full = false, + range = false, + delta = false + }, + serverCancelSupport = false, + tokenModifiers = {}, + tokenTypes = {} + } + } + }) + else + server_config.capabilities = capabilities + end + + require('lspconfig')[server_name].setup(server_config) + end, + } end, } diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua new file mode 100644 index 00000000000..bea35d3aac2 --- /dev/null +++ b/lua/plugins/nvim-treesitter.lua @@ -0,0 +1,25 @@ +return { -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` + opts = { + ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + -- Autoinstall languages that are not installed + auto_install = true, + highlight = { + enable = true, + -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. + -- If you are experiencing weird indenting issues, add the language to + -- the list of additional_vim_regex_highlighting and disabled languages for indent. + additional_vim_regex_highlighting = { 'ruby' }, + }, + indent = { enable = true, disable = { 'ruby' } }, + }, + -- There are additional nvim-treesitter modules that you can use to interact + -- with nvim-treesitter. You should go explore a few and see what interests you: + -- + -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` + -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context + -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects +} diff --git a/lua/plugins/snacks.lua b/lua/plugins/snacks.lua new file mode 100644 index 00000000000..91991713609 --- /dev/null +++ b/lua/plugins/snacks.lua @@ -0,0 +1,3 @@ +-- This is the main entry point for snacks configuration +-- All actual configurations are in the snacks/ directory +return require("plugins.snacks.init") diff --git a/lua/plugins/snacks/core.lua b/lua/plugins/snacks/core.lua new file mode 100644 index 00000000000..5ba8516e87b --- /dev/null +++ b/lua/plugins/snacks/core.lua @@ -0,0 +1,34 @@ +return { + bigfile = { enabled = true }, + input = { enabled = true }, + notifier = { + enabled = true, + timeout = 3000, -- notifications auto-close after 3s + render = { + max_width = 100, + min_width = 20, + padding = 1, + format = { + default = " {message}", + notify = " {title}\n {message}", + error = " {title}\n {message}", + warn = " {title}\n {message}", + info = " {title}\n {message}", + }, + }, + }, + quickfile = { enabled = true }, + statuscolumn = { enabled = true }, + scratch = { + enabled = true, + float = { + border = "rounded", + width = 0.8, + height = 0.8, + }, + }, + bufdelete = { + enabled = true, + next = "cycle", + }, +} diff --git a/lua/plugins/snacks/dashboard.lua b/lua/plugins/snacks/dashboard.lua new file mode 100644 index 00000000000..0f328349bff --- /dev/null +++ b/lua/plugins/snacks/dashboard.lua @@ -0,0 +1,19 @@ +return { + dashboard = { + enabled = true, + preset = { + header = [[ + ███▄ █ ▓█████ ▒█████ ██▒ █▓ ██▓ ███▄ ▄███▓ + ██ ▀█ █ ▓█ ▀ ▒██▒ ██▒▓██░ █▒▓██▒▓██▒▀█▀ ██▒ +▓██ ▀█ ██▒▒███ ▒██░ ██▒ ▓██ █▒░▒██▒▓██ ▓██░ +▓██▒ ▐▌██▒▒▓█ ▄ ▒██ ██░ ▒██ █░░░██░▒██ ▒██ +▒██░ ▓██░░▒████▒░ ████▓▒░ ▒▀█░ ░██░▒██▒ ░██▒ +░ ▒░ ▒ ▒ ░░ ▒░ ░░ ▒░▒░▒░ ░ ▐░ ░▓ ░ ▒░ ░ ░ +░ ░░ ░ ▒░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ▒ ░░ ░ ░ + ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ▒ ░░ ░ + ░ ░ ░ ░ ░ ░ ░ ░ + ░ +]], + }, + }, +} diff --git a/lua/plugins/snacks/display.lua b/lua/plugins/snacks/display.lua new file mode 100644 index 00000000000..b2b09560415 --- /dev/null +++ b/lua/plugins/snacks/display.lua @@ -0,0 +1,15 @@ +return { + display = { + enabled = true, + indent = { enabled = true }, + references = { enabled = true }, + scope = { enabled = true }, + dim = { enabled = true }, + }, + notifier = { + enabled = true, + timeout = 5000, + max_width = 100, + max_height = 10, + }, +} diff --git a/lua/plugins/snacks/git.lua b/lua/plugins/snacks/git.lua new file mode 100644 index 00000000000..61d01a6f398 --- /dev/null +++ b/lua/plugins/snacks/git.lua @@ -0,0 +1,16 @@ +return { + git = { enabled = true }, + gitbrowse = { + enabled = true, + notify = true, + what = "commit", + }, + lazygit = { + enabled = true, + float = { + border = "rounded", + width = 0.9, + height = 0.9, + }, + }, +} diff --git a/lua/plugins/snacks/init.lua b/lua/plugins/snacks/init.lua new file mode 100644 index 00000000000..366e159b672 --- /dev/null +++ b/lua/plugins/snacks/init.lua @@ -0,0 +1,49 @@ +-- Import all configurations +local core = require("plugins.snacks.core") +local display = require("plugins.snacks.display") +local git = require("plugins.snacks.git") +local terminal = require("plugins.snacks.terminal") +local dashboard = require("plugins.snacks.dashboard") +local picker = require("plugins.snacks.picker") + +-- Merge all configurations +local function merge_tables(...) + local result = {} + for _, t in ipairs({...}) do + for k, v in pairs(t) do + result[k] = v + end + end + return result +end + +-- Return the plugin spec +return { + 'folke/snacks.nvim', + priority = 1000, + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", -- optional, for file icons + "MunifTanjim/nui.nvim", + "echasnovski/mini.nvim", + }, + ---@type snacks.Config + opts = merge_tables( + core, + display, + git, + terminal, + dashboard, + picker + ), + config = function(_, opts) + -- Initialize snacks with merged options + require("snacks").setup(opts) + + -- Note: Keymaps are handled in core/keymaps.lua + end, + init = function() + -- Make snacks available globally for debugging + _G.Snacks = require("plugins.snacks") + end, +} diff --git a/lua/plugins/snacks/picker.lua b/lua/plugins/snacks/picker.lua new file mode 100644 index 00000000000..017da9aa847 --- /dev/null +++ b/lua/plugins/snacks/picker.lua @@ -0,0 +1,24 @@ +return { + picker = { + sources = { + explorer = { + tree = true, + watch = true, + diagnostics = true, + diagnostics_open = false, + git_status = true, + git_status_open = false, + git_untracked = true, + follow_file = true, + focus = "list", + auto_close = false, + jump = { close = false }, + formatters = { + file = { filename_only = true }, + severity = { pos = "right" }, + }, + matcher = { sort_empty = false, fuzzy = false }, + } + } + }, +} diff --git a/lua/plugins/snacks/terminal.lua b/lua/plugins/snacks/terminal.lua new file mode 100644 index 00000000000..3a10808dc1c --- /dev/null +++ b/lua/plugins/snacks/terminal.lua @@ -0,0 +1,10 @@ +return { + terminal = { + enabled = true, + float = { + border = "rounded", + width = 0.8, + height = 0.8, + }, + }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 00000000000..dcbe783e950 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,121 @@ +return { -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + event = 'VimEnter', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for installation instructions + 'nvim-telescope/telescope-fzf-native.nvim', + + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', + + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires a Nerd Font. + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + }, + config = function() + -- Telescope is a fuzzy finder that comes with a lot of different things that + -- it can fuzzy find! It's more than just a "file finder", it can search + -- many different aspects of Neovim, your workspace, LSP, and more! + -- + -- The easiest way to use Telescope, is to start by doing something like: + -- :Telescope help_tags + -- + -- After running this command, a window will open up and you're able to + -- type in the prompt window. You'll see a list of `help_tags` options and + -- a corresponding preview of the help. + -- + -- Two important keymaps to use while in Telescope are: + -- - Insert mode: + -- - Normal mode: ? + -- + -- This opens a window that shows you all of the keymaps for the current + -- Telescope picker. This is really useful to discover what Telescope can + -- do as well as how to actually do it! + + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = 'which_key', -- Show help in insert mode + }, + n = { + ['?'] = 'which_key', -- Show help in normal mode + }, + }, + }, + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, + } + + -- Enable Telescope extensions if they are installed + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- Apply Telescope keymaps from our centralized keymaps file + local keymaps = require('core.keymaps').telescope_keymaps + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- See `:help telescope.builtin` + local builtin = require 'telescope.builtin' + + -- LSP mappings + vim.keymap.set('n', 'gr', builtin.lsp_references, { desc = 'LSP: [G]oto [R]eferences' }) + vim.keymap.set('n', 'gd', builtin.lsp_definitions, { desc = 'LSP: [G]oto [D]efinition' }) + vim.keymap.set('n', 'gI', builtin.lsp_implementations, { desc = 'LSP: [G]oto [I]mplementation' }) + + -- Regular Telescope mappings + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + + -- Document diagnostics + vim.keymap.set('n', 'dx', builtin.diagnostics, { desc = '[D]ocument Diagnostic[x]' }) + + -- Slightly advanced example of overriding default behavior and theme + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to Telescope to change the theme, layout, etc. + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + + -- It's also possible to pass additional configuration options. + -- See `:help telescope.builtin.live_grep()` for information about particular keys + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) + + -- Shortcut for searching your Neovim configuration files + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) + end, +} diff --git a/lua/plugins/todo-comments.lua b/lua/plugins/todo-comments.lua new file mode 100644 index 00000000000..c11461df8e1 --- /dev/null +++ b/lua/plugins/todo-comments.lua @@ -0,0 +1,9 @@ +return { + 'folke/todo-comments.nvim', + event = 'VimEnter', + dependencies = { 'nvim-lua/plenary.nvim' }, + opts = { + signs = false, + -- Keymaps are handled in core/keymaps.lua + } +} diff --git a/lua/plugins/vim-sleuth.lua b/lua/plugins/vim-sleuth.lua new file mode 100644 index 00000000000..ad6149e845a --- /dev/null +++ b/lua/plugins/vim-sleuth.lua @@ -0,0 +1 @@ +return { 'tpope/vim-sleuth' } diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 00000000000..14b874b57cf --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,108 @@ +return { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + opts = { + delay = 0, + icons = { + mappings = vim.g.have_nerd_font, + keys = vim.g.have_nerd_font and {} or { + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', + }, + }, + + -- Document existing key chains + spec = { + { 'c', group = '[C]ode', desc = { + a = 'Code [A]ction', + f = '[F]ormat buffer', + }}, + { 'd', group = '[D]ocument', desc = { + x = 'Document [D]iagnostics', + s = 'Document [S]ymbols', + [''] = 'Show diagnostic under cursor', + }}, + { 's', group = '[S]earch', desc = { + h = '[H]elp', + k = '[K]eymaps', + f = '[F]iles', + s = '[S]elect Telescope', + w = 'Current [W]ord', + g = '[G]rep', + d = '[D]iagnostics', + r = '[R]esume last search', + ['.'] = 'Recent files', + ['/'] = 'Search in open files', + n = '[N]eovim config files', + }}, + { 'w', group = '[W]orkspace', desc = { + s = '[S]ymbols', + }}, + { 't', group = '[T]oggle', desc = { + h = 'Toggle inlay [H]ints', + }}, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'g', group = '[G]it', desc = { + s = 'Status', + }}, + { 'f', group = '[F]ile Explorer', desc = { + e = 'Toggle explorer', + f = 'Focus explorer', + }}, + { 'n', group = '[N]otifications', desc = { + n = 'Toggle notifications', + h = 'Notification [H]istory', + c = '[C]lear notifications', + }}, + { 'p', group = 'Debug/[P]rofile', desc = { + b = 'Toggle [B]reakpoint', + c = '[C]ontinue debugging', + n = 'Step over ([N]ext)', + i = 'Step [I]nto', + o = 'Step [O]ut', + r = 'Open [R]EPL', + l = 'Run [L]ast debug session', + x = 'Toggle debug UI', + }}, + { 'b', group = '[B]uffer', desc = { + p = '[P]revious', + n = '[N]ext', + d = '[D]elete', + D = 'Force [D]elete', + }}, + { 'q', desc = 'Open diagnostic [Q]uickfix list' }, + { 'e', desc = 'Toggle file [E]xplorer' }, + { 'o', desc = 'F[o]cus file explorer' }, + { 'x', desc = 'Close buffer' }, + { 'X', desc = 'Force close buffer' }, + { '/', desc = 'Search in current buffer' }, + { '', desc = 'Find buffers' }, + }, + }, +} diff --git a/src/main.zen b/src/main.zen new file mode 100644 index 00000000000..066a492c414 --- /dev/null +++ b/src/main.zen @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() anyerror!void { + std.debug.warn("Congratulations on your first step to writing perfect software in Zen.\n", .{}); +} From e64044b066a85e7e5d09bd07b5dc9c91d95b3abc Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 18:11:00 +0100 Subject: [PATCH 09/16] cleanup: remove session-related keymaps --- lua/plugins/which-key.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 14b874b57cf..8bede533a0c 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -57,7 +57,6 @@ return { -- Useful plugin to show you pending keybinds. g = '[G]rep', d = '[D]iagnostics', r = '[R]esume last search', - ['.'] = 'Recent files', ['/'] = 'Search in open files', n = '[N]eovim config files', }}, From 80e90a3b994b39e25d0cde43f88463c41c447081 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 23 Feb 2025 19:44:06 +0100 Subject: [PATCH 10/16] fix(gopls): disable semantic tokens and restore mini.sessions - Disable semantic tokens in gopls to prevent nil index errors - Replace auto-session with mini.sessions for better reliability - Move session keymaps to core/keymaps.lua under m namespace - Add Go project detection to skip session operations for Go projects --- lua/core/keymaps.lua | 14 ++++--- lua/plugins/nvim-lspconfig.lua | 76 ++++++++++++++++++++++++---------- lua/plugins/session.lua | 53 ++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 lua/plugins/session.lua diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 0c3514d21db..7e743dd518d 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -129,12 +129,9 @@ M.dadbod_keymaps = { -- Session management keymaps (all under m for Memory) M.session_keymaps = { - { mode = 'n', lhs = 'ms', rhs = function() _G.MiniSession.save() end, - opts = { desc = 'Memory: Save session' } }, - { mode = 'n', lhs = 'ml', rhs = function() _G.MiniSession.load() end, - opts = { desc = 'Memory: Load session' } }, - { mode = 'n', lhs = 'md', rhs = function() _G.MiniSession.delete() end, - opts = { desc = 'Memory: Delete session' } }, + { mode = 'n', lhs = 'mw', rhs = function() require('mini.sessions').write() end, opts = { desc = 'Memory: Write session' } }, + { mode = 'n', lhs = 'mr', rhs = function() require('mini.sessions').read() end, opts = { desc = 'Memory: Read session' } }, + { mode = 'n', lhs = 'md', rhs = function() require('mini.sessions').delete() end, opts = { desc = 'Memory: Delete session' } }, } -- Setup function for dadbod keymaps @@ -294,6 +291,11 @@ local function init_keymaps() -- Set up session keymaps M.setup_session_keymaps() + -- Set up session keymaps + for _, mapping in ipairs(M.session_keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + -- Set up git signs keymaps M.setup_gitsigns_keymaps() diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index fdc330c0388..8f367092170 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -137,6 +137,11 @@ return { local client = vim.lsp.get_client_by_id(args.data.client_id) if not client then return end + -- Disable semantic tokens for gopls + if client.name == "gopls" then + client.server_capabilities.semanticTokensProvider = nil + end + -- Only set up document formatting for null-ls if client.name ~= "null-ls" then client.server_capabilities.documentFormattingProvider = false @@ -188,36 +193,65 @@ return { ensure_installed = vim.tbl_keys(servers), } + -- Custom semantic tokens handler for gopls + local semantic_tokens_handler = function(err, result, ctx, config) + local client = vim.lsp.get_client_by_id(ctx.client_id) + if not client then return end + + -- Check if client has the required semantic tokens capabilities + local semantic_tokens = client.server_capabilities.semanticTokensProvider + if not semantic_tokens or not semantic_tokens.legend then + -- If no legend is provided, disable semantic tokens for this client + client.server_capabilities.semanticTokensProvider = nil + return + end + + -- If we have a valid legend, proceed with default handler + vim.lsp.semantic_tokens.on_full(err, result, ctx, config) + end + mason_lspconfig.setup_handlers { function(server_name) local server_config = servers[server_name] or {} - -- For gopls, disable semantic tokens in capabilities + -- For gopls, add debug logging if server_name == "gopls" then - server_config.capabilities = vim.tbl_deep_extend("force", capabilities, { - textDocument = { - semanticTokens = { - dynamicRegistration = false, - formats = {}, - multilineTokenSupport = false, - overlappingTokenSupport = false, - requests = { - full = false, - range = false, - delta = false - }, - serverCancelSupport = false, - tokenModifiers = {}, - tokenTypes = {} - } - } - }) - else - server_config.capabilities = capabilities + -- Create a custom on_attach that disables semantic tokens + local orig_on_attach = server_config.on_attach + server_config.on_attach = function(client, bufnr) + -- Disable semantic tokens for this client + client.server_capabilities.semanticTokensProvider = nil + -- Call original on_attach if it exists + if orig_on_attach then + orig_on_attach(client, bufnr) + end + end end + server_config.capabilities = capabilities require('lspconfig')[server_name].setup(server_config) end, } + + -- Override the semantic tokens handler to be more resilient + vim.lsp.handlers['textDocument/semanticTokens/full'] = function(err, result, ctx, config) + -- If there's an error or no result, just return + if err or not result then return end + + local client = vim.lsp.get_client_by_id(ctx.client_id) + if not client then return end + + local bufnr = ctx.bufnr + if not bufnr then return end + + -- Get the highlighter safely + local highlighter = vim.lsp.semantic_tokens.create_highlighter(bufnr, client) + if not highlighter then return end + + -- Process the response safely + pcall(function() + highlighter:process_response(result, client, ctx.request.version) + end) + end end, } diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua new file mode 100644 index 00000000000..34b9f1e4020 --- /dev/null +++ b/lua/plugins/session.lua @@ -0,0 +1,53 @@ +return { + 'echasnovski/mini.sessions', + version = '*', + event = "VimEnter", + config = function() + require('mini.sessions').setup({ + -- Whether to read latest session if Neovim opened without file arguments + autoread = false, + -- Whether to write current session before quitting Neovim + autowrite = true, + -- Directory where global sessions are stored (use `''` to disable) + directory = vim.fn.stdpath('data') .. '/sessions', + -- File for local session (use `''` to disable) + file = '', + -- Whether to force possibly harmful actions (meaning depends on function) + force = { read = false, write = true, delete = false }, + -- Hook functions for actions. Default `nil` means 'do nothing'. + hooks = { + -- Before successful action + pre = { + read = function() + -- Skip session operations for Go projects + local current_dir = vim.fn.getcwd() + local has_go_files = vim.fn.glob(current_dir .. "/*.go") ~= "" or + vim.fn.glob(current_dir .. "/go.mod") ~= "" or + vim.fn.glob(current_dir .. "/go.work") ~= "" + + if has_go_files then + return false -- Skip for Go projects + end + return true + end, + write = function() + -- Skip session operations for Go projects + local current_dir = vim.fn.getcwd() + local has_go_files = vim.fn.glob(current_dir .. "/*.go") ~= "" or + vim.fn.glob(current_dir .. "/go.mod") ~= "" or + vim.fn.glob(current_dir .. "/go.work") ~= "" + + if has_go_files then + return false -- Skip for Go projects + end + return true + end, + }, + -- After successful action + post = { read = nil, write = nil, delete = nil }, + }, + -- Whether to print session path after action + verbose = { read = false, write = true, delete = true }, + }) + end +} From 6f352e7c113f903565bc566ffe07a4b42bfef666 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sun, 27 Apr 2025 13:22:07 +0200 Subject: [PATCH 11/16] made some mods everywhere --- _home_adam_.config_nvim | 62 ----- build.zen | 44 ---- init.lua | 29 +-- lua/core/keymaps.lua | 175 ++++++++++--- lua/options/autocmds.lua | 50 ++-- lua/options/settings.lua | 46 +++- lua/plugins/bufferline.lua | 55 +--- lua/plugins/bufferline/setup.lua | 61 +++++ lua/plugins/cmp/setup.lua | 62 +++++ lua/plugins/coding.lua | 255 +------------------ lua/plugins/coding/clangd.lua | 28 ++ lua/plugins/coding/dap.lua | 136 ++++++++++ lua/plugins/coding/go.lua | 24 ++ lua/plugins/coding/zig.lua | 9 + lua/plugins/{gruvbox.lua => colorscheme.lua} | 0 lua/plugins/commentary.lua | 6 + lua/plugins/conform.lua | 7 +- lua/plugins/garbage-day.lua | 4 +- lua/plugins/gitsigns/setup.lua | 28 ++ lua/plugins/indent-blankline.lua | 8 + lua/plugins/lsp/servers.lua | 69 +++++ lua/plugins/lsp/setup.lua | 68 +++++ lua/plugins/lualine.lua | 73 ++++++ lua/plugins/lualine/setup.lua | 72 ++++++ lua/plugins/null-ls.lua | 60 +---- lua/plugins/null-ls/setup.lua | 51 ++++ lua/plugins/nvim-autopairs.lua | 33 +-- lua/plugins/nvim-autopairs/setup.lua | 36 +++ lua/plugins/nvim-cmp.lua | 78 +----- lua/plugins/nvim-lspconfig.lua | 247 ++---------------- lua/plugins/nvim-treesitter.lua | 4 +- lua/plugins/session.lua | 20 +- lua/plugins/snacks/picker.lua | 3 + lua/plugins/snacks/terminal.lua | 4 + lua/plugins/telescope.lua | 96 +------ lua/plugins/telescope/setup.lua | 45 ++++ lua/plugins/which-key.lua | 161 +++++------- lua/plugins/work/gopls_flags.txt | 1 + src/main.zen | 5 - 39 files changed, 1145 insertions(+), 1070 deletions(-) delete mode 100644 _home_adam_.config_nvim delete mode 100644 build.zen create mode 100644 lua/plugins/bufferline/setup.lua create mode 100644 lua/plugins/cmp/setup.lua create mode 100644 lua/plugins/coding/clangd.lua create mode 100644 lua/plugins/coding/dap.lua create mode 100644 lua/plugins/coding/go.lua create mode 100644 lua/plugins/coding/zig.lua rename lua/plugins/{gruvbox.lua => colorscheme.lua} (100%) create mode 100644 lua/plugins/commentary.lua create mode 100644 lua/plugins/gitsigns/setup.lua create mode 100644 lua/plugins/indent-blankline.lua create mode 100644 lua/plugins/lsp/servers.lua create mode 100644 lua/plugins/lsp/setup.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/lualine/setup.lua create mode 100644 lua/plugins/null-ls/setup.lua create mode 100644 lua/plugins/nvim-autopairs/setup.lua create mode 100644 lua/plugins/telescope/setup.lua create mode 100644 lua/plugins/work/gopls_flags.txt delete mode 100644 src/main.zen diff --git a/_home_adam_.config_nvim b/_home_adam_.config_nvim deleted file mode 100644 index 27c99652093..00000000000 --- a/_home_adam_.config_nvim +++ /dev/null @@ -1,62 +0,0 @@ -let SessionLoad = 1 -let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1 -let v:this_session=expand(":p") -silent only -silent tabonly -cd ~/.config/nvim -if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == '' - let s:wipebuf = bufnr('%') -endif -let s:shortmess_save = &shortmess -if &shortmess =~ 'A' - set shortmess=aoOA -else - set shortmess=aoO -endif -badd +1 ~/.config/nvim/lua/core/keymaps.lua -argglobal -%argdel -edit ~/.config/nvim/lua/core/keymaps.lua -wincmd t -let s:save_winminheight = &winminheight -let s:save_winminwidth = &winminwidth -set winminheight=0 -set winheight=1 -set winminwidth=0 -set winwidth=1 -argglobal -setlocal fdm=manual -setlocal fde=0 -setlocal fmr={{{,}}} -setlocal fdi=# -setlocal fdl=0 -setlocal fml=1 -setlocal fdn=20 -setlocal fen -silent! normal! zE -let &fdl = &fdl -let s:l = 1 - ((0 * winheight(0) + 17) / 35) -if s:l < 1 | let s:l = 1 | endif -keepjumps exe s:l -normal! zt -keepjumps 1 -normal! 0 -tabnext 1 -if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal' - silent exe 'bwipe ' . s:wipebuf -endif -unlet! s:wipebuf -set winheight=1 winwidth=20 -let &shortmess = s:shortmess_save -let &winminheight = s:save_winminheight -let &winminwidth = s:save_winminwidth -let s:sx = expand(":p:r")."x.vim" -if filereadable(s:sx) - exe "source " . fnameescape(s:sx) -endif -let &g:so = s:so_save | let &g:siso = s:siso_save -set hlsearch -nohlsearch -doautoall SessionLoadPost -unlet SessionLoad -" vim: set ft=vim : diff --git a/build.zen b/build.zen deleted file mode 100644 index 97511545713..00000000000 --- a/build.zen +++ /dev/null @@ -1,44 +0,0 @@ -// -// The Zen Programming Language(tm) -// Copyright (c) 2018-2020 kristopher tate & connectFree Corporation. -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// -// This project may be licensed under the terms of the ConnectFree Reference -// Source License (CF-RSL). Corporate and Academic licensing terms are also -// available. Please contact for details. -// -// Zen, the Zen three-circles logo and The Zen Programming Language are -// trademarks of connectFree Corporation in Japan and other countries. -// -// connectFree and the connectFree logo are registered trademarks -// of connectFree Corporation in Japan and other countries. connectFree -// trademarks and branding may not be used without express written permission -// of connectFree. Please remove all trademarks and branding before use. -// -// See the LICENSE file at the root of this project for complete information. -// -// - -const Builder = @import("std").build.Builder; - -pub fn build(b: *mut Builder) void { - // Standard target options allows the person running `zen build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. - const target = b.standardTargetOptions(.{}); - // Standard release options allow the person running `zen build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); - - const exe = b.addExecutable("nvim", "src/main.zen"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.install(); - - const run_cmd = exe.run(); - b.addStepDependency(run_cmd, b.getInstallStep()); - - const run_step = b.step("run", "Run the app"); - b.addStepDependency(run_step, run_cmd); -} diff --git a/init.lua b/init.lua index 80713364ca3..8395961dc41 100644 --- a/init.lua +++ b/init.lua @@ -1,17 +1,14 @@ +---@diagnostic disable: undefined-global local config_path = vim.fn.stdpath 'config' -package.path = config_path .. '/?.lua;' .. config_path .. '/?/init.lua;' .. package.path +local lua_path = config_path .. '/lua' +package.path = lua_path .. '/?.lua;' .. lua_path .. '/?/init.lua;' .. config_path .. '/?.lua;' .. config_path .. '/?/init.lua;' .. package.path -require 'core.keymaps' -require 'options.autocmds' -require 'options.settings' --- require 'plugins.init' +require('core.keymaps').setup() +require('options.autocmds').setup() +require('options.settings').setup() local plugins = require 'plugins' --- Set leader key before lazy.nvim -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then @@ -45,19 +42,5 @@ require('lazy').setup({ plugins }, { }, }) --- Set up swap file directory to be in a central location -vim.opt.directory = vim.fn.stdpath('data') .. '/swapfiles/' - --- Create the swap directory if it doesn't exist -local swap_dir = vim.fn.stdpath('data') .. '/swapfiles' -if vim.fn.isdirectory(swap_dir) == 0 then - vim.fn.mkdir(swap_dir, 'p') -end - --- Configure swap file behavior -vim.opt.swapfile = true -- Keep swap files for recovery -vim.opt.updatetime = 300 -- Save swap file after 300ms of inactivity -vim.opt.updatecount = 100 -- Write to swap file after 100 characters - -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 7e743dd518d..b87c973ecde 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -5,12 +5,17 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Core Neovim keymaps (non-plugin) +-- These are basic Neovim operations like: +-- - Window navigation (Ctrl + hjkl) +-- - Window resizing (Ctrl + Arrow keys) +-- - Line/selection movement (Alt + jk) +-- - Quick save and quit (w, W, Q) local core_keymaps = { -- Clear highlights on search when pressing in normal mode { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, -- Exit terminal mode with a more discoverable shortcut - { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, + { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, -- Window navigation (Ctrl + hjkl) { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window left' } }, @@ -37,6 +42,23 @@ local core_keymaps = { } -- LSP keymaps - these will be set up when LSP attaches to a buffer +-- Navigation: +-- - gd: Go to definition +-- - gr: Find references +-- - gI: Go to implementation +-- - gy: Go to type definition +-- +-- Workspace: +-- - ls: Document symbols +-- - lS: Workspace symbols +-- +-- Code Actions: +-- - lr: Rename symbol +-- - la: Code action +-- - lf: Format code +-- +-- Documentation: +-- - K: Show documentation local M = {} function M.setup_lsp_keymaps(bufnr) local keymaps = { @@ -78,6 +100,23 @@ function M.setup_lsp_keymaps(bufnr) end -- Telescope keymaps (all under s for Search) +-- Help: +-- - sh: Search help tags +-- - sk: Search keymaps +-- +-- Files: +-- - sf: Find files +-- - sr: Recent files +-- +-- Text Search: +-- - sg: Live grep in workspace +-- - sw: Search word under cursor +-- - /: Fuzzy find in current buffer +-- - s/: Live grep in open files +-- +-- Workspace: +-- - sd: Search diagnostics +-- - sb: Search buffers M.telescope_keymaps = { -- Help { mode = 'n', lhs = 'sh', rhs = function() require('telescope.builtin').help_tags() end, opts = { desc = 'Search: Help' } }, @@ -108,18 +147,30 @@ M.telescope_keymaps = { { mode = 'n', lhs = 'sb', rhs = function() require('telescope.builtin').buffers() end, opts = { desc = 'Search: Buffers' } }, } --- Diagnostic keymaps (navigation with [d and ]d, details with t for trouble) +-- Diagnostic keymaps +-- Navigation: +-- - [d: Previous diagnostic +-- - ]d: Next diagnostic +-- +-- Viewing: +-- - tt: Show diagnostic details in float +-- - tl: Show diagnostics in location list M.diagnostic_keymaps = { -- Navigation { mode = 'n', lhs = '[d', rhs = vim.diagnostic.goto_prev, opts = { desc = 'Diagnostic: Previous' } }, { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, - -- Viewing diagnostics (using t for Trouble) - { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Trouble: Show details' } }, - { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Trouble: Show list' } }, + -- Viewing diagnostics + { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details' } }, + { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Diagnostic: Show list' } }, } --- Database keymaps (all under D for Database, to avoid conflicts with diagnostics) +-- Database keymaps (all under D for Database) +-- UI: +-- - Dt: Toggle database UI +-- - Df: Find database buffer +-- - Dr: Rename database buffer +-- - Dl: Show last query info M.dadbod_keymaps = { { mode = 'n', lhs = 'Dt', rhs = 'DBUIToggle', opts = { desc = 'Database: Toggle UI' } }, { mode = 'n', lhs = 'Df', rhs = 'DBUIFindBuffer', opts = { desc = 'Database: Find buffer' } }, @@ -128,29 +179,30 @@ M.dadbod_keymaps = { } -- Session management keymaps (all under m for Memory) +-- Session Operations: +-- - mw: Write/save current session +-- - mr: Read/restore saved session +-- - md: Delete saved session M.session_keymaps = { - { mode = 'n', lhs = 'mw', rhs = function() require('mini.sessions').write() end, opts = { desc = 'Memory: Write session' } }, - { mode = 'n', lhs = 'mr', rhs = function() require('mini.sessions').read() end, opts = { desc = 'Memory: Read session' } }, - { mode = 'n', lhs = 'md', rhs = function() require('mini.sessions').delete() end, opts = { desc = 'Memory: Delete session' } }, + { mode = 'n', lhs = 'mw', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').write(name, { force = true }) + end, opts = { desc = 'Memory: Write session' } }, + { mode = 'n', lhs = 'mr', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').read(name) + end, opts = { desc = 'Memory: Read session' } }, + { mode = 'n', lhs = 'md', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').delete(name) + end, opts = { desc = 'Memory: Delete session' } }, } --- Setup function for dadbod keymaps -function M.setup_dadbod_keymaps() - for _, mapping in ipairs(M.dadbod_keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - --- Setup function for session keymaps -function M.setup_session_keymaps() - -- Session keymaps will be overridden by mini.lua - local keymaps = M.session_keymaps or {} - for _, mapping in ipairs(keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - -- Scratch buffer keymaps +-- Buffer Operations: +-- - .: Toggle scratch buffer +-- - S: Select scratch buffer +-- - nh: Show notification history M.scratch_keymaps = { { mode = 'n', lhs = '.', rhs = function() require("snacks").scratch() end, opts = { desc = 'Toggle scratch buffer' } }, @@ -160,7 +212,38 @@ M.scratch_keymaps = { opts = { desc = 'Show notification history' } }, } +-- Snacks keymaps (explorer and other features) +-- File Explorer: +-- - e: Toggle explorer +-- - E: Focus current file in explorer +-- - o: Alternative key to focus current file +-- +-- Terminal: +-- - : Toggle terminal in float window +M.snacks_keymaps = { + -- Explorer + { mode = 'n', lhs = 'e', rhs = function() require('snacks.picker').explorer() end, opts = { desc = 'Explorer: Toggle' } }, + { mode = 'n', lhs = 'E', rhs = function() require('snacks.picker').explorer({ reveal = true }) end, opts = { desc = 'Explorer: Focus current file' } }, + { mode = 'n', lhs = 'o', rhs = function() require('snacks.picker').explorer({ reveal = true }) end, opts = { desc = 'Explorer: Focus current file' } }, + + -- Terminal + { mode = 'n', lhs = '', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle float window' } }, +} + -- Git signs keymaps (all under g for Git) +-- Navigation: +-- - ]c: Next hunk +-- - [c: Previous hunk +-- +-- Actions: +-- - gh: Preview hunk +-- - gs: Stage hunk +-- - gu: Undo stage hunk +-- - gr: Reset hunk +-- - gS: Stage buffer +-- - gR: Reset buffer +-- - gb: Blame line +-- - gd: Diff this M.gitsigns_keymaps = { -- Navigation { mode = 'n', lhs = ']c', rhs = function() @@ -194,6 +277,8 @@ function M.setup_gitsigns_keymaps() end -- Leap keymaps +-- 's' for bidirectional search (both forward and backward) +-- 'S' for searching in all windows M.leap_keymaps = { -- 's' for bidirectional search (both forward and backward) { mode = { 'n', 'x', 'o' }, lhs = 's', rhs = function() require('leap').leap {} end, @@ -215,11 +300,43 @@ function M.setup_leap_keymaps() end end +-- Setup functions for keymaps +function M.setup_dadbod_keymaps() + local keymaps = M.dadbod_keymaps or {} + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_session_keymaps() + local keymaps = M.session_keymaps or {} + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + -- Initialize keymaps local function init_keymaps() -- Create an autocmd group for our keymaps local keymap_group = vim.api.nvim_create_augroup('custom_keymaps', { clear = true }) + -- Handle snacks explorer during buffer writes + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = keymap_group, + callback = function() + -- Pause snacks explorer updates during write + pcall(function() + local picker = require('snacks.picker') + if picker.is_open() then + picker.pause_updates() + vim.schedule(function() + picker.resume_updates() + end) + end + end) + end, + }) + -- Function to set up snacks explorer keymaps local function setup_explorer_keymaps() -- First remove any existing mappings @@ -291,11 +408,6 @@ local function init_keymaps() -- Set up session keymaps M.setup_session_keymaps() - -- Set up session keymaps - for _, mapping in ipairs(M.session_keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - -- Set up git signs keymaps M.setup_gitsigns_keymaps() @@ -306,5 +418,8 @@ end -- Initialize all keymaps init_keymaps() +-- Export `init_keymaps` as `M.setup` so `require('core.keymaps').setup()` works +M.setup = init_keymaps + -- Return the module return M diff --git a/lua/options/autocmds.lua b/lua/options/autocmds.lua index 50e781340a7..88b873369f2 100644 --- a/lua/options/autocmds.lua +++ b/lua/options/autocmds.lua @@ -1,23 +1,31 @@ -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) +---@diagnostic disable: undefined-global +local M = {} --- Auto format Go files on save -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*.go", - callback = function() - vim.lsp.buf.format({ async = false }) - end, -}) +function M.setup() + -- Highlight when yanking (copying) text + vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, + }) --- Auto format Zig files on save -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*.zig", - callback = function() - vim.lsp.buf.format({ async = false }) - end, -}) + -- Auto format Go files on save + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + vim.lsp.buf.format({ async = false }) + end, + }) + + -- Auto format Zig files on save + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.zig', + callback = function() + vim.lsp.buf.format({ async = false }) + end, + }) +end + +return M diff --git a/lua/options/settings.lua b/lua/options/settings.lua index 4ceab1eacb2..b7fa2948fa7 100644 --- a/lua/options/settings.lua +++ b/lua/options/settings.lua @@ -3,6 +3,7 @@ -- NOTE: You can change these options as you wish! -- For more options, you can see `:help option-list` +---@diagnostic disable: undefined-global -- Make line numbers default vim.opt.number = true vim.o.relativenumber = true @@ -54,7 +55,9 @@ vim.opt.wrap = false -- See `:help 'list'` -- and `:help 'listchars'` vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +-- Do not set 'tab' in listchars so ibl can show its own indent guides +-- Use a vertical bar for tabs so ibl and listchars both show vertical guides +vim.opt.listchars = { tab = '│ ', trail = '·', nbsp = '␣' } -- Preview substitutions live, as you type! vim.opt.inccommand = 'split' @@ -69,7 +72,40 @@ vim.opt.scrolloff = 10 vim.opt.winbar = "" -- Set diagnostic signs -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" }) +vim.diagnostic.config({ + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "", + [vim.diagnostic.severity.WARN] = "", + [vim.diagnostic.severity.INFO] = "", + [vim.diagnostic.severity.HINT] = "󰌵", + }, + texthl = { + [vim.diagnostic.severity.ERROR] = "DiagnosticSignError", + [vim.diagnostic.severity.WARN] = "DiagnosticSignWarn", + [vim.diagnostic.severity.INFO] = "DiagnosticSignInfo", + [vim.diagnostic.severity.HINT] = "DiagnosticSignHint", + }, + }, +}) + +-- Add module interface for settings +local M = {} + +function M.setup() + -- Leader keys + vim.g.mapleader = ' ' + vim.g.maplocalleader = ' ' + + -- Ensure swapfile directory exists and configure swapfile settings + local swap_dir = vim.fn.stdpath('data') .. '/swapfiles' + if vim.fn.isdirectory(swap_dir) == 0 then + vim.fn.mkdir(swap_dir, 'p') + end + vim.opt.directory = swap_dir + vim.opt.swapfile = true + vim.opt.updatetime = 300 + vim.opt.updatecount = 100 +end + +return M diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua index ce8af4b951b..5f0ab1605ff 100644 --- a/lua/plugins/bufferline.lua +++ b/lua/plugins/bufferline.lua @@ -2,55 +2,8 @@ return { 'akinsho/bufferline.nvim', version = "*", dependencies = 'nvim-tree/nvim-web-devicons', - opts = { - options = { - mode = "buffers", -- set to "tabs" to only show tabpages instead - numbers = "none", - close_command = "bdelete! %d", -- can be a string | function, | false see "Mouse actions" - right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" - left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions" - middle_mouse_command = nil, -- can be a string | function, | false see "Mouse actions" - indicator = { - icon = '▎', -- this should be omitted if indicator style is not 'icon' - style = 'icon', - }, - buffer_close_icon = '󰅖', - modified_icon = '●', - close_icon = '', - left_trunc_marker = '', - right_trunc_marker = '', - max_name_length = 30, - max_prefix_length = 30, - truncate_names = true, - tab_size = 21, - diagnostics = "nvim_lsp", - diagnostics_update_in_insert = false, - diagnostics_indicator = function(count, level, diagnostics_dict, context) - return "("..count..")" - end, - offsets = { - { - filetype = "NvimTree", - text = "File Explorer", - text_align = "left", - separator = true - } - }, - color_icons = true, - show_buffer_icons = true, - show_buffer_close_icons = true, - show_close_icon = true, - show_tab_indicators = true, - show_duplicate_prefix = true, - persist_buffer_sort = true, - separator_style = "thin", - enforce_regular_tabs = false, - always_show_bufferline = true, - hover = { - enabled = true, - delay = 200, - reveal = {'close'} - }, - } - } + opts = require('plugins.bufferline.setup').opts, + config = function(_, opts) + require('plugins.bufferline.setup').setup() + end, } diff --git a/lua/plugins/bufferline/setup.lua b/lua/plugins/bufferline/setup.lua new file mode 100644 index 00000000000..7cdd189d70e --- /dev/null +++ b/lua/plugins/bufferline/setup.lua @@ -0,0 +1,61 @@ +---@diagnostic disable: undefined-global +-- bufferline setup module +local M = {} + +M.opts = { + options = { + mode = "buffers", -- set to "tabs" to only show tabpages instead of buffers + numbers = "none", + close_command = "bdelete! %d", -- can be a string | function, | false see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function | false see "Mouse actions" + indicator = { + icon = '▎', -- this should be omitted if indicator style is not 'icon' + style = 'icon', + }, + buffer_close_icon = '󰅖', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + max_name_length = 30, + max_prefix_length = 30, + truncate_names = true, + tab_size = 21, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + diagnostics_indicator = function(count, level, diagnostics_dict, context) + return "("..count..")" + end, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "left", + separator = true, + }, + }, + color_icons = true, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + show_duplicate_prefix = true, + persist_buffer_sort = true, + separator_style = "thin", + enforce_regular_tabs = false, + always_show_bufferline = true, + hover = { + enabled = true, + delay = 200, + reveal = {'close'}, + }, + }, +} + +function M.setup() + require('bufferline').setup(M.opts) +end + +return M diff --git a/lua/plugins/cmp/setup.lua b/lua/plugins/cmp/setup.lua new file mode 100644 index 00000000000..e02e754d7db --- /dev/null +++ b/lua/plugins/cmp/setup.lua @@ -0,0 +1,62 @@ +---@diagnostic disable: undefined-global +-- nvim-cmp setup module +local M = {} + +function M.setup() + local cmp = require 'cmp' + local luasnip = require 'luasnip' + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { completeopt = 'menu,menuone,noinsert' }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + }, + sources = { + { name = 'lazydev', group_index = 0 }, + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, + } + + -- Cmdline completion for search (/, ?) and command (:) + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) +end + +return M diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index 5e6f59b4691..3b4e3809a55 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -1,252 +1,7 @@ +---@diagnostic disable: undefined-global return { - -- Go development - { - "ray-x/go.nvim", - dependencies = { -- optional packages - "ray-x/guihua.lua", - "neovim/nvim-lspconfig", - "nvim-treesitter/nvim-treesitter", - }, - config = function() - require("go").setup({ - -- Gopls configuration - lsp_cfg = { - settings = { - gopls = { - analyses = { - unusedparams = true, - shadow = true, - }, - staticcheck = true, - gofumpt = true, - usePlaceholders = true, - hints = { - assignVariableTypes = true, - compositeLiteralFields = true, - compositeLiteralTypes = true, - constantValues = true, - functionTypeParameters = true, - parameterNames = true, - rangeVariableTypes = true, - }, - }, - }, - }, - -- Format on save - gofmt = "gofumpt", - -- Import on save - goimports = true, - -- Enable linters - linter = "golangci-lint", - -- Test settings - test_runner = "go", - test_flags = {"-v"}, - -- Debug settings - dap_debug = true, - dap_debug_gui = true, - }) - - -- Run gofmt + goimports on save - local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {}) - vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*.go", - callback = function() - require("go.format").goimports() - end, - group = format_sync_grp, - }) - end, - event = {"CmdlineEnter"}, - ft = {"go", "gomod"}, - build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries - }, - - -- Zig development - { - "ziglang/zig.vim", - ft = "zig", - config = function() - -- Enable auto-formatting on save - vim.g.zig_fmt_autosave = 1 - end, - }, - - -- C development - { - "p00f/clangd_extensions.nvim", - dependencies = { - "neovim/nvim-lspconfig", - }, - ft = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, - opts = { - inlay_hints = { - inline = false, - }, - ast = { - role_icons = { - type = "🄣", - declaration = "🄓", - expression = "🄔", - statement = ";", - specifier = "🄢", - ["template argument"] = "🆃", - }, - kind_icons = { - Compound = "🄲", - Recovery = "🅁", - TranslationUnit = "🅄", - PackExpansion = "🄿", - TemplateTypeParm = "🅃", - TemplateTemplateParm = "🅃", - TemplateParamObject = "🅃", - }, - }, - }, - }, - - -- DAP (Debug Adapter Protocol) - { - "mfussenegger/nvim-dap", - dependencies = { - "rcarriga/nvim-dap-ui", - "theHamsta/nvim-dap-virtual-text", - "leoluz/nvim-dap-go", -- Go debug adapter - "nvim-neotest/nvim-nio", -- Required by nvim-dap-ui - }, - config = function() - local dap = require("dap") - local dapui = require("dapui") - - -- Set up Go debugging - require("dap-go").setup() - - -- Set up Python debugging - dap.adapters.python = { - type = 'executable', - command = 'debugpy-adapter', - } - - dap.configurations.python = { - { - type = 'python', - request = 'launch', - name = "Launch file", - program = "${file}", - pythonPath = function() - -- Try to detect python path from active virtual environment - if vim.env.VIRTUAL_ENV then - return vim.env.VIRTUAL_ENV .. "/bin/python" - end - -- Return system python if no venv - return '/usr/bin/python3' - end, - }, - } - - -- Set up C debugging with codelldb - dap.adapters.codelldb = { - type = 'server', - port = "${port}", - executable = { - command = 'codelldb', - args = {"--port", "${port}"}, - } - } - - dap.configurations.c = { - { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - end, - cwd = '${workspaceFolder}', - stopOnEntry = false, - args = {}, - }, - } - - -- Set up UI - dapui.setup({ - layouts = { - { - elements = { - { id = "scopes", size = 0.25 }, - { id = "breakpoints", size = 0.25 }, - { id = "stacks", size = 0.25 }, - { id = "watches", size = 0.25 }, - }, - position = "left", - size = 40 - }, - { - elements = { - { id = "repl", size = 0.5 }, - { id = "console", size = 0.5 }, - }, - position = "bottom", - size = 10 - }, - }, - }) - - -- Automatically open UI - dap.listeners.after.event_initialized["dapui_config"] = function() - dapui.open() - end - dap.listeners.before.event_terminated["dapui_config"] = function() - dapui.close() - end - dap.listeners.before.event_exited["dapui_config"] = function() - dapui.close() - end - - -- Add keymaps - vim.keymap.set("n", "pb", dap.toggle_breakpoint, { desc = "Toggle Breakpoint" }) - vim.keymap.set("n", "pc", dap.continue, { desc = "Continue Debug" }) - vim.keymap.set("n", "pn", dap.step_over, { desc = "Step Over" }) - vim.keymap.set("n", "pi", dap.step_into, { desc = "Step Into" }) - vim.keymap.set("n", "po", dap.step_out, { desc = "Step Out" }) - vim.keymap.set("n", "pr", dap.repl.open, { desc = "Debug REPL" }) - vim.keymap.set("n", "pl", dap.run_last, { desc = "Run Last Debug" }) - vim.keymap.set("n", "px", dapui.toggle, { desc = "Toggle Debug UI" }) - - -- Profiling commands - local function profile_go() - local file = vim.fn.expand('%:p') - local cmd = string.format('go test -cpuprofile cpu.prof -memprofile mem.prof -bench . %s', file) - vim.fn.system(cmd) - vim.cmd('split term://go tool pprof -http=:8080 cpu.prof') - end - - local function profile_python() - local file = vim.fn.expand('%:p') - local cmd = string.format('py-spy record -o profile.svg -f speedscope -- python %s', file) - vim.fn.system(cmd) - vim.cmd('!xdg-open profile.svg') - end - - local function profile_c() - local file = vim.fn.expand('%:p:r') -- Get file path without extension - local cmd = string.format('perf record -g ./%s && perf report -g graph', file) - vim.cmd('split term://' .. cmd) - end - - -- Add profiling keymaps based on filetype - vim.api.nvim_create_autocmd("FileType", { - pattern = { "go", "python", "c", "cpp" }, - callback = function() - local ft = vim.bo.filetype - if ft == "go" then - vim.keymap.set("n", "mp", profile_go, { buffer = true, desc = "Profile Go code" }) - elseif ft == "python" then - vim.keymap.set("n", "mp", profile_python, { buffer = true, desc = "Profile Python code" }) - elseif ft == "c" or ft == "cpp" then - vim.keymap.set("n", "mp", profile_c, { buffer = true, desc = "Profile C/C++ code" }) - end - end, - }) - end, - }, + require('plugins.coding.go'), + require('plugins.coding.zig'), + require('plugins.coding.clangd'), + require('plugins.coding.dap'), } diff --git a/lua/plugins/coding/clangd.lua b/lua/plugins/coding/clangd.lua new file mode 100644 index 00000000000..19c62f258c3 --- /dev/null +++ b/lua/plugins/coding/clangd.lua @@ -0,0 +1,28 @@ +---@diagnostic disable: undefined-global +return { + "p00f/clangd_extensions.nvim", + dependencies = { "neovim/nvim-lspconfig" }, + ft = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + opts = { + inlay_hints = { inline = false }, + ast = { + role_icons = { + type = "🄣", + declaration = "🄓", + expression = "🄔", + statement = ";", + specifier = "🄢", + ["template argument"] = "🆃", + }, + kind_icons = { + Compound = "🄲", + Recovery = "🅁", + TranslationUnit = "🅄", + PackExpansion = "🄿", + TemplateTypeParm = "🅃", + TemplateTemplateParm = "🅃", + TemplateParamObject = "🅃", + }, + }, + }, +} diff --git a/lua/plugins/coding/dap.lua b/lua/plugins/coding/dap.lua new file mode 100644 index 00000000000..97f0a5a1243 --- /dev/null +++ b/lua/plugins/coding/dap.lua @@ -0,0 +1,136 @@ +---@diagnostic disable: undefined-global +return { + "mfussenegger/nvim-dap", + dependencies = { + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "leoluz/nvim-dap-go", + "nvim-neotest/nvim-nio", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + + -- Set up Go debugging + require("dap-go").setup() + + -- Set up Python debugging + dap.adapters.python = { + type = 'executable', + command = 'debugpy-adapter', + } + + dap.configurations.python = { + { + type = 'python', + request = 'launch', + name = "Launch file", + program = "${file}", + pythonPath = function() + if vim.env.VIRTUAL_ENV then + return vim.env.VIRTUAL_ENV .. "/bin/python" + end + return '/usr/bin/python3' + end, + }, + } + + -- Set up C debugging with codelldb + dap.adapters.codelldb = { + type = 'server', + port = "${port}", + executable = { + command = 'codelldb', + args = {"--port", "${port}"}, + }, + } + + dap.configurations.c = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + }, + } + + -- Set up UI + dapui.setup({ + layouts = { + { + elements = { + { id = "scopes", size = 0.25 }, + { id = "breakpoints", size = 0.25 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.25 }, + }, + position = "left", + size = 40, + }, + { + elements = { + { id = "repl", size = 0.5 }, + { id = "console", size = 0.5 }, + }, + position = "bottom", + size = 10, + }, + }, + }) + + -- Automatically open/close UI on session events + dap.listeners.after.event_initialized['dapui_config'] = dapui.open + dap.listeners.before.event_terminated['dapui_config'] = dapui.close + dap.listeners.before.event_exited['dapui_config'] = dapui.close + + -- Add keymaps + vim.keymap.set('n', 'pb', dap.toggle_breakpoint, { desc = 'Toggle Breakpoint' }) + vim.keymap.set('n', 'pc', dap.continue, { desc = 'Continue Debug' }) + vim.keymap.set('n', 'pn', dap.step_over, { desc = 'Step Over' }) + vim.keymap.set('n', 'pi', dap.step_into, { desc = 'Step Into' }) + vim.keymap.set('n', 'po', dap.step_out, { desc = 'Step Out' }) + vim.keymap.set('n', 'pr', dap.repl.open, { desc = 'Debug REPL' }) + vim.keymap.set('n', 'pl', dap.run_last, { desc = 'Run Last Debug' }) + vim.keymap.set('n', 'px', dapui.toggle, { desc = 'Toggle Debug UI' }) + + -- Profiling commands + local function profile_go() + local file = vim.fn.expand('%:p') + local cmd = string.format('go test -cpuprofile cpu.prof -memprofile mem.prof -bench . %s', file) + vim.fn.system(cmd) + vim.cmd('split term://go tool pprof -http=:8080 cpu.prof') + end + + local function profile_python() + local file = vim.fn.expand('%:p') + local cmd = string.format('py-spy record -o profile.svg -f speedscope -- python %s', file) + vim.fn.system(cmd) + vim.cmd('!xdg-open profile.svg') + end + + local function profile_c() + local file = vim.fn.expand('%:p:r') + local cmd = string.format('perf record -g ./%s && perf report -g graph', file) + vim.cmd('split term://' .. cmd) + end + + vim.api.nvim_create_autocmd('FileType', { + pattern = { 'go', 'python', 'c', 'cpp' }, + callback = function() + local ft = vim.bo.filetype + if ft == 'go' then + vim.keymap.set('n', 'mp', profile_go, { buffer = true, desc = 'Profile Go code' }) + elseif ft == 'python' then + vim.keymap.set('n', 'mp', profile_python, { buffer = true, desc = 'Profile Python code' }) + elseif ft == 'c' or ft == 'cpp' then + vim.keymap.set('n', 'mp', profile_c, { buffer = true, desc = 'Profile C/C++ code' }) + end + end, + }) + end, +} diff --git a/lua/plugins/coding/go.lua b/lua/plugins/coding/go.lua new file mode 100644 index 00000000000..6d1b83a25ab --- /dev/null +++ b/lua/plugins/coding/go.lua @@ -0,0 +1,24 @@ +---@diagnostic disable: undefined-global +return { + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + config = function() + require("go").setup({ + lsp_cfg = false, + gofmt = false, + goimports = false, + linter = "golangci-lint", + test_runner = "go", + test_flags = { "-v" }, + dap_debug = true, + dap_debug_gui = true, + }) + end, + event = { "CmdlineEnter" }, + ft = { "go", "gomod" }, + build = ':lua require("go.install").update_all_sync()', +} diff --git a/lua/plugins/coding/zig.lua b/lua/plugins/coding/zig.lua new file mode 100644 index 00000000000..2690feda654 --- /dev/null +++ b/lua/plugins/coding/zig.lua @@ -0,0 +1,9 @@ +---@diagnostic disable: undefined-global +return { + "ziglang/zig.vim", + ft = "zig", + config = function() + -- Enable auto-formatting on save + vim.g.zig_fmt_autosave = 1 + end, +} diff --git a/lua/plugins/gruvbox.lua b/lua/plugins/colorscheme.lua similarity index 100% rename from lua/plugins/gruvbox.lua rename to lua/plugins/colorscheme.lua diff --git a/lua/plugins/commentary.lua b/lua/plugins/commentary.lua new file mode 100644 index 00000000000..cf2c32c96d2 --- /dev/null +++ b/lua/plugins/commentary.lua @@ -0,0 +1,6 @@ +return { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end, +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index b7b0c09eb35..a6b1caaf490 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -1,5 +1,7 @@ +---@diagnostic disable: undefined-global return { -- Autoformat 'stevearc/conform.nvim', + enabled = false, event = { 'BufWritePre' }, cmd = { 'ConformInfo' }, keys = { @@ -18,7 +20,7 @@ return { -- Autoformat -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } + local disable_filetypes = {} -- C and C++ now enabled for format-on-save local lsp_format_opt if disable_filetypes[vim.bo[bufnr].filetype] then lsp_format_opt = 'never' @@ -32,6 +34,9 @@ return { -- Autoformat end, formatters_by_ft = { lua = { 'stylua' }, + go = { 'gofumpt', 'goimports' }, -- Run gofumpt first, then goimports + c = { 'clang_format' }, -- Add clang-format for C + cpp = { 'clang_format' }, -- Add clang-format for C++ -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- diff --git a/lua/plugins/garbage-day.lua b/lua/plugins/garbage-day.lua index 25134296f93..cfdb687a6a7 100644 --- a/lua/plugins/garbage-day.lua +++ b/lua/plugins/garbage-day.lua @@ -1,6 +1,6 @@ -- Garbage collector that stops inactive LSP clients to free RAM return { - 'zeioth/garbage-day.nvim', + --[[ 'zeioth/garbage-day.nvim', dependencies = 'neovim/nvim-lspconfig', event = 'VeryLazy', opts = { @@ -17,5 +17,5 @@ return { pause = 110, -- Lower pause for more frequent but shorter GC pauses step_mul = 100, -- Lower step multiplier for smoother collection }, - }, + }, ]] } diff --git a/lua/plugins/gitsigns/setup.lua b/lua/plugins/gitsigns/setup.lua new file mode 100644 index 00000000000..3c8716d6ca0 --- /dev/null +++ b/lua/plugins/gitsigns/setup.lua @@ -0,0 +1,28 @@ +---@diagnostic disable: undefined-global +-- GitSigns setup module +local M = {} + +function M.setup() + require('gitsigns').setup({ + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = '~' }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { interval = 1000, follow_files = true }, + attach_to_untracked = true, + current_line_blame = false, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, + preview_config = { border = 'single', style = 'minimal', relative = 'cursor', row = 0, col = 1 }, + }) +end + +return M diff --git a/lua/plugins/indent-blankline.lua b/lua/plugins/indent-blankline.lua new file mode 100644 index 00000000000..c4dc25ab70b --- /dev/null +++ b/lua/plugins/indent-blankline.lua @@ -0,0 +1,8 @@ +-- Indentation guides for Neovim +return { + 'lukas-reineke/indent-blankline.nvim', + main = 'ibl', + event = { 'BufReadPre', 'BufNewFile' }, + opts = {}, -- Use ibl's defaults for best compatibility + +} diff --git a/lua/plugins/lsp/servers.lua b/lua/plugins/lsp/servers.lua new file mode 100644 index 00000000000..3b8d96061e9 --- /dev/null +++ b/lua/plugins/lsp/servers.lua @@ -0,0 +1,69 @@ +---@diagnostic disable: undefined-global +-- LSP servers configuration + +-- Go flags for build tags +local go_flags = 'integration' +local gopls_build_flags = go_flags ~= '' and { '-tags=' .. go_flags } or {} + +return { + -- Python + pyright = {}, + -- Go + gopls = { + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = false, + gofumpt = false, + hints = { + assignVariableTypes = false, + compositeLiteralFields = false, + compositeLiteralTypes = false, + constantValues = false, + functionTypeParameters = false, + parameterNames = false, + rangeVariableTypes = false, + }, + vulncheck = 'Off', + completionBudget = '100ms', + symbolMatcher = 'FastFuzzy', + symbolStyle = 'Dynamic', + diagnosticsDelay = '500ms', + buildFlags = gopls_build_flags, + }, + }, + }, + -- Lua + lua_ls = { + settings = { + Lua = { + runtime = { version = 'LuaJIT' }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + checkThirdParty = false, + library = { + [vim.fn.expand '$VIMRUNTIME/lua'] = true, + [vim.fn.stdpath 'config' .. '/lua'] = true, + }, + }, + telemetry = { enable = false }, + }, + }, + }, + -- C/C++ + clangd = {}, + + -- SQL + sqls = { + settings = { + sqls = { + connections = {}, + lowercaseKeywords = true, + }, + }, + }, +} diff --git a/lua/plugins/lsp/setup.lua b/lua/plugins/lsp/setup.lua new file mode 100644 index 00000000000..d5cb7b907ec --- /dev/null +++ b/lua/plugins/lsp/setup.lua @@ -0,0 +1,68 @@ +---@diagnostic disable: undefined-global +-- LSP setup (mason + lspconfig) + +local M = {} + +function M.setup() + local servers = require('plugins.lsp.servers') + + -- nvim-cmp capabilities + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + -- Setup mason-lspconfig + local mason_lspconfig = require('mason-lspconfig') + mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers) } + + mason_lspconfig.setup_handlers { + function(server_name) + local config = servers[server_name] or {} + config.capabilities = capabilities + + -- Default on_attach to setup keymaps & navic + local function on_attach(client, bufnr) + require('core.keymaps').setup_lsp_keymaps(bufnr) + -- Attach navic if available + if client.server_capabilities.documentSymbolProvider then + require('nvim-navic').attach(client, bufnr) + end + end + config.on_attach = on_attach + + -- Disable gopls semantic tokens to avoid issues + if server_name == 'gopls' and config.on_attach then + local orig_on_attach = config.on_attach + config.on_attach = function(client, bufnr) + client.server_capabilities.semanticTokensProvider = nil + orig_on_attach(client, bufnr) + end + end + + require('lspconfig')[server_name].setup(config) + end, + } + + -- Override references handler + vim.lsp.handlers['textDocument/references'] = function(err, result, ctx, config) + if not result or vim.tbl_isempty(result) then + vim.notify('No references found', vim.log.levels.INFO) + else + require('telescope.builtin').lsp_references() + end + end + + -- Override semanticTokens/full + vim.lsp.handlers['textDocument/semanticTokens/full'] = function(err, result, ctx, cfg) + if err or not result then return end + local client = vim.lsp.get_client_by_id(ctx.client_id) + if not client then return end + local bufnr = ctx.bufnr + local highlighter = vim.lsp.semantic_tokens.create_highlighter(bufnr, client) + if not highlighter then return end + pcall(function() + highlighter:process_response(result, client, ctx.request.version) + end) + end +end + +return M diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 00000000000..2d2c0447be7 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,73 @@ +---@diagnostic disable: undefined-global +return { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup { + options = { + theme = 'gruvbox', + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { + 'filename', + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + sections = { 'error', 'warn', 'info', 'hint' }, + symbols = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, + colored = true, + update_in_insert = false, + always_visible = true, + }, + { + function() + -- Get the navic location with a more reliable approach + local location = require('nvim-navic').get_location() + if location and location ~= "" then + return "📍 " .. location -- Add an icon for better visibility + end + return "" + end, + cond = function() + return package.loaded['nvim-navic'] and require('nvim-navic').is_available() + end, + color = { fg = '#a3be8c', gui = 'bold' }, -- Make it more visible with color + }, + }, + lualine_x = { + { + function() + local qf_list = vim.fn.getqflist() + local count = #qf_list + if count > 0 then + return 'QF:' .. count + else + return '' + end + end, + icon = '', + color = { fg = '#d7af5f', gui = 'bold' }, + }, + 'encoding', + 'fileformat', + 'filetype', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + extensions = { 'quickfix' }, + } + end, +} diff --git a/lua/plugins/lualine/setup.lua b/lua/plugins/lualine/setup.lua new file mode 100644 index 00000000000..5420300e7e8 --- /dev/null +++ b/lua/plugins/lualine/setup.lua @@ -0,0 +1,72 @@ +---@diagnostic disable: undefined-global +-- lualine setup module +local M = {} + +function M.setup() + require('lualine').setup { + options = { + theme = 'gruvbox', + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { + 'filename', + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + sections = { 'error', 'warn', 'info', 'hint' }, + symbols = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, + colored = true, + update_in_insert = false, + always_visible = true, + }, + { + function() + local location = require('nvim-navic').get_location() + if location and location ~= '' then + return '📍 ' .. location + end + return '' + end, + cond = function() + return package.loaded['nvim-navic'] and require('nvim-navic').is_available() + end, + color = { fg = '#a3be8c', gui = 'bold' }, + }, + }, + lualine_x = { + { + function() + local qf_list = vim.fn.getqflist() + local count = #qf_list + if count > 0 then + return 'QF:' .. count + end + return '' + end, + icon = '', + color = { fg = '#d7af5f', gui = 'bold' }, + }, + 'encoding', + 'fileformat', + 'filetype', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + extensions = { 'quickfix' }, + } +end + +return M diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua index ce2dff0636f..3c41d5a80ac 100644 --- a/lua/plugins/null-ls.lua +++ b/lua/plugins/null-ls.lua @@ -5,64 +5,6 @@ return { 'jay-babu/mason-null-ls.nvim', }, config = function() - local null_ls = require 'null-ls' - local null_ls_utils = require 'null-ls.utils' - - local formatting = null_ls.builtins.formatting - local diagnostics = null_ls.builtins.diagnostics - - null_ls.setup { - root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), - timeout = 10000, -- Reduced timeout - debounce = 250, -- Add debounce to prevent excessive updates - update_in_insert = false, -- Only update diagnostics when leaving insert mode - sources = { - -- Go formatting and linting - formatting.gofumpt.with({ - extra_args = { "-extra" }, -- More aggressive formatting - }), - formatting.goimports.with({ - args = { "-local", "", "-w", "$FILENAME" }, -- Optimize imports - }), - diagnostics.golangci_lint.with({ - diagnostics_format = '#{m}', - extra_args = { - '--fast', - '--max-issues-per-linter', '30', - '--max-same-issues', '4', - '--max-same-issues-per-linter', '0', -- Disable duplicate issue reporting per linter - '--fix=false', -- Don't try to fix issues - '--tests=false', -- Don't analyze tests for faster results - '--print-issued-lines=false', -- Don't print the lines that triggered issues - '--timeout=10s', -- Timeout after 10 seconds - '--out-format=json', -- Use JSON format for faster parsing - }, - method = null_ls.methods.DIAGNOSTICS_ON_SAVE, -- Only run on save - timeout = 10000, -- 10 second timeout - }), - - -- Web formatting - formatting.prettier.with { - filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, - extra_args = { - '--bracket-same-line', - '--trailing-comma', 'all', - '--tab-width', '2', - '--semi', - '--single-quote', - }, - }, - - -- Shell formatting - formatting.shfmt.with { - extra_args = { '-i', '2', '-ci', '-bn' }, - }, - - -- SQL formatting - formatting.sqlfluff.with { - extra_args = { '--dialect', 'tsql' }, - }, - }, - } + require('plugins.null-ls.setup').setup() end, } diff --git a/lua/plugins/null-ls/setup.lua b/lua/plugins/null-ls/setup.lua new file mode 100644 index 00000000000..d36235ed9d9 --- /dev/null +++ b/lua/plugins/null-ls/setup.lua @@ -0,0 +1,51 @@ +---@diagnostic disable: undefined-global +-- null-ls setup module +local M = {} + +function M.setup() + local null_ls = require 'null-ls' + local null_ls_utils = require 'null-ls.utils' + local formatting = null_ls.builtins.formatting + local diagnostics = null_ls.builtins.diagnostics + + null_ls.setup { + root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), + timeout = 10000, + debounce = 250, + update_in_insert = false, + sources = { + formatting.gofumpt.with({ extra_args = { "-extra" } }), + formatting.goimports.with({ args = { "-local", "", "-w", "$FILENAME" } }), + diagnostics.golangci_lint.with({ + diagnostics_format = '#{m}', + extra_args = { + '--fast', + '--max-issues-per-linter', '30', + '--max-same-issues', '4', + '--max-same-issues-per-linter', '0', + '--fix=false', + '--tests=false', + '--print-issued-lines=false', + '--timeout=10s', + '--out-format=json', + }, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + timeout = 10000, + }), + formatting.prettier.with { + filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, + extra_args = { + '--bracket-same-line', + '--trailing-comma', 'all', + '--tab-width', '2', + '--semi', + '--single-quote', + }, + }, + formatting.shfmt.with { extra_args = { '-i', '2', '-ci', '-bn' } }, + formatting.sqlfluff.with { extra_args = { '--dialect', 'tsql' } }, + }, + } +end + +return M diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua index 4bbf9ea8fb0..aa6ea965957 100644 --- a/lua/plugins/nvim-autopairs.lua +++ b/lua/plugins/nvim-autopairs.lua @@ -1,35 +1,8 @@ return { 'windwp/nvim-autopairs', event = "InsertEnter", -- Only load in insert mode - opts = { - check_ts = true, - ts_config = { - lua = { "string" }, - javascript = { "template_string" }, - java = false, - }, - ignored_next_char = "[%w%.]", - enable_moveright = false, -- Don't move cursor after pair - enable_afterquote = false, -- Don't add pairs after quotes - enable_check_bracket_line = true, - enable_bracket_in_quote = false, - map_cr = true, - map_bs = true, - map_c_h = false, - map_c_w = false, - disable_in_macro = true, - disable_in_visualblock = true, - enable_abbr = false, - }, - config = function(_, opts) - local npairs = require('nvim-autopairs') - npairs.setup(opts) - - -- Only enable completion integration if cmp is loaded - local ok, cmp = pcall(require, 'cmp') - if ok then - local cmp_autopairs = require('nvim-autopairs.completion.cmp') - cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) - end + opts = nil, + config = function() + require('plugins.nvim-autopairs.setup').setup(require('plugins.nvim-autopairs.setup').opts) end, } diff --git a/lua/plugins/nvim-autopairs/setup.lua b/lua/plugins/nvim-autopairs/setup.lua new file mode 100644 index 00000000000..f4ed31f51b4 --- /dev/null +++ b/lua/plugins/nvim-autopairs/setup.lua @@ -0,0 +1,36 @@ +---@diagnostic disable: undefined-global +-- nvim-autopairs setup module +local M = {} + +M.opts = { + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, + ignored_next_char = "[%w%.]", + enable_moveright = false, + enable_afterquote = false, + enable_check_bracket_line = true, + enable_bracket_in_quote = false, + map_cr = true, + map_bs = true, + map_c_h = false, + map_c_w = false, + disable_in_macro = true, + disable_in_visualblock = true, + enable_abbr = false, +} + +function M.setup(opts) + local npairs = require('nvim-autopairs') + npairs.setup(opts) + local ok, cmp = pcall(require, 'cmp') + if ok then + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) + end +end + +return M diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua index 787e29e900e..62b45888899 100644 --- a/lua/plugins/nvim-cmp.lua +++ b/lua/plugins/nvim-cmp.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global return { -- Autocompletion 'hrsh7th/nvim-cmp', event = 'InsertEnter', @@ -35,81 +36,6 @@ return { -- Autocompletion 'hrsh7th/cmp-path', }, config = function() - -- See `:help cmp` - local cmp = require 'cmp' - local luasnip = require 'luasnip' - luasnip.config.setup {} - - cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { completeopt = 'menu,menuone,noinsert' }, - - -- For an understanding of why these mappings were - -- chosen, you will need to read `:help ins-completion` - -- - -- No, but seriously. Please read `:help ins-completion`, it is really good! - mapping = cmp.mapping.preset.insert { - -- Select the [n]ext item - [''] = cmp.mapping.select_next_item(), - -- Select the [p]revious item - [''] = cmp.mapping.select_prev_item(), - - -- Scroll the documentation window [b]ack / [f]orward - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - - -- Accept ([y]es) the completion. - -- This will auto-import if your LSP supports it. - -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, - - -- If you prefer more traditional completion keymaps, - -- you can uncomment the following lines - --[''] = cmp.mapping.confirm { select = true }, - --[''] = cmp.mapping.select_next_item(), - --[''] = cmp.mapping.select_prev_item(), - - -- Manually trigger a completion from nvim-cmp. - -- Generally you don't need this, because nvim-cmp will display - -- completions whenever it has completion options available. - [''] = cmp.mapping.complete {}, - - -- Think of as moving to the right of your snippet expansion. - -- So if you have a snippet that's like: - -- function $name($args) - -- $body - -- end - -- - -- will move you to the right of each of the expansion locations. - -- is similar, except moving you backwards. - [''] = cmp.mapping(function() - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - end - end, { 'i', 's' }), - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps - }, - sources = { - { - name = 'lazydev', - -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it - group_index = 0, - }, - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, - } + require('plugins.cmp.setup').setup() end, } diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index 8f367092170..55134df3c0b 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -1,3 +1,6 @@ +---@diagnostic disable: undefined-global +local go_flags = 'integration' -- add the tags here, instead of searching it below + return { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -14,24 +17,24 @@ return { 'lua-language-server', 'marksman', -- Go tools - 'gopls', -- Go LSP - 'gofumpt', -- Stricter Go formatter - 'goimports', -- Go import manager - 'golangci-lint', -- Go linter - 'delve', -- Go debugger + 'gopls', -- Go LSP + 'gofumpt', -- Stricter Go formatter + 'goimports', -- Go import manager + 'golangci-lint', -- Go linter + 'delve', -- Go debugger -- Zig tools - 'zls', -- Zig LSP + 'zls', -- Zig LSP -- C tools - 'clangd', -- C/C++ LSP - 'clang-format', -- C/C++ formatter - 'codelldb', -- Native code debugger + 'clangd', -- C/C++ LSP + 'clang-format', -- C/C++ formatter + 'codelldb', -- Native code debugger -- Python tools - 'pyright', -- Python LSP - 'black', -- Python formatter - 'ruff', -- Python linter - 'debugpy', -- Python debugger + 'pyright', -- Python LSP + 'black', -- Python formatter + 'ruff', -- Python linter + 'debugpy', -- Python debugger -- SQL tools - 'sqls', -- Advanced SQL LSP + 'sqls', -- Advanced SQL LSP }, auto_update = true, run_on_start = true, @@ -45,213 +48,17 @@ return { -- Allows extra capabilities provided by nvim-cmp 'hrsh7th/cmp-nvim-lsp', + + -- Add nvim-navic for breadcrumbs + { 'SmiteshP/nvim-navic', config = function() + require('nvim-navic').setup { + highlight = true, + separator = ' > ', + depth_limit = 5, + } + end }, }, config = function() - -- Brief aside: **What is LSP?** - -- - -- LSP is an initialism you've probably heard, but might not understand what it is. - -- - -- LSP stands for Language Server Protocol. It's a protocol that helps editors - -- and language tooling communicate in a standardized fashion. - -- - -- See `:help lsp` for more details. - - -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- - -- Add any additional override configuration in the following tables. Available keys are: - -- - cmd (table): Override the default command used to start the server - -- - filetypes (table): Override the default list of associated filetypes for the server - -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. - -- - settings (table): Override the default settings passed to the server. Can be used to disable diagnostics. - local servers = { - -- Python - pyright = {}, - -- Go - gopls = { - settings = { - gopls = { - analyses = { - unusedparams = true, - }, - staticcheck = false, -- Let golangci-lint handle this - gofumpt = false, -- Let null-ls handle this - hints = { - assignVariableTypes = false, -- Disable hints for better performance - compositeLiteralFields = false, - compositeLiteralTypes = false, - constantValues = false, - functionTypeParameters = false, - parameterNames = false, - rangeVariableTypes = false, - }, - vulncheck = "Off", -- Disable vulnerability checking - completionBudget = "100ms", -- Limit completion time - symbolMatcher = "FastFuzzy", -- Faster symbol matching - symbolStyle = "Dynamic", - usePlaceholders = false, -- Disable placeholders for better performance - matcher = "Fuzzy", -- Faster matching algorithm - diagnosticsDelay = "500ms", -- Add slight delay to batch diagnostics - }, - }, - }, - -- Lua - lua_ls = { - settings = { - Lua = { - diagnostics = { - globals = { 'vim' }, - }, - workspace = { - library = { - [vim.fn.expand('$VIMRUNTIME/lua')] = true, - [vim.fn.stdpath('config') .. '/lua'] = true, - }, - }, - }, - }, - }, - -- SQL - Advanced SQL language server with better completion - sqls = { - settings = { - sqls = { - connections = {}, -- Will be populated by dadbod - lowercaseKeywords = true, -- Format keywords to lowercase - }, - }, - }, - } - - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - - -- Single LSP attach handler for all functionality - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(args) - -- Remove any diagnostic keymaps - pcall(vim.keymap.del, 'n', 'e', { buffer = args.buf }) - - -- Get the client - local client = vim.lsp.get_client_by_id(args.data.client_id) - if not client then return end - - -- Disable semantic tokens for gopls - if client.name == "gopls" then - client.server_capabilities.semanticTokensProvider = nil - end - - -- Only set up document formatting for null-ls - if client.name ~= "null-ls" then - client.server_capabilities.documentFormattingProvider = false - end - - -- Set up LSP keymaps - require('core.keymaps').setup_lsp_keymaps(args.buf) - - -- Override the built-in LSP handler for references to use telescope - vim.lsp.handlers['textDocument/references'] = function(_, result, ctx) - if not result or vim.tbl_isempty(result) then - vim.notify('No references found') - else - require('telescope.builtin').lsp_references() - end - end - - -- Set up document highlight on hover only if the server supports it - if client.server_capabilities.documentHighlightProvider then - local highlight_group = vim.api.nvim_create_augroup('lsp_document_highlight_' .. args.buf, { clear = true }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - group = highlight_group, - buffer = args.buf, - callback = function() - -- Check if the client is still attached and valid - if vim.lsp.buf_get_clients(args.buf)[1] then - vim.lsp.buf.document_highlight() - end - end, - }) - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - group = highlight_group, - buffer = args.buf, - callback = function() - -- Check if the client is still attached and valid - if vim.lsp.buf_get_clients(args.buf)[1] then - vim.lsp.buf.clear_references() - end - end, - }) - end - end, - }) - - -- Ensure the servers above are installed - local mason_lspconfig = require 'mason-lspconfig' - - mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), - } - - -- Custom semantic tokens handler for gopls - local semantic_tokens_handler = function(err, result, ctx, config) - local client = vim.lsp.get_client_by_id(ctx.client_id) - if not client then return end - - -- Check if client has the required semantic tokens capabilities - local semantic_tokens = client.server_capabilities.semanticTokensProvider - if not semantic_tokens or not semantic_tokens.legend then - -- If no legend is provided, disable semantic tokens for this client - client.server_capabilities.semanticTokensProvider = nil - return - end - - -- If we have a valid legend, proceed with default handler - vim.lsp.semantic_tokens.on_full(err, result, ctx, config) - end - - mason_lspconfig.setup_handlers { - function(server_name) - local server_config = servers[server_name] or {} - - -- For gopls, add debug logging - if server_name == "gopls" then - -- Create a custom on_attach that disables semantic tokens - local orig_on_attach = server_config.on_attach - server_config.on_attach = function(client, bufnr) - -- Disable semantic tokens for this client - client.server_capabilities.semanticTokensProvider = nil - -- Call original on_attach if it exists - if orig_on_attach then - orig_on_attach(client, bufnr) - end - end - end - - server_config.capabilities = capabilities - require('lspconfig')[server_name].setup(server_config) - end, - } - - -- Override the semantic tokens handler to be more resilient - vim.lsp.handlers['textDocument/semanticTokens/full'] = function(err, result, ctx, config) - -- If there's an error or no result, just return - if err or not result then return end - - local client = vim.lsp.get_client_by_id(ctx.client_id) - if not client then return end - - local bufnr = ctx.bufnr - if not bufnr then return end - - -- Get the highlighter safely - local highlighter = vim.lsp.semantic_tokens.create_highlighter(bufnr, client) - if not highlighter then return end - - -- Process the response safely - pcall(function() - highlighter:process_response(result, client, ctx.request.version) - end) - end + require('plugins.lsp.setup').setup() end, } diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua index bea35d3aac2..fdb866264bb 100644 --- a/lua/plugins/nvim-treesitter.lua +++ b/lua/plugins/nvim-treesitter.lua @@ -5,8 +5,10 @@ return { -- Highlight, edit, and navigate code -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, - -- Autoinstall languages that are not installed + sync_install = false, auto_install = true, + ignore_install = {}, + highlight = { enable = true, -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua index 34b9f1e4020..bfe6be650f7 100644 --- a/lua/plugins/session.lua +++ b/lua/plugins/session.lua @@ -3,6 +3,12 @@ return { version = '*', event = "VimEnter", config = function() + -- Function to get current directory name + local function get_session_name() + local cwd = vim.fn.getcwd() + return vim.fn.fnamemodify(cwd, ':t') + end + require('mini.sessions').setup({ -- Whether to read latest session if Neovim opened without file arguments autoread = false, @@ -49,5 +55,17 @@ return { -- Whether to print session path after action verbose = { read = false, write = true, delete = true }, }) - end + + -- Set up autocommands for auto-saving + local session_group = vim.api.nvim_create_augroup('mini_sessions', { clear = true }) + vim.api.nvim_create_autocmd('VimLeavePre', { + group = session_group, + callback = function() + local name = get_session_name() + if name then + require('mini.sessions').write(name, { force = true }) + end + end, + }) + end, } diff --git a/lua/plugins/snacks/picker.lua b/lua/plugins/snacks/picker.lua index 017da9aa847..e8bf2477664 100644 --- a/lua/plugins/snacks/picker.lua +++ b/lua/plugins/snacks/picker.lua @@ -18,6 +18,9 @@ return { severity = { pos = "right" }, }, matcher = { sort_empty = false, fuzzy = false }, + -- Add safety options + safe_update = true, -- Skip updates if buffer is being written/closed + ignore_nil_buffers = true, -- Skip nil buffers during updates } } }, diff --git a/lua/plugins/snacks/terminal.lua b/lua/plugins/snacks/terminal.lua index 3a10808dc1c..b9220453a02 100644 --- a/lua/plugins/snacks/terminal.lua +++ b/lua/plugins/snacks/terminal.lua @@ -6,5 +6,9 @@ return { width = 0.8, height = 0.8, }, + -- Set to true for better toggle behavior + persistent = true, + -- Auto-close terminal when process exits + auto_close = true, }, } diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index dcbe783e950..4ced8ca1f00 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global return { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', event = 'VimEnter', @@ -23,99 +24,6 @@ return { -- Fuzzy Finder (files, lsp, etc) { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() - -- Telescope is a fuzzy finder that comes with a lot of different things that - -- it can fuzzy find! It's more than just a "file finder", it can search - -- many different aspects of Neovim, your workspace, LSP, and more! - -- - -- The easiest way to use Telescope, is to start by doing something like: - -- :Telescope help_tags - -- - -- After running this command, a window will open up and you're able to - -- type in the prompt window. You'll see a list of `help_tags` options and - -- a corresponding preview of the help. - -- - -- Two important keymaps to use while in Telescope are: - -- - Insert mode: - -- - Normal mode: ? - -- - -- This opens a window that shows you all of the keymaps for the current - -- Telescope picker. This is really useful to discover what Telescope can - -- do as well as how to actually do it! - - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - defaults = { - mappings = { - i = { - [''] = 'which_key', -- Show help in insert mode - }, - n = { - ['?'] = 'which_key', -- Show help in normal mode - }, - }, - }, - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable Telescope extensions if they are installed - pcall(require('telescope').load_extension, 'fzf') - pcall(require('telescope').load_extension, 'ui-select') - - -- Apply Telescope keymaps from our centralized keymaps file - local keymaps = require('core.keymaps').telescope_keymaps - for _, mapping in ipairs(keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - -- See `:help telescope.builtin` - local builtin = require 'telescope.builtin' - - -- LSP mappings - vim.keymap.set('n', 'gr', builtin.lsp_references, { desc = 'LSP: [G]oto [R]eferences' }) - vim.keymap.set('n', 'gd', builtin.lsp_definitions, { desc = 'LSP: [G]oto [D]efinition' }) - vim.keymap.set('n', 'gI', builtin.lsp_implementations, { desc = 'LSP: [G]oto [I]mplementation' }) - - -- Regular Telescope mappings - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- Document diagnostics - vim.keymap.set('n', 'dx', builtin.diagnostics, { desc = '[D]ocument Diagnostic[x]' }) - - -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) - - -- It's also possible to pass additional configuration options. - -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, { desc = '[S]earch [/] in Open Files' }) - - -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() - builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) + require('plugins.telescope.setup').setup() end, } diff --git a/lua/plugins/telescope/setup.lua b/lua/plugins/telescope/setup.lua new file mode 100644 index 00000000000..6f3dca2eef3 --- /dev/null +++ b/lua/plugins/telescope/setup.lua @@ -0,0 +1,45 @@ +---@diagnostic disable: undefined-global +local M = {} + +function M.setup() + -- Base Telescope configuration + require('telescope').setup { + defaults = { + mappings = { + i = { [''] = 'which_key' }, + n = { ['?'] = 'which_key' }, + }, + }, + extensions = { + ['ui-select'] = { require('telescope.themes').get_dropdown() }, + }, + } + + -- Load extensions + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- Apply keymaps from core.keymaps + local keymaps = require('core.keymaps').telescope_keymaps + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Additional builtins mapping (if not handled by core) + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'gr', builtin.lsp_references, { desc = 'LSP: [G]oto [R]eferences' }) + vim.keymap.set('n', 'gd', builtin.lsp_definitions, { desc = 'LSP: [G]oto [D]efinition' }) + vim.keymap.set('n', 'gI', builtin.lsp_implementations, { desc = 'LSP: [G]oto [I]mplementation' }) + -- Other mappings moved from inline config + vim.keymap.set('n', '/', function() + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false }) + end, { desc = '[/] Fuzzily search in current buffer' }) + vim.keymap.set('n', 's/', function() + builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files' } + end, { desc = '[S]earch [/] in Open Files' }) + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) +end + +return M diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 8bede533a0c..1b532fe7b66 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -6,102 +6,73 @@ return { -- Useful plugin to show you pending keybinds. icons = { mappings = vim.g.have_nerd_font, keys = vim.g.have_nerd_font and {} or { - Up = ' ', - Down = ' ', - Left = ' ', - Right = ' ', - C = ' ', - M = ' ', - D = ' ', - S = ' ', - CR = ' ', - Esc = ' ', - ScrollWheelDown = ' ', - ScrollWheelUp = ' ', - NL = ' ', - BS = ' ', - Space = ' ', - Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', + Up = ' ', Down = ' ', Left = ' ', Right = ' ', + C = ' ', M = ' ', D = ' ', S = ' ', + CR = ' ', Esc = ' ', ScrollWheelDown = ' ', + ScrollWheelUp = ' ', NL = ' ', BS = ' ', + Space = ' ', Tab = ' ', F1 = '', F2 = '', + F3 = '', F4 = '', F5 = '', F6 = '', + F7 = '', F8 = '', F9 = '', F10 = '', + F11 = '', F12 = '', }, }, - - -- Document existing key chains - spec = { - { 'c', group = '[C]ode', desc = { - a = 'Code [A]ction', - f = '[F]ormat buffer', - }}, - { 'd', group = '[D]ocument', desc = { - x = 'Document [D]iagnostics', - s = 'Document [S]ymbols', - [''] = 'Show diagnostic under cursor', - }}, - { 's', group = '[S]earch', desc = { - h = '[H]elp', - k = '[K]eymaps', - f = '[F]iles', - s = '[S]elect Telescope', - w = 'Current [W]ord', - g = '[G]rep', - d = '[D]iagnostics', - r = '[R]esume last search', - ['/'] = 'Search in open files', - n = '[N]eovim config files', - }}, - { 'w', group = '[W]orkspace', desc = { - s = '[S]ymbols', - }}, - { 't', group = '[T]oggle', desc = { - h = 'Toggle inlay [H]ints', - }}, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, - { 'g', group = '[G]it', desc = { - s = 'Status', - }}, - { 'f', group = '[F]ile Explorer', desc = { - e = 'Toggle explorer', - f = 'Focus explorer', - }}, - { 'n', group = '[N]otifications', desc = { - n = 'Toggle notifications', - h = 'Notification [H]istory', - c = '[C]lear notifications', - }}, - { 'p', group = 'Debug/[P]rofile', desc = { - b = 'Toggle [B]reakpoint', - c = '[C]ontinue debugging', - n = 'Step over ([N]ext)', - i = 'Step [I]nto', - o = 'Step [O]ut', - r = 'Open [R]EPL', - l = 'Run [L]ast debug session', - x = 'Toggle debug UI', - }}, - { 'b', group = '[B]uffer', desc = { - p = '[P]revious', - n = '[N]ext', - d = '[D]elete', - D = 'Force [D]elete', - }}, - { 'q', desc = 'Open diagnostic [Q]uickfix list' }, - { 'e', desc = 'Toggle file [E]xplorer' }, - { 'o', desc = 'F[o]cus file explorer' }, - { 'x', desc = 'Close buffer' }, - { 'X', desc = 'Force close buffer' }, - { '/', desc = 'Search in current buffer' }, - { '', desc = 'Find buffers' }, - }, }, + config = function(_, opts) + local wk = require('which-key') + wk.setup(opts) + wk.add({ + { "/", desc = "Search in current buffer" }, + { "", desc = "Find buffers" }, + { "X", desc = "Force close buffer" }, + { "b", group = "[B]uffer" }, + { "bD", desc = "Force [D]elete" }, + { "bd", desc = "Delete buffer" }, + { "bn", desc = "Next buffer" }, + { "bp", desc = "Previous buffer" }, + { "c", group = "[C]ode" }, + { "ca", desc = "Code Action" }, + { "cf", desc = "Format buffer" }, + { "d", desc = "Show diagnostic under cursor" }, + { "ds", desc = "Document symbols" }, + { "dx", desc = "Document diagnostics" }, + { "e", desc = "Toggle file explorer" }, + { "f", group = "[F]ile Explorer" }, + { "fe", desc = "Toggle explorer" }, + { "ff", desc = "Focus explorer" }, + { "g", group = "[G]it" }, + { "gs", desc = "Status" }, + { "h", group = "Git [H]unk" }, + { "n", group = "[N]otifications" }, + { "nc", desc = "Clear notifications" }, + { "nh", desc = "Notification history" }, + { "nn", desc = "Toggle notifications" }, + { "o", desc = "Focus file explorer" }, + { "p", group = "Debug/[P]rofile" }, + { "pb", desc = "Toggle breakpoint" }, + { "pc", desc = "Continue debugging" }, + { "pi", desc = "Step into" }, + { "pl", desc = "Run last debug session" }, + { "pn", desc = "Step over" }, + { "po", desc = "Step out" }, + { "pr", desc = "Open REPL" }, + { "px", desc = "Toggle debug UI" }, + { "q", desc = "Open diagnostic quickfix list" }, + { "s", group = "[S]earch" }, + { "s/", desc = "Search in open files" }, + { "sd", desc = "Diagnostics" }, + { "sf", desc = "Files" }, + { "sg", desc = "Grep" }, + { "sh", desc = "Help" }, + { "sk", desc = "Keymaps" }, + { "sn", desc = "Neovim config files" }, + { "sr", desc = "Resume last search" }, + { "ss", desc = "Select Telescope" }, + { "sw", desc = "Current word" }, + { "t", group = "[T]oggle" }, + { "th", desc = "Toggle inlay hints" }, + { "w", group = "[W]orkspace" }, + { "ws", desc = "Symbols" }, + { "x", desc = "Close buffer" }, + }) + end, } diff --git a/lua/plugins/work/gopls_flags.txt b/lua/plugins/work/gopls_flags.txt new file mode 100644 index 00000000000..1cff4fb4a74 --- /dev/null +++ b/lua/plugins/work/gopls_flags.txt @@ -0,0 +1 @@ +-tags=integration diff --git a/src/main.zen b/src/main.zen deleted file mode 100644 index 066a492c414..00000000000 --- a/src/main.zen +++ /dev/null @@ -1,5 +0,0 @@ -const std = @import("std"); - -pub fn main() anyerror!void { - std.debug.warn("Congratulations on your first step to writing perfect software in Zen.\n", .{}); -} From 2e0d6e1637b7ae633d9fc8b17ac59e340ff6694e Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Tue, 29 Apr 2025 17:45:34 +0200 Subject: [PATCH 12/16] further fixes and mods. still not really done yet --- lua/core/keymaps.lua | 1 + lua/options/settings.lua | 6 ++ lua/plugins/colorscheme.lua | 1 + lua/plugins/dadbod.lua | 1 + lua/plugins/init.lua | 1 + lua/plugins/leap.lua | 1 + lua/plugins/session.lua | 1 + lua/plugins/snacks/init.lua | 4 +- lua/plugins/which-key.lua | 164 +++++++++++++++++++++--------------- 9 files changed, 112 insertions(+), 68 deletions(-) diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index b87c973ecde..5aaca13193e 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) diff --git a/lua/options/settings.lua b/lua/options/settings.lua index b7fa2948fa7..0faa11df2e4 100644 --- a/lua/options/settings.lua +++ b/lua/options/settings.lua @@ -59,6 +59,12 @@ vim.opt.list = true -- Use a vertical bar for tabs so ibl and listchars both show vertical guides vim.opt.listchars = { tab = '│ ', trail = '·', nbsp = '␣' } +-- Set tab size and convert tabs to spaces +vim.opt.tabstop = 2 -- Number of visual spaces per TAB +vim.opt.shiftwidth = 2 -- Number of spaces to use for each step of (auto)indent +vim.opt.softtabstop = 2 -- Number of spaces that a counts for while performing editing operations +vim.opt.expandtab = true -- Use spaces instead of tabs + -- Preview substitutions live, as you type! vim.opt.inccommand = 'split' diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 40f77dd4391..5dc5d2b8937 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global return { -- You can easily change to a different colorscheme. -- Change the name of the colorscheme plugin below, and then -- change the command in the config to whatever the name of that colorscheme is. diff --git a/lua/plugins/dadbod.lua b/lua/plugins/dadbod.lua index b99ce4c1336..6653504fe11 100644 --- a/lua/plugins/dadbod.lua +++ b/lua/plugins/dadbod.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global -- Database explorer and query runner return { 'tpope/vim-dadbod', diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 2639278261a..49aa76a9c7f 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global local plugins = {} local plugin_files = vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/plugins', '*.lua', false, true) diff --git a/lua/plugins/leap.lua b/lua/plugins/leap.lua index 9f8ef2c432c..ec0a15d9ebd 100644 --- a/lua/plugins/leap.lua +++ b/lua/plugins/leap.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global -- Quick navigation plugin return { 'ggandor/leap.nvim', diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua index bfe6be650f7..21addca8795 100644 --- a/lua/plugins/session.lua +++ b/lua/plugins/session.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global return { 'echasnovski/mini.sessions', version = '*', diff --git a/lua/plugins/snacks/init.lua b/lua/plugins/snacks/init.lua index 366e159b672..10bd67c52b4 100644 --- a/lua/plugins/snacks/init.lua +++ b/lua/plugins/snacks/init.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global -- Import all configurations local core = require("plugins.snacks.core") local display = require("plugins.snacks.display") @@ -27,7 +28,6 @@ return { "MunifTanjim/nui.nvim", "echasnovski/mini.nvim", }, - ---@type snacks.Config opts = merge_tables( core, display, @@ -44,6 +44,6 @@ return { end, init = function() -- Make snacks available globally for debugging - _G.Snacks = require("plugins.snacks") + _G.Snacks = require("plugins.snacks.init") end, } diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 1b532fe7b66..332f39a5c58 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -6,73 +6,105 @@ return { -- Useful plugin to show you pending keybinds. icons = { mappings = vim.g.have_nerd_font, keys = vim.g.have_nerd_font and {} or { - Up = ' ', Down = ' ', Left = ' ', Right = ' ', - C = ' ', M = ' ', D = ' ', S = ' ', - CR = ' ', Esc = ' ', ScrollWheelDown = ' ', - ScrollWheelUp = ' ', NL = ' ', BS = ' ', - Space = ' ', Tab = ' ', F1 = '', F2 = '', - F3 = '', F4 = '', F5 = '', F6 = '', - F7 = '', F8 = '', F9 = '', F10 = '', - F11 = '', F12 = '', + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', }, }, + + -- Document existing key chains + spec = { + { 'c', group = '[C]ode', desc = { + a = 'Code [A]ction', + f = '[F]ormat buffer', + }}, + { 'd', group = '[D]ocument', desc = { + x = 'Document [D]iagnostics', + s = 'Document [S]ymbols', + [''] = 'Show diagnostic under cursor', + }}, + { 's', group = '[S]earch', desc = { + h = '[H]elp', + k = '[K]eymaps', + f = '[F]iles', + s = '[S]elect Telescope', + w = 'Current [W]ord', + g = '[G]rep', + d = '[D]iagnostics', + r = '[R]esume last search', + ['/'] = 'Search in open files', + n = '[N]eovim config files', + }}, + { 'l', group = '[L]SP/Language' }, + { 'm', group = '[M]emory/Sessions' }, + { 'D', group = '[D]atabase' }, + { 't', group = '[T]oggle', desc = { + h = 'Toggle inlay [H]ints', + }}, + { 'w', group = '[W]orkspace', desc = { + s = '[S]ymbols', + }}, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'g', group = '[G]it', desc = { + s = 'Status', + }}, + { 'f', group = '[F]ile Explorer', desc = { + e = 'Toggle explorer', + f = 'Focus explorer', + }}, + { 'n', group = '[N]otifications', desc = { + n = 'Toggle notifications', + h = 'Notification [H]istory', + c = '[C]lear notifications', + }}, + { 'p', group = 'Debug/[P]rofile', desc = { + b = 'Toggle [B]reakpoint', + c = '[C]ontinue debugging', + n = 'Step over ([N]ext)', + i = 'Step [I]nto', + o = 'Step [O]ut', + r = 'Open [R]EPL', + l = 'Run [L]ast debug session', + x = 'Toggle debug UI', + }}, + { 'b', group = '[B]uffer', desc = { + p = '[P]revious', + n = '[N]ext', + d = '[D]elete', + D = 'Force [D]elete', + }}, + { 'q', desc = 'Open diagnostic [Q]uickfix list' }, + { 'e', desc = 'Toggle file [E]xplorer' }, + { 'o', desc = 'F[o]cus file explorer' }, + { 'x', desc = 'Close buffer' }, + { 'X', desc = 'Force close buffer' }, + { '/', desc = 'Search in current buffer' }, + { '', desc = 'Find buffers' }, + }, }, - config = function(_, opts) - local wk = require('which-key') - wk.setup(opts) - wk.add({ - { "/", desc = "Search in current buffer" }, - { "", desc = "Find buffers" }, - { "X", desc = "Force close buffer" }, - { "b", group = "[B]uffer" }, - { "bD", desc = "Force [D]elete" }, - { "bd", desc = "Delete buffer" }, - { "bn", desc = "Next buffer" }, - { "bp", desc = "Previous buffer" }, - { "c", group = "[C]ode" }, - { "ca", desc = "Code Action" }, - { "cf", desc = "Format buffer" }, - { "d", desc = "Show diagnostic under cursor" }, - { "ds", desc = "Document symbols" }, - { "dx", desc = "Document diagnostics" }, - { "e", desc = "Toggle file explorer" }, - { "f", group = "[F]ile Explorer" }, - { "fe", desc = "Toggle explorer" }, - { "ff", desc = "Focus explorer" }, - { "g", group = "[G]it" }, - { "gs", desc = "Status" }, - { "h", group = "Git [H]unk" }, - { "n", group = "[N]otifications" }, - { "nc", desc = "Clear notifications" }, - { "nh", desc = "Notification history" }, - { "nn", desc = "Toggle notifications" }, - { "o", desc = "Focus file explorer" }, - { "p", group = "Debug/[P]rofile" }, - { "pb", desc = "Toggle breakpoint" }, - { "pc", desc = "Continue debugging" }, - { "pi", desc = "Step into" }, - { "pl", desc = "Run last debug session" }, - { "pn", desc = "Step over" }, - { "po", desc = "Step out" }, - { "pr", desc = "Open REPL" }, - { "px", desc = "Toggle debug UI" }, - { "q", desc = "Open diagnostic quickfix list" }, - { "s", group = "[S]earch" }, - { "s/", desc = "Search in open files" }, - { "sd", desc = "Diagnostics" }, - { "sf", desc = "Files" }, - { "sg", desc = "Grep" }, - { "sh", desc = "Help" }, - { "sk", desc = "Keymaps" }, - { "sn", desc = "Neovim config files" }, - { "sr", desc = "Resume last search" }, - { "ss", desc = "Select Telescope" }, - { "sw", desc = "Current word" }, - { "t", group = "[T]oggle" }, - { "th", desc = "Toggle inlay hints" }, - { "w", group = "[W]orkspace" }, - { "ws", desc = "Symbols" }, - { "x", desc = "Close buffer" }, - }) - end, } From f6a19a3a7500f4536a86bed072154542f731e93e Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Wed, 30 Apr 2025 14:58:34 +0200 Subject: [PATCH 13/16] added illuminate and some fixes --- lua/plugins/illuminate.lua | 35 +++++++++++++++++++++++++++ lua/plugins/lsp/overrides.lua | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 lua/plugins/illuminate.lua create mode 100644 lua/plugins/lsp/overrides.lua diff --git a/lua/plugins/illuminate.lua b/lua/plugins/illuminate.lua new file mode 100644 index 00000000000..bdef833f1b8 --- /dev/null +++ b/lua/plugins/illuminate.lua @@ -0,0 +1,35 @@ +---@diagnostic disable: undefined-global +return { + 'RRethy/vim-illuminate', + event = { "BufReadPost", "BufNewFile" }, + opts = { + delay = 200, + large_file_cutoff = 2000, + large_file_overrides = { + providers = { "lsp" } + }, + providers = { + 'lsp', + 'treesitter', + 'regex', + }, + min_count_to_highlight = 2, -- minimum number of matches required to perform highlighting + }, + config = function(_, opts) + require('illuminate').configure(opts) + + -- Set highlight style (using colors that match with gruvbox theme) + vim.api.nvim_set_hl(0, 'IlluminatedWordText', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordRead', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordWrite', { bg = '#3c3836', bold = true }) + + -- Map keys to navigate between highlighted words + vim.keymap.set('n', 'hn', function() + require('illuminate').goto_next_reference() + end, { desc = 'Go to next reference' }) + + vim.keymap.set('n', 'hp', function() + require('illuminate').goto_prev_reference() + end, { desc = 'Go to previous reference' }) + end, +} diff --git a/lua/plugins/lsp/overrides.lua b/lua/plugins/lsp/overrides.lua new file mode 100644 index 00000000000..6cfa14f929c --- /dev/null +++ b/lua/plugins/lsp/overrides.lua @@ -0,0 +1,45 @@ +---@diagnostic disable: undefined-global +-- Override internal LSP functions to ensure position_encoding is always set + +local M = {} + +function M.setup() + -- Create a wrapper that ensures position_encoding is added to all calls + local function with_encoding(fn) + return function(params, ...) + params = params or {} + if not params.position_encoding then + params.position_encoding = 'utf-16' + end + return fn(params, ...) + end + end + + -- Override standard LSP buffer functions that may be missing position_encoding + vim.lsp.buf.code_action = with_encoding(vim.lsp.buf.code_action) + vim.lsp.buf.rename = with_encoding(vim.lsp.buf.rename) + vim.lsp.buf.hover = with_encoding(vim.lsp.buf.hover) + vim.lsp.buf.formatting = with_encoding(vim.lsp.buf.formatting) + vim.lsp.buf.range_formatting = with_encoding(vim.lsp.buf.range_formatting) + vim.lsp.buf.format = with_encoding(vim.lsp.buf.format) + + -- Patch util functions as well + local orig_make_position_params = vim.lsp.util.make_position_params + vim.lsp.util.make_position_params = function(window, client, position_encoding) + if not position_encoding then + position_encoding = 'utf-16' + end + return orig_make_position_params(window, client, position_encoding) + end + + -- Override symbols_to_items to ensure position_encoding is set + local orig_symbols_to_items = vim.lsp.util.symbols_to_items + vim.lsp.util.symbols_to_items = function(symbols, bufnr, position_encoding) + if not position_encoding then + position_encoding = 'utf-16' + end + return orig_symbols_to_items(symbols, bufnr, position_encoding) + end +end + +return M From 06d714c9456545757fe23190114232f1cd9b1a75 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Thu, 5 Mar 2026 20:02:43 +0100 Subject: [PATCH 14/16] forgot to push this... lots of changes to add elixir support and other fixes --- .vscode/settings.json | 3 + lua/core/keymaps.lua | 129 ++++++++++++++++-- lua/options/autocmds.lua | 55 ++++++-- lua/plugins/better-hover.lua | 58 +++++++++ lua/plugins/blink-cmp.lua | 12 -- lua/plugins/cmp/setup.lua | 224 ++++++++++++++++++++++++++++++-- lua/plugins/coding.lua | 1 + lua/plugins/coding/dap.lua | 10 ++ lua/plugins/coding/elixir.lua | 38 ++++++ lua/plugins/doc-test.lua | 76 +++++++++++ lua/plugins/hover.lua | 44 +++++++ lua/plugins/lsp/overrides.lua | 72 ++++++---- lua/plugins/lsp/servers.lua | 80 +++++++++++- lua/plugins/lsp/setup.lua | 110 +++++++++++++++- lua/plugins/null-ls.lua | 37 +++++- lua/plugins/null-ls/setup.lua | 1 + lua/plugins/nvim-cmp.lua | 12 +- lua/plugins/nvim-lspconfig.lua | 35 ++++- lua/plugins/nvim-treesitter.lua | 43 ++++-- lua/plugins/which-key.lua | 12 +- 20 files changed, 952 insertions(+), 100 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 lua/plugins/better-hover.lua delete mode 100644 lua/plugins/blink-cmp.lua create mode 100644 lua/plugins/coding/elixir.lua create mode 100644 lua/plugins/doc-test.lua create mode 100644 lua/plugins/hover.lua diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000000..134c17cb445 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "stylua.targetReleaseVersion": "latest" +} \ No newline at end of file diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 5aaca13193e..9d92904f43c 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -12,6 +12,9 @@ vim.g.maplocalleader = ' ' -- - Line/selection movement (Alt + jk) -- - Quick save and quit (w, W, Q) local core_keymaps = { + -- Quick access to find files by content (shortcut for sg) + { mode = 'n', lhs = '', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search text in all files' } }, + -- Clear highlights on search when pressing in normal mode { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, @@ -70,8 +73,38 @@ function M.setup_lsp_keymaps(bufnr) { mode = 'n', lhs = 'gy', rhs = function() require('telescope.builtin').lsp_type_definitions() end, opts = { desc = 'LSP: Go to type definition' } }, -- Symbol navigation - { mode = 'n', lhs = 'ls', rhs = function() require('telescope.builtin').lsp_document_symbols() end, opts = { desc = 'LSP: Document symbols' } }, - { mode = 'n', lhs = 'lS', rhs = function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, opts = { desc = 'LSP: Workspace symbols' } }, + { mode = 'n', lhs = 'ls', rhs = function() + -- Explicitly add position_encoding to fix symbols_to_items error + require('telescope.builtin').lsp_document_symbols({ position_encoding = 'utf-16' }) + end, opts = { desc = 'LSP: Document symbols' } }, + { mode = 'n', lhs = 'lS', rhs = function() + -- Use a safe wrapper to avoid nil indexing errors + local status_ok, _ = pcall(function() + require('telescope.builtin').lsp_dynamic_workspace_symbols({ + position_encoding = 'utf-16', + show_line = true, + fname_width = 50, + symbol_width = 35, + attach_mappings = function(prompt_bufnr) + -- This prevents errors when no results are found + require("telescope.actions").select_default:replace(function() + local entry = require("telescope.actions.state").get_selected_entry() + if not entry then return end + require("telescope.actions").close(prompt_bufnr) + if entry.value and entry.value.filename then + vim.cmd(string.format('edit %s', entry.value.filename)) + vim.api.nvim_win_set_cursor(0, {entry.value.lnum, entry.value.col}) + end + end) + return true + end + }) + end) + + if not status_ok then + vim.notify("Workspace symbols not available for this language server", vim.log.levels.INFO) + end + end, opts = { desc = 'LSP: Workspace symbols' } }, -- Code actions { mode = 'n', lhs = 'lr', rhs = vim.lsp.buf.rename, opts = { desc = 'LSP: Rename symbol' } }, @@ -79,7 +112,7 @@ function M.setup_lsp_keymaps(bufnr) { mode = 'n', lhs = 'lf', rhs = function() vim.lsp.buf.format({ async = true }) end, opts = { desc = 'LSP: Format code' } }, -- Documentation - { mode = 'n', lhs = 'K', rhs = vim.lsp.buf.hover, opts = { desc = 'LSP: Show documentation' } }, + { mode = 'n', lhs = 'K', rhs = function() require('hover').hover() end, opts = { desc = 'Enhanced documentation (hover.nvim)' } }, } -- First clear any existing LSP keymaps for this buffer @@ -162,8 +195,9 @@ M.diagnostic_keymaps = { { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, -- Viewing diagnostics - { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details' } }, + { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details in float' } }, { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Diagnostic: Show list' } }, + { mode = 'n', lhs = 'td', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Diagnostic: Search all diagnostics' } }, } -- Database keymaps (all under D for Database) @@ -223,12 +257,31 @@ M.scratch_keymaps = { -- - : Toggle terminal in float window M.snacks_keymaps = { -- Explorer - { mode = 'n', lhs = 'e', rhs = function() require('snacks.picker').explorer() end, opts = { desc = 'Explorer: Toggle' } }, - { mode = 'n', lhs = 'E', rhs = function() require('snacks.picker').explorer({ reveal = true }) end, opts = { desc = 'Explorer: Focus current file' } }, - { mode = 'n', lhs = 'o', rhs = function() require('snacks.picker').explorer({ reveal = true }) end, opts = { desc = 'Explorer: Focus current file' } }, + { mode = 'n', lhs = 'e', rhs = function() + -- Open explorer in current window + require('snacks').explorer.open() + end, opts = { desc = 'Explorer: Toggle' } }, + + { mode = 'n', lhs = 'E', rhs = function() + -- Reveal current file in explorer + require('snacks').explorer.reveal() + end, opts = { desc = 'Explorer: Focus current file' } }, + + { mode = 'n', lhs = 'o', rhs = function() + -- Open current file in a new tab and focus it + vim.cmd('tab split %') + end, opts = { desc = 'Open current file in new tab' } }, + + -- Custom function to open explorer files in new tabs + { mode = 'n', lhs = 'f', rhs = function() + -- Open explorer in a new tab + vim.cmd('tabnew') + require('snacks').explorer.open() + end, opts = { desc = 'Explorer: Open in new tab' } }, -- Terminal { mode = 'n', lhs = '', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle float window' } }, + { mode = 'n', lhs = 'tc', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle console' } }, } -- Git signs keymaps (all under g for Git) @@ -277,6 +330,35 @@ function M.setup_gitsigns_keymaps() end end +-- Elixir keymaps (using 'x' as the prefix - mnemonic for 'eXlixir') +M.elixir_keymaps = { + { mode = 'n', lhs = 'xt', + rhs = function() + require('elixir').run_test_file() + end, + opts = { desc = 'Elixir: Test file' } + }, + { mode = 'n', lhs = 'xn', + rhs = function() + require('elixir').run_nearest_test() + end, + opts = { desc = 'Elixir: Test nearest' } + }, + { mode = 'n', lhs = 'xm', + rhs = function() + vim.cmd('Telescope elixir mix') + end, + opts = { desc = 'Elixir: Mix tasks' } + }, +} + +-- Set up Elixir keymaps +function M.setup_elixir_keymaps() + for _, mapping in ipairs(M.elixir_keymaps or {}) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + -- Leap keymaps -- 's' for bidirectional search (both forward and backward) -- 'S' for searching in all windows @@ -327,7 +409,7 @@ local function init_keymaps() callback = function() -- Pause snacks explorer updates during write pcall(function() - local picker = require('snacks.picker') + local picker = require('plugins.snacks.picker') if picker.is_open() then picker.pause_updates() vim.schedule(function() @@ -405,12 +487,19 @@ local function init_keymaps() -- Set up database keymaps M.setup_dadbod_keymaps() + + -- Set up default tab navigation + vim.keymap.set('n', 'gt', ':tabnext', { silent = true, desc = 'Next tab' }) + vim.keymap.set('n', 'gT', ':tabprevious', { silent = true, desc = 'Previous tab' }) -- Set up session keymaps M.setup_session_keymaps() -- Set up git signs keymaps M.setup_gitsigns_keymaps() + + -- Set up Elixir keymaps + M.setup_elixir_keymaps() -- Set up leap keymaps M.setup_leap_keymaps() @@ -422,5 +511,29 @@ init_keymaps() -- Export `init_keymaps` as `M.setup` so `require('core.keymaps').setup()` works M.setup = init_keymaps +-- Mini-surround keymaps +-- These define how mini.surround plugin works with text objects +-- sa - add surroundings (visual mode or with motion like saiw) +-- sd - delete surroundings +-- sr - replace surroundings +-- sn - Find next surrounding +-- sN - Find previous surrounding +-- sh - Highlight surrounding +-- sf - Find surrounding (to use with textobject) +-- ss - Go to left surrounding +-- sS - Go to right surrounding +M.mini_surround_keymaps = { + add = 'sa', -- Add surrounding in Normal and Visual modes + delete = 'sd', -- Delete surrounding + find = 'sf', -- Find surrounding (to the right) + find_left = 'sF', -- Find surrounding (to the left) + highlight = 'sh', -- Highlight surrounding + replace = 'sr', -- Replace surrounding + update_n_lines = '', -- Update `n_lines` + + suffix_last = 'l', -- Suffix to search with 'prev' method + suffix_next = 'n', -- Suffix to search with 'next' method +} + -- Return the module return M diff --git a/lua/options/autocmds.lua b/lua/options/autocmds.lua index 88b873369f2..ebe0c0ca3ce 100644 --- a/lua/options/autocmds.lua +++ b/lua/options/autocmds.lua @@ -11,19 +11,58 @@ function M.setup() end, }) - -- Auto format Go files on save - vim.api.nvim_create_autocmd('BufWritePre', { - pattern = '*.go', + + -- Add a smart format-on-save command that only uses null-ls + -- Fix for zig.vim ftplugin error - handles both JSON and struct output + vim.api.nvim_create_autocmd('FileType', { + pattern = 'zig', + group = vim.api.nvim_create_augroup('user-zig-fix', { clear = true }), callback = function() - vim.lsp.buf.format({ async = false }) + if vim.fn.executable('zig') ~= 1 or vim.g.zig_std_dir then return end + + -- First try with --json flag + local handle = io.popen('zig env --json 2>/dev/null') + if handle then + local result = handle:read('*a') + handle:close() + + -- Try to parse as JSON first + local success, env = pcall(vim.fn.json_decode, result) + if success and type(env) == 'table' and env.std_dir then + vim.g.zig_std_dir = env.std_dir + vim.opt_local.path:prepend(env.std_dir) + return + end + end + + -- If JSON parsing failed, try to parse the struct output + handle = io.popen('zig env 2>/dev/null') + if handle then + local result = handle:read('*a') + handle:close() + + -- Extract std_dir from struct output + local std_dir = result:match('%.std_dir%s*=%s*"([^"]+)"') + if std_dir then + vim.g.zig_std_dir = std_dir + vim.opt_local.path:prepend(std_dir) + end + end end, }) - -- Auto format Zig files on save vim.api.nvim_create_autocmd('BufWritePre', { - pattern = '*.zig', - callback = function() - vim.lsp.buf.format({ async = false }) + pattern = '*', + callback = function(args) + local bufnr = args.buf + -- Check if null-ls is the formatter for this buffer + local client = vim.lsp.get_clients({ name = 'null-ls', bufnr = bufnr })[1] + if not client then + return + end + + -- Format the buffer + vim.lsp.buf.format({ bufnr = bufnr, filter = function(c) return c.name == 'null-ls' end, async = false }) end, }) end diff --git a/lua/plugins/better-hover.lua b/lua/plugins/better-hover.lua new file mode 100644 index 00000000000..d79004b6608 --- /dev/null +++ b/lua/plugins/better-hover.lua @@ -0,0 +1,58 @@ +---@diagnostic disable: undefined-global +-- Direct approach to fix hover documentation with custom function +return { + "neovim/nvim-lspconfig", + config = function() + -- Create a direct standalone hover function + local function better_hover() + -- Save original functions we'll temporarily override + local orig_open_floating = vim.lsp.util.open_floating_preview + + -- Replace the floating preview function temporarily + vim.lsp.util.open_floating_preview = function(contents, syntax, opts) + opts = opts or {} + -- Force nicer styling + opts.border = "rounded" + opts.max_width = math.min(math.floor(vim.o.columns * 0.7), 80) + opts.max_height = math.floor(vim.o.lines * 0.3) + + -- Process contents to remove separator lines and improve formatting + local cleaned_contents = {} + for _, line in ipairs(contents) do + -- Skip separator lines + if not line:match("^%-%-%-%-+$") then + table.insert(cleaned_contents, line) + end + end + + -- Call original with improved options and cleaned content + local bufnr, winnr = orig_open_floating(cleaned_contents, syntax, opts) + + -- Enhance the created buffer + if bufnr and winnr then + -- Set better options for the window + vim.api.nvim_win_set_option(winnr, "conceallevel", 2) + vim.api.nvim_win_set_option(winnr, "foldenable", false) + + -- If it's markdown, ensure proper highlighting + if syntax == "markdown" then + vim.api.nvim_buf_set_option(bufnr, "filetype", "markdown") + end + end + + return bufnr, winnr + end + + -- Call the regular hover function with our temporary override + vim.lsp.buf.hover() + + -- Restore original function + vim.lsp.util.open_floating_preview = orig_open_floating + end + + -- Directly override the K keymap - this bypasses any conflicts + vim.keymap.set("n", "K", better_hover, { noremap = true, silent = true, desc = "LSP: Better hover docs" }) + end, + -- Run this after all other LSP configs are loaded + priority = 999, +} diff --git a/lua/plugins/blink-cmp.lua b/lua/plugins/blink-cmp.lua deleted file mode 100644 index d1ec77a6e48..00000000000 --- a/lua/plugins/blink-cmp.lua +++ /dev/null @@ -1,12 +0,0 @@ -return { - 'saghen/blink.cmp', - dependencies = 'rafamadriz/friendly-snippets', - version = '*', - opts = { - keymap = { preset = 'default' }, - appearance = { - use_nvim_cmp_as_default = true, - nerd_font_variant = 'mono', - }, - }, -} diff --git a/lua/plugins/cmp/setup.lua b/lua/plugins/cmp/setup.lua index e02e754d7db..25ffaa9b6e6 100644 --- a/lua/plugins/cmp/setup.lua +++ b/lua/plugins/cmp/setup.lua @@ -5,6 +5,8 @@ local M = {} function M.setup() local cmp = require 'cmp' local luasnip = require 'luasnip' + local types = require 'cmp.types' + local compare = require 'cmp.config.compare' luasnip.config.setup {} cmp.setup { @@ -13,13 +15,127 @@ function M.setup() luasnip.lsp_expand(args.body) end, }, - completion = { completeopt = 'menu,menuone,noinsert' }, + -- Improved completion settings - more like VSCode + completion = { + completeopt = 'menu,menuone,noinsert', + keyword_length = 1, -- Show completions after 1 character + autocomplete = { types.cmp.TriggerEvent.TextChanged }, + get_trigger_characters = function(trigger_characters) + -- Always add '.' as a trigger character to ensure method/property completions + if not vim.tbl_contains(trigger_characters, '.') then + table.insert(trigger_characters, '.') + end + if not vim.tbl_contains(trigger_characters, ':') then + table.insert(trigger_characters, ':') + end + return trigger_characters + end, + }, + -- Custom sorting to prioritize fields and methods over snippets + sorting = { + priority_weight = 10, -- Increase weight to make priority differences more significant + comparators = { + -- Custom comparator that puts snippets at the end + function(entry1, entry2) + local types = require('cmp.types') + + -- Extract the kinds + local kind1 = entry1:get_kind() + local kind2 = entry2:get_kind() + + -- Define snippet kinds + local snippet_kinds = { + [types.lsp.CompletionItemKind.Snippet] = true + } + + -- Check if either is a snippet + local is_snippet1 = snippet_kinds[kind1] or false + local is_snippet2 = snippet_kinds[kind2] or false + + -- If one is a snippet and the other isn't, the non-snippet comes first + if is_snippet1 and not is_snippet2 then + return false + elseif not is_snippet1 and is_snippet2 then + return true + end + + -- Otherwise fall through to other comparators + return nil + end, + compare.exact, -- Exact match first + compare.kind, -- Sort by kind (functions first, then properties, etc) + compare.sort_text, -- Sort by LSP's sortText + compare.score, -- Score based + compare.offset, -- Closest to cursor + compare.length, -- Shorter first + compare.order, -- Source order + }, + }, + -- Enhanced VSCode-like icons with more modern symbols + formatting = { + format = function(entry, vim_item) + -- Set icons for completion types + 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 = "󰊄", TypeAlias = "", Parameter = "", StaticMethod = "", + Macro = "󰁌" + } + + -- Enhanced formatting with better icons and spacing + vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind] or '', vim_item.kind) + + -- Show more detailed source info + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + path = "[Path]", + })[entry.source.name] + + return vim_item + end, + }, + -- Enhanced documentation window + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + col_offset = -3, + side_padding = 1, + }), + documentation = cmp.config.window.bordered({ + winhighlight = "Normal:CmpDoc", + }), + }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), [''] = cmp.mapping.complete {}, [''] = cmp.mapping(function() if luasnip.expand_or_locally_jumpable() then @@ -32,30 +148,112 @@ function M.setup() end end, { 'i', 's' }), }, - sources = { - { name = 'lazydev', group_index = 0 }, - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - { name = 'buffer' }, + -- Configure completion sources by priority with tweaked settings + sources = cmp.config.sources( + { + { name = 'nvim_lsp', priority = 1000, max_item_count = 50 }, -- LSP comes first with more items + { name = 'path', priority = 500 }, -- Then paths + { name = 'buffer', priority = 250, keyword_length = 3 }, -- Then current buffer + -- Snippets with extremely low priority and limited visibility + { name = 'luasnip', priority = 10, max_item_count = 3, keyword_length = 4 }, + } + ), + -- Enable experimental features for VSCode-like experience + experimental = { + ghost_text = true, -- Shows virtual text as preview }, } -- Cmdline completion for search (/, ?) and command (:) + -- Enhanced commandline completion with better history and formatting cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { - { name = 'buffer' } + { name = 'buffer', max_item_count = 20 } + }, + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + }) + }, + completion = { + completeopt = 'menu,menuone,noinsert', } }) cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), + mapping = cmp.mapping.preset.cmdline({ + -- Explicit key mappings for command mode completion + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + cmp.select_next_item() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + cmp.select_prev_item() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + end + end, + }, + [''] = { + c = cmp.mapping.abort(), + }, + [''] = { + c = cmp.mapping.confirm({ select = true }), + }, + }), sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) + { name = 'path', max_item_count = 20 }, + { name = 'cmdline', max_item_count = 30, keyword_length = 1 } + }), + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + col_offset = -3, + side_padding = 1, + }) + }, + formatting = { + format = function(entry, vim_item) + -- Only show item kind for cmdline completion + vim_item.kind = ' ' + vim_item.menu = '' + return vim_item + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + autocomplete = { cmp.TriggerEvent.TextChanged }, + } }) end diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index 3b4e3809a55..1e0c8bb1f3e 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -4,4 +4,5 @@ return { require('plugins.coding.zig'), require('plugins.coding.clangd'), require('plugins.coding.dap'), + require('plugins.coding.elixir'), } diff --git a/lua/plugins/coding/dap.lua b/lua/plugins/coding/dap.lua index 97f0a5a1243..3ca97094641 100644 --- a/lua/plugins/coding/dap.lua +++ b/lua/plugins/coding/dap.lua @@ -1,6 +1,16 @@ ---@diagnostic disable: undefined-global return { "mfussenegger/nvim-dap", + keys = { + { "pb", desc = "Toggle [B]reakpoint" }, + { "pc", desc = "[C]ontinue debugging" }, + { "pn", desc = "Step over ([N]ext)" }, + { "pi", desc = "Step [I]nto" }, + { "po", desc = "Step [O]ut" }, + { "pr", desc = "Open [R]EPL" }, + { "pl", desc = "Run [L]ast debug session" }, + { "px", desc = "Toggle debug UI" }, + }, dependencies = { "rcarriga/nvim-dap-ui", "theHamsta/nvim-dap-virtual-text", diff --git a/lua/plugins/coding/elixir.lua b/lua/plugins/coding/elixir.lua new file mode 100644 index 00000000000..3b0651b640c --- /dev/null +++ b/lua/plugins/coding/elixir.lua @@ -0,0 +1,38 @@ +return { + { + 'elixir-tools/elixir-tools.nvim', + version = '*', + ft = { 'ex', 'exs', 'heex', 'eex', 'elixir' }, + dependencies = { + 'neovim/nvim-lspconfig', + 'nvim-lua/plenary.nvim', + }, + config = function() + local elixir = require('elixir') + + -- Configure elixir-tools with LSP disabled (handled by lspconfig) + elixir.setup({ + -- Disable the built-in LSP client to avoid conflicts + elixirls = { enable = false }, + + -- Enable non-LSP features + credo = { enable = true }, + projectionist = { enable = true }, + + -- Configure the test runner + test_runner = { + enabled = true, + runner = 'exunit', -- or 'exunit_individual' for individual test runs + }, + + -- Enable mix integration + mix = { + enabled = true, + format_on_save = false, -- Disabled to prevent file changed warnings + }, + }) + + -- Keymaps are now in core/keymaps.lua with lx prefix + end, + }, +} diff --git a/lua/plugins/doc-test.lua b/lua/plugins/doc-test.lua new file mode 100644 index 00000000000..596b47152a0 --- /dev/null +++ b/lua/plugins/doc-test.lua @@ -0,0 +1,76 @@ +---@diagnostic disable: undefined-global +-- Test doc window plugin +return { + "neovim/nvim-lspconfig", + config = function() + -- Create a test function that shows a styled floating window + local function test_doc_window() + local contents = { + "## Documentation Test", + "", + "This is a test documentation window to see how styling works.", + "", + "**Important**: This shows what documentation *should* look like.", + "", + "```lua", + "function example(param)", + " -- This is a code sample", + " return param + 1", + "end", + "```", + } + + -- Create a nicely styled window + local opts = { + border = "rounded", + width = 60, + height = 12, + wrap = true, + pad_left = 1, + pad_right = 1, + } + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, contents) + vim.api.nvim_buf_set_option(bufnr, "filetype", "markdown") + + -- Position the window near the cursor + local cursor_pos = vim.api.nvim_win_get_cursor(0) + local row = cursor_pos[1] + local col = cursor_pos[2] + + -- Calculate position + local ui = vim.api.nvim_list_uis()[1] + local width = opts.width or 60 + local height = opts.height or 12 + local anchor = "NW" + local col_offset = 0 + + -- Open the window + local winnr = vim.api.nvim_open_win(bufnr, false, { + relative = "cursor", + row = 1, + col = col_offset, + width = width, + height = height, + style = "minimal", + border = opts.border, + anchor = anchor, + }) + + -- Set window options + vim.api.nvim_win_set_option(winnr, "conceallevel", 2) + vim.api.nvim_win_set_option(winnr, "concealcursor", "n") + vim.api.nvim_win_set_option(winnr, "winblend", 0) + + -- Return window and buffer numbers + return bufnr, winnr + end + + -- Add a command to test the documentation window + vim.api.nvim_create_user_command("TestDocWindow", test_doc_window, {}) + + -- Also map it to a key for easy testing + vim.keymap.set("n", "td", test_doc_window, { desc = "Test doc window styling" }) + end +} diff --git a/lua/plugins/hover.lua b/lua/plugins/hover.lua new file mode 100644 index 00000000000..c8a187ce326 --- /dev/null +++ b/lua/plugins/hover.lua @@ -0,0 +1,44 @@ +---@diagnostic disable: undefined-global +return { + 'lewis6991/hover.nvim', + event = 'VeryLazy', + config = function() + require('hover').setup({ + init = function() + -- Required for hover.nvim + require('hover.providers.lsp') + -- Optional additional providers + require('hover.providers.gh') + require('hover.providers.man') + require('hover.providers.dictionary') + end, + preview_opts = { + border = 'rounded', + width = 80, + height = 20, + }, + title = true, + -- Key mappings + -- Use the same mapping as before ('K') + mappings = { + toggle_hover = 'K', + -- Scroll option + scroll_up = '', + scroll_down = '', + }, + }) + + -- Style adjustments + vim.api.nvim_set_hl(0, 'HoverFloat', { link = 'Normal' }) + vim.api.nvim_set_hl(0, 'HoverFloatBorder', { link = 'FloatBorder' }) + + -- Override the LSP hover handler to ensure our hover.nvim is used + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + -- Clear and override the K mapping to ensure it uses hover.nvim + vim.keymap.set('n', 'K', require('hover').hover, + { buffer = args.buf, desc = 'Enhanced documentation (hover.nvim)' }) + end, + }) + end, +} diff --git a/lua/plugins/lsp/overrides.lua b/lua/plugins/lsp/overrides.lua index 6cfa14f929c..9f7e5ad8a78 100644 --- a/lua/plugins/lsp/overrides.lua +++ b/lua/plugins/lsp/overrides.lua @@ -4,41 +4,57 @@ local M = {} function M.setup() - -- Create a wrapper that ensures position_encoding is added to all calls - local function with_encoding(fn) - return function(params, ...) - params = params or {} - if not params.position_encoding then - params.position_encoding = 'utf-16' - end - return fn(params, ...) + -- Patch the symbols_to_items function to always use utf-16 encoding + -- and handle nil values safely + local original_symbols_to_items = vim.lsp.util.symbols_to_items + vim.lsp.util.symbols_to_items = function(symbols, bufnr, position_encoding) + -- Default to utf-16 if not specified + position_encoding = position_encoding or 'utf-16' + + -- Add extra safety checks for nil values + if not symbols or type(symbols) ~= 'table' then + return {} end + + -- Call original with proper encoding + return original_symbols_to_items(symbols, bufnr, position_encoding) end - - -- Override standard LSP buffer functions that may be missing position_encoding - vim.lsp.buf.code_action = with_encoding(vim.lsp.buf.code_action) - vim.lsp.buf.rename = with_encoding(vim.lsp.buf.rename) - vim.lsp.buf.hover = with_encoding(vim.lsp.buf.hover) - vim.lsp.buf.formatting = with_encoding(vim.lsp.buf.formatting) - vim.lsp.buf.range_formatting = with_encoding(vim.lsp.buf.range_formatting) - vim.lsp.buf.format = with_encoding(vim.lsp.buf.format) - -- Patch util functions as well - local orig_make_position_params = vim.lsp.util.make_position_params - vim.lsp.util.make_position_params = function(window, client, position_encoding) - if not position_encoding then - position_encoding = 'utf-16' + -- Patch workspace_symbol handler to be safer + vim.lsp.handlers['workspace/symbol'] = function(err, result, ctx, config) + if err or not result or vim.tbl_isempty(result) then + return {} + end + + -- Set a default position_encoding + local position_encoding = 'utf-16' + local client = vim.lsp.get_client_by_id(ctx.client_id) + if client and client.offset_encoding then + position_encoding = client.offset_encoding end - return orig_make_position_params(window, client, position_encoding) + + -- Process safely + local items = vim.lsp.util.symbols_to_items(result, nil, position_encoding) or {} + return items end - -- Override symbols_to_items to ensure position_encoding is set - local orig_symbols_to_items = vim.lsp.util.symbols_to_items - vim.lsp.util.symbols_to_items = function(symbols, bufnr, position_encoding) - if not position_encoding then - position_encoding = 'utf-16' + -- Patch all lsp_* functions in telescope.builtin to include position_encoding + local telescope_builtin = require('telescope.builtin') + local telescope_funcs = { + 'lsp_references', 'lsp_definitions', 'lsp_implementations', + 'lsp_type_definitions', 'lsp_document_symbols', 'lsp_workspace_symbols', + 'lsp_dynamic_workspace_symbols' + } + + for _, func_name in ipairs(telescope_funcs) do + local original_func = telescope_builtin[func_name] + telescope_builtin[func_name] = function(opts) + opts = opts or {} + if not opts.position_encoding then + opts.position_encoding = 'utf-16' + end + return original_func(opts) end - return orig_symbols_to_items(symbols, bufnr, position_encoding) end end diff --git a/lua/plugins/lsp/servers.lua b/lua/plugins/lsp/servers.lua index 3b8d96061e9..89327ed16bd 100644 --- a/lua/plugins/lsp/servers.lua +++ b/lua/plugins/lsp/servers.lua @@ -55,7 +55,72 @@ return { }, }, -- C/C++ - clangd = {}, + clangd = { + cmd = { + 'clangd', + '--background-index', + '--clang-tidy', + '--header-insertion=iwyu', + '--completion-style=detailed', + '--function-arg-placeholders', + '--fallback-style=llvm', + }, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true, + }, + on_attach = function(client, bufnr) + -- Set the correct standard based on filetype + local filetype = vim.bo[bufnr].filetype + if filetype == 'c' then + client.config.init_options.fallbackFlags = { '-std=c23' } + elseif filetype == 'cpp' then + client.config.init_options.fallbackFlags = { '-std=c++23' } + end + + -- Call the default on_attach to setup keymaps and navic + require('plugins.lsp.setup').default_on_attach(client, bufnr) + end, + settings = { + clangd = { + InlayHints = { + Designators = true, + Enabled = true, + ParameterNames = true, + DeducedTypes = true, + }, + }, + }, + }, + + -- Zig + zls = { + settings = { + zls = { + -- Enable semantic highlighting + enable_semantic_tokens = true, + -- Enable inlay hints for better code understanding + enable_inlay_hints = true, + -- Enable snippets + enable_snippets = true, + -- Enable auto-fixing + enable_autofix = true, + -- Warn about style issues + warn_style = true, + -- Highlight global variables + highlight_global_var_declarations = true, + -- Enable build-on-save for faster feedback + enable_build_on_save = true, + -- Skip std library references for better performance + skip_std_references = false, + -- Prefer ast-check over zig fmt for faster response + prefer_ast_check_as_child_process = true, + -- Enable import embedfile argument completions + enable_import_embedfile_argument_completions = true, + }, + }, + }, -- SQL sqls = { @@ -66,4 +131,17 @@ return { }, }, }, + + -- Elixir + elixirls = { + cmd = { 'elixir-ls' }, + settings = { + elixirLS = { + dialyzerEnabled = true, + fetchDeps = true, + enableTestLenses = true, + suggestSpecs = true, + } + } + } } diff --git a/lua/plugins/lsp/setup.lua b/lua/plugins/lsp/setup.lua index d5cb7b907ec..4ea1960e18f 100644 --- a/lua/plugins/lsp/setup.lua +++ b/lua/plugins/lsp/setup.lua @@ -4,10 +4,50 @@ local M = {} function M.setup() + -- Apply LSP function overrides for position_encoding + require('plugins.lsp.overrides').setup() + local servers = require('plugins.lsp.servers') - -- nvim-cmp capabilities + -- Enhanced nvim-cmp capabilities (VSCode-like) local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem = { + documentationFormat = { 'markdown', 'plaintext' }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { valueSet = { 1 } }, + resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + }, + }, + } + -- Complete with all available methods and properties + capabilities.textDocument.completion.completionList = { + itemDefaults = { + 'commitCharacters', + 'editRange', + 'insertTextFormat', + 'insertTextMode', + 'data', + }, + } + -- Add semantic tokens for better syntax highlighting + capabilities.textDocument.semanticTokens = { + tokenTypes = { 'namespace', 'type', 'class', 'enum', 'interface', 'struct', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'event', 'function', 'method', 'macro', 'keyword', 'modifier', 'comment', 'string', 'number', 'regexp', 'operator', 'decorator' }, + tokenModifiers = { 'declaration', 'definition', 'readonly', 'static', 'deprecated', 'abstract', 'async', 'modification', 'documentation', 'defaultLibrary' }, + formats = { 'relative' }, + requests = { + range = true, + full = true, + }, + } capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- Setup mason-lspconfig @@ -20,16 +60,27 @@ function M.setup() config.capabilities = capabilities -- Default on_attach to setup keymaps & navic - local function on_attach(client, bufnr) + M.default_on_attach = function(client, bufnr) require('core.keymaps').setup_lsp_keymaps(bufnr) - -- Attach navic if available - if client.server_capabilities.documentSymbolProvider then - require('nvim-navic').attach(client, bufnr) + + -- Only attach navic if: + -- 1. The client supports document symbols + -- 2. The client isn't elixirls (handled by elixir-tools.nvim) + if client.server_capabilities.documentSymbolProvider + and client.name ~= 'elixirls' then + local status_ok, _ = pcall(require, 'nvim-navic') + if status_ok then + require('nvim-navic').attach(client, bufnr) + end end end - config.on_attach = on_attach + + -- Only set the default on_attach if one isn't already provided + if not config.on_attach then + config.on_attach = M.default_on_attach + end - -- Disable gopls semantic tokens to avoid issues + -- Enhance LSP capabilities for specific servers if server_name == 'gopls' and config.on_attach then local orig_on_attach = config.on_attach config.on_attach = function(client, bufnr) @@ -37,11 +88,56 @@ function M.setup() orig_on_attach(client, bufnr) end end + + -- Force all LSP servers to use incremental completions (like VSCode) + if not config.settings then config.settings = {} end + if not config.settings.completions then config.settings.completions = {} end + config.settings.completions.completeFunctionCalls = true + + -- Enhanced settings for Lua LSP + if server_name == 'lua_ls' then + if not config.settings.Lua then config.settings.Lua = {} end + config.settings.Lua.completion = { + callSnippet = "Replace", + showWord = "Disable", + workspaceWord = false, + displayContext = 5, + keywordSnippet = "Both", + postfix = ".", + } + -- More comprehensive inferencing + config.settings.Lua.hint = { + enable = true, + setType = true, + paramType = true, + paramName = "Literal", + arrayIndex = "Enable", + } + -- Better type resolution + config.settings.Lua.type = { + castNumberToInteger = true, + } + -- Add standard Lua libraries for better completion + if not config.settings.Lua.workspace then config.settings.Lua.workspace = {} end + if not config.settings.Lua.workspace.library then config.settings.Lua.workspace.library = {} end + + -- Include standard libraries + local lua_types = vim.fn.expand('~/.local/share/nvim/mason/packages/lua-language-server/libexec/meta/3rd') + if vim.fn.isdirectory(lua_types) == 1 then + config.settings.Lua.workspace.library[lua_types] = true + end + -- Enable all features + config.settings.Lua.hover = { enable = true, expandAlias = true } + config.settings.Lua.signatureHelp = { enable = true } + config.settings.Lua.diagnostics = { enable = true, globals = { "vim" } } + end require('lspconfig')[server_name].setup(config) end, } + -- Hover handler will now be provided by Blink + -- Override references handler vim.lsp.handlers['textDocument/references'] = function(err, result, ctx, config) if not result or vim.tbl_isempty(result) then diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua index 3c41d5a80ac..d1e64f41472 100644 --- a/lua/plugins/null-ls.lua +++ b/lua/plugins/null-ls.lua @@ -1,10 +1,43 @@ -return { +---@diagnostic disable: undefined-global +local vim = vim + +local M = { 'nvimtools/none-ls.nvim', event = { 'BufReadPre', 'BufNewFile' }, dependencies = { 'jay-babu/mason-null-ls.nvim', }, config = function() - require('plugins.null-ls.setup').setup() + -- Safely require null-ls + local ok, null_ls = pcall(require, 'null-ls') + if not ok then + vim.notify('Failed to load null-ls', vim.log.levels.ERROR) + return + end + + -- Safely require setup + local setup_ok, setup = pcall(require, 'plugins.null-ls.setup') + if not setup_ok or type(setup.setup) ~= 'function' then + vim.notify('Failed to load null-ls setup', vim.log.levels.ERROR) + return + end + + -- Initialize null-ls + setup.setup() + + -- Additional safety check for sources + vim.defer_fn(function() + if not null_ls or not null_ls.get_sources then + vim.notify('null-ls sources not available', vim.log.levels.WARN) + return + end + + local sources = null_ls.get_sources() + if #sources == 0 then + vim.notify('No null-ls sources registered', vim.log.levels.WARN) + end + end, 1000) -- Check after 1 second end, } + +return M diff --git a/lua/plugins/null-ls/setup.lua b/lua/plugins/null-ls/setup.lua index d36235ed9d9..2159d2d3b5b 100644 --- a/lua/plugins/null-ls/setup.lua +++ b/lua/plugins/null-ls/setup.lua @@ -9,6 +9,7 @@ function M.setup() local diagnostics = null_ls.builtins.diagnostics null_ls.setup { + root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), timeout = 10000, debounce = 250, diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua index 62b45888899..25054fd678f 100644 --- a/lua/plugins/nvim-cmp.lua +++ b/lua/plugins/nvim-cmp.lua @@ -19,12 +19,12 @@ return { -- Autocompletion -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, }, }, 'saadparwaiz1/cmp_luasnip', diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index 55134df3c0b..e672a006052 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -4,13 +4,42 @@ local go_flags = 'integration' -- add the tags here, instead of searching it bel return { -- Main LSP Configuration 'neovim/nvim-lspconfig', + event = { "BufReadPre", "BufNewFile" }, dependencies = { -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants - 'williamboman/mason-lspconfig.nvim', + { + 'williamboman/mason.nvim', + cmd = { "Mason", "MasonInstall", "MasonUpdate" }, + config = function() + require("mason").setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + }, + border = "rounded", + width = 0.8, + height = 0.9, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, + }) + end + }, + { + 'williamboman/mason-lspconfig.nvim', + dependencies = { 'williamboman/mason.nvim' }, + config = function() + require("mason-lspconfig").setup({ + automatic_installation = true + }) + end + }, -- 'folke/neodev.nvim', -- Adds support for Neovim Lua API -- No longer needed with lazydev { 'WhoIsSethDaniel/mason-tool-installer.nvim', + event = "VeryLazy", config = function() require('mason-tool-installer').setup { ensure_installed = { @@ -35,6 +64,8 @@ return { 'debugpy', -- Python debugger -- SQL tools 'sqls', -- Advanced SQL LSP + -- Elixir + 'elixir-ls' -- Elixir LSP }, auto_update = true, run_on_start = true, diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua index fdb866264bb..0a38e72d853 100644 --- a/lua/plugins/nvim-treesitter.lua +++ b/lua/plugins/nvim-treesitter.lua @@ -1,22 +1,49 @@ -return { -- Highlight, edit, and navigate code +return { + -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + build = function() + local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) + ts_update() + -- Install C++ parser explicitly to avoid tarball issues + vim.cmd('silent! TSInstall cpp') + end, main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + -- List of languages to ensure are installed + ensure_installed = { + 'bash', 'c', 'cpp', 'diff', 'html', 'lua', 'luadoc', + 'markdown', 'markdown_inline', 'python', 'rust', + 'javascript', 'typescript', 'json', 'yaml', 'query', + 'vim', 'vimdoc', 'comment', 'regex' + }, + -- Install parsers synchronously (only applied to `ensure_installed`) sync_install = false, + -- Automatically install missing parsers when entering buffer auto_install = true, - ignore_install = {}, + -- List of parsers to ignore installing (for "all") + ignore_install = { 'phpdoc' }, highlight = { enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. + -- Additional filetypes to enable highlighting for additional_vim_regex_highlighting = { 'ruby' }, + -- Disable for large files + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + }, + indent = { + enable = true, + disable = { 'ruby', 'yaml' } }, - indent = { enable = true, disable = { 'ruby' } }, }, -- There are additional nvim-treesitter modules that you can use to interact -- with nvim-treesitter. You should go explore a few and see what interests you: diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 332f39a5c58..5080897ea64 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-global return { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' @@ -63,12 +64,12 @@ return { -- Useful plugin to show you pending keybinds. { 'l', group = '[L]SP/Language' }, { 'm', group = '[M]emory/Sessions' }, { 'D', group = '[D]atabase' }, - { 't', group = '[T]oggle', desc = { - h = 'Toggle inlay [H]ints', - }}, - { 'w', group = '[W]orkspace', desc = { - s = '[S]ymbols', + { 't', group = '[T]roubleshooting', desc = { + d = 'Search all [D]iagnostics', + l = 'Diagnostics in [L]ocation list', + t = 'Diagnostic details in floa[T]', }}, + { 'w', desc = 'Save file' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, { 'g', group = '[G]it', desc = { s = 'Status', @@ -105,6 +106,7 @@ return { -- Useful plugin to show you pending keybinds. { 'X', desc = 'Force close buffer' }, { '/', desc = 'Search in current buffer' }, { '', desc = 'Find buffers' }, + { '', desc = 'Search text in all files' }, }, }, } From e408a538582b2c66e8cab56dc6f7171f643a42d9 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Thu, 7 May 2026 17:09:35 +0200 Subject: [PATCH 15/16] massive cleanup, shaved off quite a bit on startup, now roughly 50ms --- lua/core/keymaps.lua | 539 -------------------------------- lua/core/keymaps/core.lua | 36 +++ lua/core/keymaps/diagnostic.lua | 13 + lua/core/keymaps/git.lua | 37 +++ lua/core/keymaps/init.lua | 122 ++++++++ lua/core/keymaps/lsp.lua | 70 +++++ lua/core/keymaps/plugins.lua | 120 +++++++ lua/core/keymaps/telescope.lua | 32 ++ lua/options/autocmds.lua | 48 ++- lua/options/settings.lua | 7 +- lua/plugins/better-hover.lua | 58 ---- lua/plugins/doc-test.lua | 76 ----- lua/plugins/leap.lua | 4 +- lua/plugins/lsp/setup.lua | 11 +- lua/plugins/mini-surround.lua | 2 +- lua/plugins/nvim-autopairs.lua | 2 +- lua/plugins/nvim-lspconfig.lua | 2 +- lua/plugins/session.lua | 48 +-- 18 files changed, 475 insertions(+), 752 deletions(-) delete mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/keymaps/core.lua create mode 100644 lua/core/keymaps/diagnostic.lua create mode 100644 lua/core/keymaps/git.lua create mode 100644 lua/core/keymaps/init.lua create mode 100644 lua/core/keymaps/lsp.lua create mode 100644 lua/core/keymaps/plugins.lua create mode 100644 lua/core/keymaps/telescope.lua delete mode 100644 lua/plugins/better-hover.lua delete mode 100644 lua/plugins/doc-test.lua diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua deleted file mode 100644 index 9d92904f43c..00000000000 --- a/lua/core/keymaps.lua +++ /dev/null @@ -1,539 +0,0 @@ ----@diagnostic disable: undefined-global --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- Core Neovim keymaps (non-plugin) --- These are basic Neovim operations like: --- - Window navigation (Ctrl + hjkl) --- - Window resizing (Ctrl + Arrow keys) --- - Line/selection movement (Alt + jk) --- - Quick save and quit (w, W, Q) -local core_keymaps = { - -- Quick access to find files by content (shortcut for sg) - { mode = 'n', lhs = '', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search text in all files' } }, - - -- Clear highlights on search when pressing in normal mode - { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, - - -- Exit terminal mode with a more discoverable shortcut - { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, - - -- Window navigation (Ctrl + hjkl) - { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window left' } }, - { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window right' } }, - { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window down' } }, - { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window up' } }, - - -- Window resizing (Ctrl + Arrow keys) - { mode = 'n', lhs = '', rhs = 'resize +2', opts = { desc = 'Window: Increase height' } }, - { mode = 'n', lhs = '', rhs = 'resize -2', opts = { desc = 'Window: Decrease height' } }, - { mode = 'n', lhs = '', rhs = 'vertical resize -2', opts = { desc = 'Window: Decrease width' } }, - { mode = 'n', lhs = '', rhs = 'vertical resize +2', opts = { desc = 'Window: Increase width' } }, - - -- Move lines up and down (Alt + jk) - { mode = 'n', lhs = '', rhs = ':m .+1==', opts = { desc = 'Move line down', silent = true } }, - { mode = 'n', lhs = '', rhs = ':m .-2==', opts = { desc = 'Move line up', silent = true } }, - { mode = 'v', lhs = '', rhs = ":m '>+1gv=gv", opts = { desc = 'Move selection down', silent = true } }, - { mode = 'v', lhs = '', rhs = ":m '<-2gv=gv", opts = { desc = 'Move selection up', silent = true } }, - - -- Quick save and quit - { mode = 'n', lhs = 'w', rhs = 'w', opts = { desc = 'Save file' } }, - { mode = 'n', lhs = 'W', rhs = 'wa', opts = { desc = 'Save all files' } }, - { mode = 'n', lhs = 'Q', rhs = 'qa', opts = { desc = 'Quit all' } }, -} - --- LSP keymaps - these will be set up when LSP attaches to a buffer --- Navigation: --- - gd: Go to definition --- - gr: Find references --- - gI: Go to implementation --- - gy: Go to type definition --- --- Workspace: --- - ls: Document symbols --- - lS: Workspace symbols --- --- Code Actions: --- - lr: Rename symbol --- - la: Code action --- - lf: Format code --- --- Documentation: --- - K: Show documentation -local M = {} -function M.setup_lsp_keymaps(bufnr) - local keymaps = { - -- Go to definitions - { mode = 'n', lhs = 'gd', rhs = function() require('telescope.builtin').lsp_definitions() end, opts = { desc = 'LSP: Go to definition' } }, - { mode = 'n', lhs = 'gr', rhs = function() require('telescope.builtin').lsp_references() end, opts = { desc = 'LSP: Find references' } }, - { mode = 'n', lhs = 'gI', rhs = function() require('telescope.builtin').lsp_implementations() end, opts = { desc = 'LSP: Go to implementation' } }, - { mode = 'n', lhs = 'gy', rhs = function() require('telescope.builtin').lsp_type_definitions() end, opts = { desc = 'LSP: Go to type definition' } }, - - -- Symbol navigation - { mode = 'n', lhs = 'ls', rhs = function() - -- Explicitly add position_encoding to fix symbols_to_items error - require('telescope.builtin').lsp_document_symbols({ position_encoding = 'utf-16' }) - end, opts = { desc = 'LSP: Document symbols' } }, - { mode = 'n', lhs = 'lS', rhs = function() - -- Use a safe wrapper to avoid nil indexing errors - local status_ok, _ = pcall(function() - require('telescope.builtin').lsp_dynamic_workspace_symbols({ - position_encoding = 'utf-16', - show_line = true, - fname_width = 50, - symbol_width = 35, - attach_mappings = function(prompt_bufnr) - -- This prevents errors when no results are found - require("telescope.actions").select_default:replace(function() - local entry = require("telescope.actions.state").get_selected_entry() - if not entry then return end - require("telescope.actions").close(prompt_bufnr) - if entry.value and entry.value.filename then - vim.cmd(string.format('edit %s', entry.value.filename)) - vim.api.nvim_win_set_cursor(0, {entry.value.lnum, entry.value.col}) - end - end) - return true - end - }) - end) - - if not status_ok then - vim.notify("Workspace symbols not available for this language server", vim.log.levels.INFO) - end - end, opts = { desc = 'LSP: Workspace symbols' } }, - - -- Code actions - { mode = 'n', lhs = 'lr', rhs = vim.lsp.buf.rename, opts = { desc = 'LSP: Rename symbol' } }, - { mode = 'n', lhs = 'la', rhs = vim.lsp.buf.code_action, opts = { desc = 'LSP: Code action' } }, - { mode = 'n', lhs = 'lf', rhs = function() vim.lsp.buf.format({ async = true }) end, opts = { desc = 'LSP: Format code' } }, - - -- Documentation - { mode = 'n', lhs = 'K', rhs = function() require('hover').hover() end, opts = { desc = 'Enhanced documentation (hover.nvim)' } }, - } - - -- First clear any existing LSP keymaps for this buffer - local lsp_maps = { 'gd', 'gr', 'gI', 'gy', 'K', - 'ls', 'lS', 'lr', 'la', 'lf' } - for _, lhs in ipairs(lsp_maps) do - pcall(vim.keymap.del, 'n', lhs, { buffer = bufnr }) - end - - -- Then set our keymaps with buffer local - for _, mapping in ipairs(keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { - buffer = bufnr, - replace_keycodes = false, - nowait = true, - silent = true, - })) - end -end - --- Telescope keymaps (all under s for Search) --- Help: --- - sh: Search help tags --- - sk: Search keymaps --- --- Files: --- - sf: Find files --- - sr: Recent files --- --- Text Search: --- - sg: Live grep in workspace --- - sw: Search word under cursor --- - /: Fuzzy find in current buffer --- - s/: Live grep in open files --- --- Workspace: --- - sd: Search diagnostics --- - sb: Search buffers -M.telescope_keymaps = { - -- Help - { mode = 'n', lhs = 'sh', rhs = function() require('telescope.builtin').help_tags() end, opts = { desc = 'Search: Help' } }, - { mode = 'n', lhs = 'sk', rhs = function() require('telescope.builtin').keymaps() end, opts = { desc = 'Search: Keymaps' } }, - - -- Files - { mode = 'n', lhs = 'sf', rhs = function() require('telescope.builtin').find_files() end, opts = { desc = 'Search: Files' } }, - { mode = 'n', lhs = 'sr', rhs = function() require('telescope.builtin').oldfiles() end, opts = { desc = 'Search: Recent files' } }, - - -- Text - { mode = 'n', lhs = 'sg', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search: Text in workspace' } }, - { mode = 'n', lhs = 'sw', rhs = function() require('telescope.builtin').grep_string() end, opts = { desc = 'Search: Word under cursor' } }, - { mode = 'n', lhs = '/', rhs = function() - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, opts = { desc = 'Search: Text in buffer' } }, - { mode = 'n', lhs = 's/', rhs = function() - require('telescope.builtin').live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, opts = { desc = 'Search: Text in open files' } }, - - -- Workspace - { mode = 'n', lhs = 'sd', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Search: Diagnostics' } }, - { mode = 'n', lhs = 'sb', rhs = function() require('telescope.builtin').buffers() end, opts = { desc = 'Search: Buffers' } }, -} - --- Diagnostic keymaps --- Navigation: --- - [d: Previous diagnostic --- - ]d: Next diagnostic --- --- Viewing: --- - tt: Show diagnostic details in float --- - tl: Show diagnostics in location list -M.diagnostic_keymaps = { - -- Navigation - { mode = 'n', lhs = '[d', rhs = vim.diagnostic.goto_prev, opts = { desc = 'Diagnostic: Previous' } }, - { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, - - -- Viewing diagnostics - { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details in float' } }, - { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Diagnostic: Show list' } }, - { mode = 'n', lhs = 'td', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Diagnostic: Search all diagnostics' } }, -} - --- Database keymaps (all under D for Database) --- UI: --- - Dt: Toggle database UI --- - Df: Find database buffer --- - Dr: Rename database buffer --- - Dl: Show last query info -M.dadbod_keymaps = { - { mode = 'n', lhs = 'Dt', rhs = 'DBUIToggle', opts = { desc = 'Database: Toggle UI' } }, - { mode = 'n', lhs = 'Df', rhs = 'DBUIFindBuffer', opts = { desc = 'Database: Find buffer' } }, - { mode = 'n', lhs = 'Dr', rhs = 'DBUIRenameBuffer', opts = { desc = 'Database: Rename buffer' } }, - { mode = 'n', lhs = 'Dl', rhs = 'DBUILastQueryInfo', opts = { desc = 'Database: Last query' } }, -} - --- Session management keymaps (all under m for Memory) --- Session Operations: --- - mw: Write/save current session --- - mr: Read/restore saved session --- - md: Delete saved session -M.session_keymaps = { - { mode = 'n', lhs = 'mw', rhs = function() - local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') - require('mini.sessions').write(name, { force = true }) - end, opts = { desc = 'Memory: Write session' } }, - { mode = 'n', lhs = 'mr', rhs = function() - local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') - require('mini.sessions').read(name) - end, opts = { desc = 'Memory: Read session' } }, - { mode = 'n', lhs = 'md', rhs = function() - local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') - require('mini.sessions').delete(name) - end, opts = { desc = 'Memory: Delete session' } }, -} - --- Scratch buffer keymaps --- Buffer Operations: --- - .: Toggle scratch buffer --- - S: Select scratch buffer --- - nh: Show notification history -M.scratch_keymaps = { - { mode = 'n', lhs = '.', rhs = function() require("snacks").scratch() end, - opts = { desc = 'Toggle scratch buffer' } }, - { mode = 'n', lhs = 'S', rhs = function() require("snacks").scratch.select() end, - opts = { desc = 'Select scratch buffer' } }, - { mode = 'n', lhs = 'nh', rhs = function() require("snacks.notifier").show_history() end, - opts = { desc = 'Show notification history' } }, -} - --- Snacks keymaps (explorer and other features) --- File Explorer: --- - e: Toggle explorer --- - E: Focus current file in explorer --- - o: Alternative key to focus current file --- --- Terminal: --- - : Toggle terminal in float window -M.snacks_keymaps = { - -- Explorer - { mode = 'n', lhs = 'e', rhs = function() - -- Open explorer in current window - require('snacks').explorer.open() - end, opts = { desc = 'Explorer: Toggle' } }, - - { mode = 'n', lhs = 'E', rhs = function() - -- Reveal current file in explorer - require('snacks').explorer.reveal() - end, opts = { desc = 'Explorer: Focus current file' } }, - - { mode = 'n', lhs = 'o', rhs = function() - -- Open current file in a new tab and focus it - vim.cmd('tab split %') - end, opts = { desc = 'Open current file in new tab' } }, - - -- Custom function to open explorer files in new tabs - { mode = 'n', lhs = 'f', rhs = function() - -- Open explorer in a new tab - vim.cmd('tabnew') - require('snacks').explorer.open() - end, opts = { desc = 'Explorer: Open in new tab' } }, - - -- Terminal - { mode = 'n', lhs = '', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle float window' } }, - { mode = 'n', lhs = 'tc', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle console' } }, -} - --- Git signs keymaps (all under g for Git) --- Navigation: --- - ]c: Next hunk --- - [c: Previous hunk --- --- Actions: --- - gh: Preview hunk --- - gs: Stage hunk --- - gu: Undo stage hunk --- - gr: Reset hunk --- - gS: Stage buffer --- - gR: Reset buffer --- - gb: Blame line --- - gd: Diff this -M.gitsigns_keymaps = { - -- Navigation - { mode = 'n', lhs = ']c', rhs = function() - if vim.wo.diff then return ']c' end - vim.schedule(function() require('gitsigns').next_hunk() end) - return '' - end, opts = { desc = 'Git: Next hunk', expr = true } }, - - { mode = 'n', lhs = '[c', rhs = function() - if vim.wo.diff then return '[c' end - vim.schedule(function() require('gitsigns').prev_hunk() end) - return '' - end, opts = { desc = 'Git: Previous hunk', expr = true } }, - - -- Actions - { mode = 'n', lhs = 'gh', rhs = function() require('gitsigns').preview_hunk() end, opts = { desc = 'Git: Preview hunk' } }, - { mode = 'n', lhs = 'gb', rhs = function() require('gitsigns').blame_line() end, opts = { desc = 'Git: Blame line' } }, - { mode = 'n', lhs = 'gd', rhs = function() require('gitsigns').diffthis() end, opts = { desc = 'Git: Show diff' } }, - { mode = { 'n', 'v' }, lhs = 'gs', rhs = function() require('gitsigns').stage_hunk() end, opts = { desc = 'Git: Stage hunk' } }, - { mode = { 'n', 'v' }, lhs = 'gr', rhs = function() require('gitsigns').reset_hunk() end, opts = { desc = 'Git: Reset hunk' } }, - { mode = 'n', lhs = 'gS', rhs = function() require('gitsigns').stage_buffer() end, opts = { desc = 'Git: Stage buffer' } }, - { mode = 'n', lhs = 'gu', rhs = function() require('gitsigns').undo_stage_hunk() end, opts = { desc = 'Git: Undo stage' } }, - { mode = 'n', lhs = 'gR', rhs = function() require('gitsigns').reset_buffer() end, opts = { desc = 'Git: Reset buffer' } }, -} - --- Setup function for git signs keymaps -function M.setup_gitsigns_keymaps() - for _, mapping in ipairs(M.gitsigns_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - --- Elixir keymaps (using 'x' as the prefix - mnemonic for 'eXlixir') -M.elixir_keymaps = { - { mode = 'n', lhs = 'xt', - rhs = function() - require('elixir').run_test_file() - end, - opts = { desc = 'Elixir: Test file' } - }, - { mode = 'n', lhs = 'xn', - rhs = function() - require('elixir').run_nearest_test() - end, - opts = { desc = 'Elixir: Test nearest' } - }, - { mode = 'n', lhs = 'xm', - rhs = function() - vim.cmd('Telescope elixir mix') - end, - opts = { desc = 'Elixir: Mix tasks' } - }, -} - --- Set up Elixir keymaps -function M.setup_elixir_keymaps() - for _, mapping in ipairs(M.elixir_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - --- Leap keymaps --- 's' for bidirectional search (both forward and backward) --- 'S' for searching in all windows -M.leap_keymaps = { - -- 's' for bidirectional search (both forward and backward) - { mode = { 'n', 'x', 'o' }, lhs = 's', rhs = function() require('leap').leap {} end, - opts = { desc = 'Leap: Search bidirectional' } }, - - -- 'S' for searching in all windows - { mode = { 'n', 'x', 'o' }, lhs = 'S', rhs = function() - require('leap').leap { target_windows = vim.tbl_filter( - function (win) return vim.api.nvim_win_get_config(win).focusable end, - vim.api.nvim_tabpage_list_wins(0) - )} - end, opts = { desc = 'Leap: Search across windows' } }, -} - --- Setup function for leap keymaps -function M.setup_leap_keymaps() - for _, mapping in ipairs(M.leap_keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - --- Setup functions for keymaps -function M.setup_dadbod_keymaps() - local keymaps = M.dadbod_keymaps or {} - for _, mapping in ipairs(keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - -function M.setup_session_keymaps() - local keymaps = M.session_keymaps or {} - for _, mapping in ipairs(keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - --- Initialize keymaps -local function init_keymaps() - -- Create an autocmd group for our keymaps - local keymap_group = vim.api.nvim_create_augroup('custom_keymaps', { clear = true }) - - -- Handle snacks explorer during buffer writes - vim.api.nvim_create_autocmd({ 'BufWritePre' }, { - group = keymap_group, - callback = function() - -- Pause snacks explorer updates during write - pcall(function() - local picker = require('plugins.snacks.picker') - if picker.is_open() then - picker.pause_updates() - vim.schedule(function() - picker.resume_updates() - end) - end - end) - end, - }) - - -- Function to set up snacks explorer keymaps - local function setup_explorer_keymaps() - -- First remove any existing mappings - for _, key in ipairs({ 'e', 'E' }) do - pcall(vim.keymap.del, 'n', key) - pcall(vim.keymap.del, 'n', key, { buffer = true }) - end - - -- Set our mappings with high priority - for _, mapping in ipairs(M.snacks_keymaps or {}) do - if mapping.lhs == 'e' or mapping.lhs == 'E' then - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { - replace_keycodes = false, - nowait = true, - silent = true, - })) - end - end - end - - -- Set up autocmds to maintain our keymaps - vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter' }, { - group = keymap_group, - callback = setup_explorer_keymaps, - }) - - -- Set up LSP keymaps on attach - vim.api.nvim_create_autocmd('LspAttach', { - group = keymap_group, - callback = function(args) - M.setup_lsp_keymaps(args.buf) - end, - }) - - -- Set up core keymaps - for _, mapping in ipairs(core_keymaps) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - -- Set up plugin keymaps - for _, mapping in ipairs(M.telescope_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - for _, mapping in ipairs(M.diagnostic_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - for _, mapping in ipairs(M.buffer_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - -- Set up snacks keymaps - for _, mapping in ipairs(M.snacks_keymaps or {}) do - -- Skip explorer keymaps as they're handled by setup_explorer_keymaps - if mapping.lhs ~= 'e' and mapping.lhs ~= 'E' then - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - end - - -- Set up scratch buffer keymaps - for _, mapping in ipairs(M.scratch_keymaps or {}) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end - - -- Set up database keymaps - M.setup_dadbod_keymaps() - - -- Set up default tab navigation - vim.keymap.set('n', 'gt', ':tabnext', { silent = true, desc = 'Next tab' }) - vim.keymap.set('n', 'gT', ':tabprevious', { silent = true, desc = 'Previous tab' }) - - -- Set up session keymaps - M.setup_session_keymaps() - - -- Set up git signs keymaps - M.setup_gitsigns_keymaps() - - -- Set up Elixir keymaps - M.setup_elixir_keymaps() - - -- Set up leap keymaps - M.setup_leap_keymaps() -end - --- Initialize all keymaps -init_keymaps() - --- Export `init_keymaps` as `M.setup` so `require('core.keymaps').setup()` works -M.setup = init_keymaps - --- Mini-surround keymaps --- These define how mini.surround plugin works with text objects --- sa - add surroundings (visual mode or with motion like saiw) --- sd - delete surroundings --- sr - replace surroundings --- sn - Find next surrounding --- sN - Find previous surrounding --- sh - Highlight surrounding --- sf - Find surrounding (to use with textobject) --- ss - Go to left surrounding --- sS - Go to right surrounding -M.mini_surround_keymaps = { - add = 'sa', -- Add surrounding in Normal and Visual modes - delete = 'sd', -- Delete surrounding - find = 'sf', -- Find surrounding (to the right) - find_left = 'sF', -- Find surrounding (to the left) - highlight = 'sh', -- Highlight surrounding - replace = 'sr', -- Replace surrounding - update_n_lines = '', -- Update `n_lines` - - suffix_last = 'l', -- Suffix to search with 'prev' method - suffix_next = 'n', -- Suffix to search with 'next' method -} - --- Return the module -return M diff --git a/lua/core/keymaps/core.lua b/lua/core/keymaps/core.lua new file mode 100644 index 00000000000..643fc8d03d1 --- /dev/null +++ b/lua/core/keymaps/core.lua @@ -0,0 +1,36 @@ +---@diagnostic disable: undefined-global +-- Core Neovim keymaps (non-plugin) + +return { + -- Quick access to find files by content + { mode = 'n', lhs = '', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search text in all files' } }, + + -- Clear highlights on search + { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, + + -- Exit terminal mode + { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, + + -- Window navigation (Ctrl + hjkl) + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window left' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window right' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window down' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window up' } }, + + -- Window resizing (Ctrl + Arrow keys) + { mode = 'n', lhs = '', rhs = 'resize +2', opts = { desc = 'Window: Increase height' } }, + { mode = 'n', lhs = '', rhs = 'resize -2', opts = { desc = 'Window: Decrease height' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize -2', opts = { desc = 'Window: Decrease width' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize +2', opts = { desc = 'Window: Increase width' } }, + + -- Move lines up and down (Alt + jk) + { mode = 'n', lhs = '', rhs = ':m .+1==', opts = { desc = 'Move line down', silent = true } }, + { mode = 'n', lhs = '', rhs = ':m .-2==', opts = { desc = 'Move line up', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '>+1gv=gv", opts = { desc = 'Move selection down', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '<-2gv=gv", opts = { desc = 'Move selection up', silent = true } }, + + -- Quick save and quit + { mode = 'n', lhs = 'w', rhs = 'w', opts = { desc = 'Save file' } }, + { mode = 'n', lhs = 'W', rhs = 'wa', opts = { desc = 'Save all files' } }, + { mode = 'n', lhs = 'Q', rhs = 'qa', opts = { desc = 'Quit all' } }, +} diff --git a/lua/core/keymaps/diagnostic.lua b/lua/core/keymaps/diagnostic.lua new file mode 100644 index 00000000000..c561cd23712 --- /dev/null +++ b/lua/core/keymaps/diagnostic.lua @@ -0,0 +1,13 @@ +---@diagnostic disable: undefined-global +-- Diagnostic keymaps + +return { + -- Navigation + { mode = 'n', lhs = '[d', rhs = vim.diagnostic.goto_prev, opts = { desc = 'Diagnostic: Previous' } }, + { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, + + -- Viewing diagnostics + { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details in float' } }, + { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Diagnostic: Show list' } }, + { mode = 'n', lhs = 'td', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Diagnostic: Search all diagnostics' } }, +} diff --git a/lua/core/keymaps/git.lua b/lua/core/keymaps/git.lua new file mode 100644 index 00000000000..a269fa12df8 --- /dev/null +++ b/lua/core/keymaps/git.lua @@ -0,0 +1,37 @@ +---@diagnostic disable: undefined-global +-- Git keymaps + +local M = {} + +M.keymaps = { + -- Navigation + { mode = 'n', lhs = ']c', rhs = function() + if vim.wo.diff then return ']c' end + vim.schedule(function() require('gitsigns').next_hunk() end) + return '' + end, opts = { desc = 'Git: Next hunk', expr = true } }, + + { mode = 'n', lhs = '[c', rhs = function() + if vim.wo.diff then return '[c' end + vim.schedule(function() require('gitsigns').prev_hunk() end) + return '' + end, opts = { desc = 'Git: Previous hunk', expr = true } }, + + -- Actions + { mode = 'n', lhs = 'gh', rhs = function() require('gitsigns').preview_hunk() end, opts = { desc = 'Git: Preview hunk' } }, + { mode = 'n', lhs = 'gb', rhs = function() require('gitsigns').blame_line() end, opts = { desc = 'Git: Blame line' } }, + { mode = 'n', lhs = 'gd', rhs = function() require('gitsigns').diffthis() end, opts = { desc = 'Git: Show diff' } }, + { mode = { 'n', 'v' }, lhs = 'gs', rhs = function() require('gitsigns').stage_hunk() end, opts = { desc = 'Git: Stage hunk' } }, + { mode = { 'n', 'v' }, lhs = 'gr', rhs = function() require('gitsigns').reset_hunk() end, opts = { desc = 'Git: Reset hunk' } }, + { mode = 'n', lhs = 'gS', rhs = function() require('gitsigns').stage_buffer() end, opts = { desc = 'Git: Stage buffer' } }, + { mode = 'n', lhs = 'gu', rhs = function() require('gitsigns').undo_stage_hunk() end, opts = { desc = 'Git: Undo stage' } }, + { mode = 'n', lhs = 'gR', rhs = function() require('gitsigns').reset_buffer() end, opts = { desc = 'Git: Reset buffer' } }, +} + +function M.setup() + for _, mapping in ipairs(M.keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +return M diff --git a/lua/core/keymaps/init.lua b/lua/core/keymaps/init.lua new file mode 100644 index 00000000000..06a117fd173 --- /dev/null +++ b/lua/core/keymaps/init.lua @@ -0,0 +1,122 @@ +---@diagnostic disable: undefined-global +-- Keymaps init - loads all keymap modules + +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +local M = {} + +-- Import keymap modules +local core = require('core.keymaps.core') +local lsp = require('core.keymaps.lsp') +local telescope = require('core.keymaps.telescope') +local diagnostic = require('core.keymaps.diagnostic') +local git = require('core.keymaps.git') +local plugins = require('core.keymaps.plugins') + +-- Export for external use +M.setup_lsp_keymaps = lsp.setup +M.telescope_keymaps = telescope +M.diagnostic_keymaps = diagnostic +M.gitsigns_keymaps = git.keymaps +M.dadbod_keymaps = plugins.dadbod +M.session_keymaps = plugins.session +M.scratch_keymaps = plugins.scratch +M.snacks_keymaps = plugins.snacks +M.leap_keymaps = plugins.leap +M.elixir_keymaps = plugins.elixir +M.mini_surround_keymaps = plugins.mini_surround + +-- Setup functions +M.setup_gitsigns_keymaps = git.setup +M.setup_dadbod_keymaps = plugins.setup_dadbod +M.setup_session_keymaps = plugins.setup_session +M.setup_elixir_keymaps = plugins.setup_elixir +M.setup_leap_keymaps = plugins.setup_leap + +-- Default on_attach for LSP (used by lsp/setup.lua) +M.default_on_attach = nil + +local explorer_keymaps_set = false +local function setup_explorer_keymaps() + if explorer_keymaps_set then return end + explorer_keymaps_set = true + + for _, key in ipairs({ 'e', 'E' }) do + pcall(vim.keymap.del, 'n', key) + end + + for _, mapping in ipairs(plugins.snacks) do + if mapping.lhs == 'e' or mapping.lhs == 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { + replace_keycodes = false, + nowait = true, + silent = true, + })) + end + end +end + +local function init_keymaps() + local keymap_group = vim.api.nvim_create_augroup('custom_keymaps', { clear = true }) + + -- Handle snacks explorer during buffer writes + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = keymap_group, + callback = function() + pcall(function() + local picker = require('plugins.snacks.picker') + if picker.is_open() then + picker.pause_updates() + vim.schedule(function() picker.resume_updates() end) + end + end) + end, + }) + + -- Set up autocmds to maintain explorer keymaps + vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter' }, { + group = keymap_group, + callback = setup_explorer_keymaps, + }) + + -- Set up LSP keymaps on attach + vim.api.nvim_create_autocmd('LspAttach', { + group = keymap_group, + callback = function(args) M.setup_lsp_keymaps(args.buf) end, + }) + + -- Core keymaps + for _, mapping in ipairs(core) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Telescope keymaps + for _, mapping in ipairs(telescope) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Diagnostic keymaps + for _, mapping in ipairs(diagnostic) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Plugin keymaps + plugins.setup_snacks() + plugins.setup_scratch() + plugins.setup_dadbod() + plugins.setup_session() + plugins.setup_leap() + plugins.setup_elixir() + git.setup() + + -- Tab navigation + vim.keymap.set('n', 'gt', ':tabnext', { silent = true, desc = 'Next tab' }) + vim.keymap.set('n', 'gT', ':tabprevious', { silent = true, desc = 'Previous tab' }) +end + +init_keymaps() + +M.setup = init_keymaps + +return M diff --git a/lua/core/keymaps/lsp.lua b/lua/core/keymaps/lsp.lua new file mode 100644 index 00000000000..76e0af31ff3 --- /dev/null +++ b/lua/core/keymaps/lsp.lua @@ -0,0 +1,70 @@ +---@diagnostic disable: undefined-global +-- LSP keymaps + +local M = {} + +function M.setup(bufnr) + local keymaps = { + -- Go to definitions + { mode = 'n', lhs = 'gd', rhs = function() require('telescope.builtin').lsp_definitions() end, opts = { desc = 'LSP: Go to definition' } }, + { mode = 'n', lhs = 'gr', rhs = function() require('telescope.builtin').lsp_references() end, opts = { desc = 'LSP: Find references' } }, + { mode = 'n', lhs = 'gI', rhs = function() require('telescope.builtin').lsp_implementations() end, opts = { desc = 'LSP: Go to implementation' } }, + { mode = 'n', lhs = 'gy', rhs = function() require('telescope.builtin').lsp_type_definitions() end, opts = { desc = 'LSP: Go to type definition' } }, + + -- Symbol navigation + { mode = 'n', lhs = 'ls', rhs = function() + require('telescope.builtin').lsp_document_symbols({ position_encoding = 'utf-16' }) + end, opts = { desc = 'LSP: Document symbols' } }, + { mode = 'n', lhs = 'lS', rhs = function() + local status_ok, _ = pcall(function() + require('telescope.builtin').lsp_dynamic_workspace_symbols({ + position_encoding = 'utf-16', + show_line = true, + fname_width = 50, + symbol_width = 35, + attach_mappings = function(prompt_bufnr) + require("telescope.actions").select_default:replace(function() + local entry = require("telescope.actions.state").get_selected_entry() + if not entry then return end + require("telescope.actions").close(prompt_bufnr) + if entry.value and entry.value.filename then + vim.cmd(string.format('edit %s', entry.value.filename)) + vim.api.nvim_win_set_cursor(0, {entry.value.lnum, entry.value.col}) + end + end) + return true + end + }) + end) + if not status_ok then + vim.notify("Workspace symbols not available for this language server", vim.log.levels.INFO) + end + end, opts = { desc = 'LSP: Workspace symbols' } }, + + -- Code actions + { mode = 'n', lhs = 'lr', rhs = vim.lsp.buf.rename, opts = { desc = 'LSP: Rename symbol' } }, + { mode = 'n', lhs = 'la', rhs = vim.lsp.buf.code_action, opts = { desc = 'LSP: Code action' } }, + { mode = 'n', lhs = 'lf', rhs = function() vim.lsp.buf.format({ async = true }) end, opts = { desc = 'LSP: Format code' } }, + + -- Documentation + { mode = 'n', lhs = 'K', rhs = function() require('hover').hover() end, opts = { desc = 'Enhanced documentation (hover.nvim)' } }, + } + + -- Clear existing LSP keymaps for this buffer + local lsp_maps = { 'gd', 'gr', 'gI', 'gy', 'K', 'ls', 'lS', 'lr', 'la', 'lf' } + for _, lhs in ipairs(lsp_maps) do + pcall(vim.keymap.del, 'n', lhs, { buffer = bufnr }) + end + + -- Set keymaps with buffer local + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { + buffer = bufnr, + replace_keycodes = false, + nowait = true, + silent = true, + })) + end +end + +return M diff --git a/lua/core/keymaps/plugins.lua b/lua/core/keymaps/plugins.lua new file mode 100644 index 00000000000..800c2db4a87 --- /dev/null +++ b/lua/core/keymaps/plugins.lua @@ -0,0 +1,120 @@ +---@diagnostic disable: undefined-global +-- Plugin keymaps (dadbod, session, scratch, snacks, leap, elixir, mini-surround) + +local M = {} + +-- Database keymaps +M.dadbod = { + { mode = 'n', lhs = 'Dt', rhs = 'DBUIToggle', opts = { desc = 'Database: Toggle UI' } }, + { mode = 'n', lhs = 'Df', rhs = 'DBUIFindBuffer', opts = { desc = 'Database: Find buffer' } }, + { mode = 'n', lhs = 'Dr', rhs = 'DBUIRenameBuffer', opts = { desc = 'Database: Rename buffer' } }, + { mode = 'n', lhs = 'Dl', rhs = 'DBUILastQueryInfo', opts = { desc = 'Database: Last query' } }, +} + +-- Session keymaps +M.session = { + { mode = 'n', lhs = 'mw', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').write(name, { force = true }) + end, opts = { desc = 'Memory: Write session' } }, + { mode = 'n', lhs = 'mr', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').read(name) + end, opts = { desc = 'Memory: Read session' } }, + { mode = 'n', lhs = 'md', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').delete(name) + end, opts = { desc = 'Memory: Delete session' } }, +} + +-- Scratch buffer keymaps +M.scratch = { + { mode = 'n', lhs = '.', rhs = function() require("snacks").scratch() end, opts = { desc = 'Toggle scratch buffer' } }, + { mode = 'n', lhs = 'S', rhs = function() require("snacks").scratch.select() end, opts = { desc = 'Select scratch buffer' } }, + { mode = 'n', lhs = 'nh', rhs = function() require("snacks.notifier").show_history() end, opts = { desc = 'Show notification history' } }, +} + +-- Snacks keymaps (explorer and terminal) +M.snacks = { + { mode = 'n', lhs = 'e', rhs = function() require('snacks').explorer.open() end, opts = { desc = 'Explorer: Toggle' } }, + { mode = 'n', lhs = 'E', rhs = function() require('snacks').explorer.reveal() end, opts = { desc = 'Explorer: Focus current file' } }, + { mode = 'n', lhs = 'o', rhs = function() vim.cmd('tab split %') end, opts = { desc = 'Open current file in new tab' } }, + { mode = 'n', lhs = 'f', rhs = function() + vim.cmd('tabnew') + require('snacks').explorer.open() + end, opts = { desc = 'Explorer: Open in new tab' } }, + { mode = 'n', lhs = '', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle float window' } }, + { mode = 'n', lhs = 'tc', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle console' } }, +} + +-- Leap keymaps +M.leap = { + { mode = { 'n', 'x', 'o' }, lhs = 's', rhs = function() require('leap').leap {} end, opts = { desc = 'Leap: Search bidirectional' } }, + { mode = { 'n', 'x', 'o' }, lhs = 'S', rhs = function() + require('leap').leap { target_windows = vim.tbl_filter( + function (win) return vim.api.nvim_win_get_config(win).focusable end, + vim.api.nvim_tabpage_list_wins(0) + )} + end, opts = { desc = 'Leap: Search across windows' } }, +} + +-- Elixir keymaps +M.elixir = { + { mode = 'n', lhs = 'xt', rhs = function() require('elixir').run_test_file() end, opts = { desc = 'Elixir: Test file' } }, + { mode = 'n', lhs = 'xn', rhs = function() require('elixir').run_nearest_test() end, opts = { desc = 'Elixir: Test nearest' } }, + { mode = 'n', lhs = 'xm', rhs = function() vim.cmd('Telescope elixir mix') end, opts = { desc = 'Elixir: Mix tasks' } }, +} + +-- Mini-surround keymaps (used by mini.surround config) +M.mini_surround = { + add = 'sa', + delete = 'sd', + find = 'sf', + find_left = 'sF', + highlight = 'sh', + replace = 'sr', + update_n_lines = '', + suffix_last = 'l', + suffix_next = 'n', +} + +-- Setup functions +function M.setup_dadbod() + for _, mapping in ipairs(M.dadbod) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_session() + for _, mapping in ipairs(M.session) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_scratch() + for _, mapping in ipairs(M.scratch) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_snacks() + for _, mapping in ipairs(M.snacks) do + if mapping.lhs ~= 'e' and mapping.lhs ~= 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + end +end + +function M.setup_leap() + for _, mapping in ipairs(M.leap) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_elixir() + for _, mapping in ipairs(M.elixir) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +return M diff --git a/lua/core/keymaps/telescope.lua b/lua/core/keymaps/telescope.lua new file mode 100644 index 00000000000..4ee6f44fbc6 --- /dev/null +++ b/lua/core/keymaps/telescope.lua @@ -0,0 +1,32 @@ +---@diagnostic disable: undefined-global +-- Telescope keymaps + +return { + -- Help + { mode = 'n', lhs = 'sh', rhs = function() require('telescope.builtin').help_tags() end, opts = { desc = 'Search: Help' } }, + { mode = 'n', lhs = 'sk', rhs = function() require('telescope.builtin').keymaps() end, opts = { desc = 'Search: Keymaps' } }, + + -- Files + { mode = 'n', lhs = 'sf', rhs = function() require('telescope.builtin').find_files() end, opts = { desc = 'Search: Files' } }, + { mode = 'n', lhs = 'sr', rhs = function() require('telescope.builtin').oldfiles() end, opts = { desc = 'Search: Recent files' } }, + + -- Text + { mode = 'n', lhs = 'sg', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search: Text in workspace' } }, + { mode = 'n', lhs = 'sw', rhs = function() require('telescope.builtin').grep_string() end, opts = { desc = 'Search: Word under cursor' } }, + { mode = 'n', lhs = '/', rhs = function() + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, opts = { desc = 'Search: Text in buffer' } }, + { mode = 'n', lhs = 's/', rhs = function() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, opts = { desc = 'Search: Text in open files' } }, + + -- Workspace + { mode = 'n', lhs = 'sd', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Search: Diagnostics' } }, + { mode = 'n', lhs = 'sb', rhs = function() require('telescope.builtin').buffers() end, opts = { desc = 'Search: Buffers' } }, +} diff --git a/lua/options/autocmds.lua b/lua/options/autocmds.lua index ebe0c0ca3ce..c641ff30db8 100644 --- a/lua/options/autocmds.lua +++ b/lua/options/autocmds.lua @@ -12,41 +12,31 @@ function M.setup() }) - -- Add a smart format-on-save command that only uses null-ls - -- Fix for zig.vim ftplugin error - handles both JSON and struct output + -- Fix for zig.vim ftplugin error - cache zig env result vim.api.nvim_create_autocmd('FileType', { pattern = 'zig', group = vim.api.nvim_create_augroup('user-zig-fix', { clear = true }), callback = function() if vim.fn.executable('zig') ~= 1 or vim.g.zig_std_dir then return end - - -- First try with --json flag - local handle = io.popen('zig env --json 2>/dev/null') - if handle then - local result = handle:read('*a') - handle:close() - - -- Try to parse as JSON first - local success, env = pcall(vim.fn.json_decode, result) - if success and type(env) == 'table' and env.std_dir then - vim.g.zig_std_dir = env.std_dir - vim.opt_local.path:prepend(env.std_dir) - return - end + + -- Single popen call - try JSON first (newer zig), fallback to struct parsing + local handle = io.popen('zig env 2>/dev/null') + if not handle then return end + + local result = handle:read('*a') + handle:close() + + -- Try JSON parse first + local success, env = pcall(vim.fn.json_decode, result) + if success and type(env) == 'table' and env.std_dir then + vim.g.zig_std_dir = env.std_dir + else + -- Fallback: extract from struct output + vim.g.zig_std_dir = result:match('%.std_dir%s*=%s*"([^"]+)"') end - - -- If JSON parsing failed, try to parse the struct output - handle = io.popen('zig env 2>/dev/null') - if handle then - local result = handle:read('*a') - handle:close() - - -- Extract std_dir from struct output - local std_dir = result:match('%.std_dir%s*=%s*"([^"]+)"') - if std_dir then - vim.g.zig_std_dir = std_dir - vim.opt_local.path:prepend(std_dir) - end + + if vim.g.zig_std_dir then + vim.opt_local.path:prepend(vim.g.zig_std_dir) end end, }) diff --git a/lua/options/settings.lua b/lua/options/settings.lua index 0faa11df2e4..270e4515a62 100644 --- a/lua/options/settings.lua +++ b/lua/options/settings.lua @@ -6,7 +6,7 @@ ---@diagnostic disable: undefined-global -- Make line numbers default vim.opt.number = true -vim.o.relativenumber = true +vim.opt.relativenumber = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! -- vim.opt.relativenumber = true @@ -99,10 +99,6 @@ vim.diagnostic.config({ local M = {} function M.setup() - -- Leader keys - vim.g.mapleader = ' ' - vim.g.maplocalleader = ' ' - -- Ensure swapfile directory exists and configure swapfile settings local swap_dir = vim.fn.stdpath('data') .. '/swapfiles' if vim.fn.isdirectory(swap_dir) == 0 then @@ -110,7 +106,6 @@ function M.setup() end vim.opt.directory = swap_dir vim.opt.swapfile = true - vim.opt.updatetime = 300 vim.opt.updatecount = 100 end diff --git a/lua/plugins/better-hover.lua b/lua/plugins/better-hover.lua deleted file mode 100644 index d79004b6608..00000000000 --- a/lua/plugins/better-hover.lua +++ /dev/null @@ -1,58 +0,0 @@ ----@diagnostic disable: undefined-global --- Direct approach to fix hover documentation with custom function -return { - "neovim/nvim-lspconfig", - config = function() - -- Create a direct standalone hover function - local function better_hover() - -- Save original functions we'll temporarily override - local orig_open_floating = vim.lsp.util.open_floating_preview - - -- Replace the floating preview function temporarily - vim.lsp.util.open_floating_preview = function(contents, syntax, opts) - opts = opts or {} - -- Force nicer styling - opts.border = "rounded" - opts.max_width = math.min(math.floor(vim.o.columns * 0.7), 80) - opts.max_height = math.floor(vim.o.lines * 0.3) - - -- Process contents to remove separator lines and improve formatting - local cleaned_contents = {} - for _, line in ipairs(contents) do - -- Skip separator lines - if not line:match("^%-%-%-%-+$") then - table.insert(cleaned_contents, line) - end - end - - -- Call original with improved options and cleaned content - local bufnr, winnr = orig_open_floating(cleaned_contents, syntax, opts) - - -- Enhance the created buffer - if bufnr and winnr then - -- Set better options for the window - vim.api.nvim_win_set_option(winnr, "conceallevel", 2) - vim.api.nvim_win_set_option(winnr, "foldenable", false) - - -- If it's markdown, ensure proper highlighting - if syntax == "markdown" then - vim.api.nvim_buf_set_option(bufnr, "filetype", "markdown") - end - end - - return bufnr, winnr - end - - -- Call the regular hover function with our temporary override - vim.lsp.buf.hover() - - -- Restore original function - vim.lsp.util.open_floating_preview = orig_open_floating - end - - -- Directly override the K keymap - this bypasses any conflicts - vim.keymap.set("n", "K", better_hover, { noremap = true, silent = true, desc = "LSP: Better hover docs" }) - end, - -- Run this after all other LSP configs are loaded - priority = 999, -} diff --git a/lua/plugins/doc-test.lua b/lua/plugins/doc-test.lua deleted file mode 100644 index 596b47152a0..00000000000 --- a/lua/plugins/doc-test.lua +++ /dev/null @@ -1,76 +0,0 @@ ----@diagnostic disable: undefined-global --- Test doc window plugin -return { - "neovim/nvim-lspconfig", - config = function() - -- Create a test function that shows a styled floating window - local function test_doc_window() - local contents = { - "## Documentation Test", - "", - "This is a test documentation window to see how styling works.", - "", - "**Important**: This shows what documentation *should* look like.", - "", - "```lua", - "function example(param)", - " -- This is a code sample", - " return param + 1", - "end", - "```", - } - - -- Create a nicely styled window - local opts = { - border = "rounded", - width = 60, - height = 12, - wrap = true, - pad_left = 1, - pad_right = 1, - } - - local bufnr = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, contents) - vim.api.nvim_buf_set_option(bufnr, "filetype", "markdown") - - -- Position the window near the cursor - local cursor_pos = vim.api.nvim_win_get_cursor(0) - local row = cursor_pos[1] - local col = cursor_pos[2] - - -- Calculate position - local ui = vim.api.nvim_list_uis()[1] - local width = opts.width or 60 - local height = opts.height or 12 - local anchor = "NW" - local col_offset = 0 - - -- Open the window - local winnr = vim.api.nvim_open_win(bufnr, false, { - relative = "cursor", - row = 1, - col = col_offset, - width = width, - height = height, - style = "minimal", - border = opts.border, - anchor = anchor, - }) - - -- Set window options - vim.api.nvim_win_set_option(winnr, "conceallevel", 2) - vim.api.nvim_win_set_option(winnr, "concealcursor", "n") - vim.api.nvim_win_set_option(winnr, "winblend", 0) - - -- Return window and buffer numbers - return bufnr, winnr - end - - -- Add a command to test the documentation window - vim.api.nvim_create_user_command("TestDocWindow", test_doc_window, {}) - - -- Also map it to a key for easy testing - vim.keymap.set("n", "td", test_doc_window, { desc = "Test doc window styling" }) - end -} diff --git a/lua/plugins/leap.lua b/lua/plugins/leap.lua index ec0a15d9ebd..f61c9bf2185 100644 --- a/lua/plugins/leap.lua +++ b/lua/plugins/leap.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: undefined-global -- Quick navigation plugin return { - 'ggandor/leap.nvim', + url = "https://codeberg.org/andyg/leap.nvim", dependencies = { 'tpope/vim-repeat', -- For dot-repeat support }, @@ -20,7 +20,7 @@ return { -- Set highlight colors for better visibility vim.api.nvim_set_hl(0, 'LeapMatch', { fg = '#89B4FA', bold = true, nocombine = true }) - vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { fg = '#F38BA8', bold = true, nocombine = true }) + vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { fg = '#cfa369', bold = true, nocombine = true }) vim.api.nvim_set_hl(0, 'LeapLabelSecondary', { fg = '#94E2D5', bold = true, nocombine = true }) end, } diff --git a/lua/plugins/lsp/setup.lua b/lua/plugins/lsp/setup.lua index 4ea1960e18f..c5014867b2a 100644 --- a/lua/plugins/lsp/setup.lua +++ b/lua/plugins/lsp/setup.lua @@ -50,12 +50,12 @@ function M.setup() } capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -- Setup mason-lspconfig + -- Setup mason-lspconfig with handlers local mason_lspconfig = require('mason-lspconfig') - mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers) } - - mason_lspconfig.setup_handlers { - function(server_name) + mason_lspconfig.setup { + ensure_installed = vim.tbl_keys(servers), + handlers = { + function(server_name) local config = servers[server_name] or {} config.capabilities = capabilities @@ -134,6 +134,7 @@ function M.setup() require('lspconfig')[server_name].setup(config) end, + }, } -- Hover handler will now be provided by Blink diff --git a/lua/plugins/mini-surround.lua b/lua/plugins/mini-surround.lua index 0050bc37fb6..26ea8741ca6 100644 --- a/lua/plugins/mini-surround.lua +++ b/lua/plugins/mini-surround.lua @@ -1,7 +1,7 @@ return { 'echasnovski/mini.surround', version = '*', - event = "VeryLazy", + event = 'VeryLazy', config = function() require('mini.surround').setup({ -- Use mappings from centralized keymaps diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua index aa6ea965957..dd9fdbb8e98 100644 --- a/lua/plugins/nvim-autopairs.lua +++ b/lua/plugins/nvim-autopairs.lua @@ -1,6 +1,6 @@ return { 'windwp/nvim-autopairs', - event = "InsertEnter", -- Only load in insert mode + event = 'InsertEnter', opts = nil, config = function() require('plugins.nvim-autopairs.setup').setup(require('plugins.nvim-autopairs.setup').opts) diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index e672a006052..88ae0cf2d9c 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -39,7 +39,7 @@ return { -- 'folke/neodev.nvim', -- Adds support for Neovim Lua API -- No longer needed with lazydev { 'WhoIsSethDaniel/mason-tool-installer.nvim', - event = "VeryLazy", + event = 'VeryLazy', config = function() require('mason-tool-installer').setup { ensure_installed = { diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua index 21addca8795..5ec46cf9c06 100644 --- a/lua/plugins/session.lua +++ b/lua/plugins/session.lua @@ -2,53 +2,33 @@ return { 'echasnovski/mini.sessions', version = '*', - event = "VimEnter", + event = 'VimEnter', config = function() - -- Function to get current directory name local function get_session_name() + return vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + end + + -- Cache Go project check per directory + local go_project_cache = {} + local function is_go_project() local cwd = vim.fn.getcwd() - return vim.fn.fnamemodify(cwd, ':t') + if go_project_cache[cwd] == nil then + -- Single glob with brace expansion + go_project_cache[cwd] = vim.fn.glob(cwd .. '/{*.go,go.mod,go.work}') ~= '' + end + return go_project_cache[cwd] end require('mini.sessions').setup({ - -- Whether to read latest session if Neovim opened without file arguments autoread = false, - -- Whether to write current session before quitting Neovim autowrite = true, - -- Directory where global sessions are stored (use `''` to disable) directory = vim.fn.stdpath('data') .. '/sessions', - -- File for local session (use `''` to disable) file = '', - -- Whether to force possibly harmful actions (meaning depends on function) force = { read = false, write = true, delete = false }, - -- Hook functions for actions. Default `nil` means 'do nothing'. hooks = { - -- Before successful action pre = { - read = function() - -- Skip session operations for Go projects - local current_dir = vim.fn.getcwd() - local has_go_files = vim.fn.glob(current_dir .. "/*.go") ~= "" or - vim.fn.glob(current_dir .. "/go.mod") ~= "" or - vim.fn.glob(current_dir .. "/go.work") ~= "" - - if has_go_files then - return false -- Skip for Go projects - end - return true - end, - write = function() - -- Skip session operations for Go projects - local current_dir = vim.fn.getcwd() - local has_go_files = vim.fn.glob(current_dir .. "/*.go") ~= "" or - vim.fn.glob(current_dir .. "/go.mod") ~= "" or - vim.fn.glob(current_dir .. "/go.work") ~= "" - - if has_go_files then - return false -- Skip for Go projects - end - return true - end, + read = function() return not is_go_project() end, + write = function() return not is_go_project() end, }, -- After successful action post = { read = nil, write = nil, delete = nil }, From 78fc3d5aea28e77f1ecd0bcd55c1b78ab6ef1164 Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Sat, 4 Jul 2026 14:26:18 +0200 Subject: [PATCH 16/16] some further fixes and modifications --- lua/core/keymaps/init.lua | 3 - lua/core/keymaps/plugins.lua | 15 +---- lua/plugins/coding.lua | 1 - lua/plugins/coding/elixir.lua | 38 ------------- lua/plugins/lsp/servers.lua | 24 ++++---- lua/plugins/lsp/setup.lua | 7 +-- lua/plugins/null-ls/setup.lua | 67 +++++++++++----------- lua/plugins/nvim-lspconfig.lua | 7 ++- lua/plugins/nvim-treesitter.lua | 99 ++++++++++++++++----------------- 9 files changed, 102 insertions(+), 159 deletions(-) delete mode 100644 lua/plugins/coding/elixir.lua diff --git a/lua/core/keymaps/init.lua b/lua/core/keymaps/init.lua index 06a117fd173..773b0463b19 100644 --- a/lua/core/keymaps/init.lua +++ b/lua/core/keymaps/init.lua @@ -24,14 +24,12 @@ M.session_keymaps = plugins.session M.scratch_keymaps = plugins.scratch M.snacks_keymaps = plugins.snacks M.leap_keymaps = plugins.leap -M.elixir_keymaps = plugins.elixir M.mini_surround_keymaps = plugins.mini_surround -- Setup functions M.setup_gitsigns_keymaps = git.setup M.setup_dadbod_keymaps = plugins.setup_dadbod M.setup_session_keymaps = plugins.setup_session -M.setup_elixir_keymaps = plugins.setup_elixir M.setup_leap_keymaps = plugins.setup_leap -- Default on_attach for LSP (used by lsp/setup.lua) @@ -107,7 +105,6 @@ local function init_keymaps() plugins.setup_dadbod() plugins.setup_session() plugins.setup_leap() - plugins.setup_elixir() git.setup() -- Tab navigation diff --git a/lua/core/keymaps/plugins.lua b/lua/core/keymaps/plugins.lua index 800c2db4a87..278d1bf75b4 100644 --- a/lua/core/keymaps/plugins.lua +++ b/lua/core/keymaps/plugins.lua @@ -1,5 +1,5 @@ ---@diagnostic disable: undefined-global --- Plugin keymaps (dadbod, session, scratch, snacks, leap, elixir, mini-surround) +-- Plugin keymaps (dadbod, session, scratch, snacks, leap, mini-surround) local M = {} @@ -58,13 +58,6 @@ M.leap = { end, opts = { desc = 'Leap: Search across windows' } }, } --- Elixir keymaps -M.elixir = { - { mode = 'n', lhs = 'xt', rhs = function() require('elixir').run_test_file() end, opts = { desc = 'Elixir: Test file' } }, - { mode = 'n', lhs = 'xn', rhs = function() require('elixir').run_nearest_test() end, opts = { desc = 'Elixir: Test nearest' } }, - { mode = 'n', lhs = 'xm', rhs = function() vim.cmd('Telescope elixir mix') end, opts = { desc = 'Elixir: Mix tasks' } }, -} - -- Mini-surround keymaps (used by mini.surround config) M.mini_surround = { add = 'sa', @@ -111,10 +104,4 @@ function M.setup_leap() end end -function M.setup_elixir() - for _, mapping in ipairs(M.elixir) do - vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) - end -end - return M diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index 1e0c8bb1f3e..3b4e3809a55 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -4,5 +4,4 @@ return { require('plugins.coding.zig'), require('plugins.coding.clangd'), require('plugins.coding.dap'), - require('plugins.coding.elixir'), } diff --git a/lua/plugins/coding/elixir.lua b/lua/plugins/coding/elixir.lua deleted file mode 100644 index 3b0651b640c..00000000000 --- a/lua/plugins/coding/elixir.lua +++ /dev/null @@ -1,38 +0,0 @@ -return { - { - 'elixir-tools/elixir-tools.nvim', - version = '*', - ft = { 'ex', 'exs', 'heex', 'eex', 'elixir' }, - dependencies = { - 'neovim/nvim-lspconfig', - 'nvim-lua/plenary.nvim', - }, - config = function() - local elixir = require('elixir') - - -- Configure elixir-tools with LSP disabled (handled by lspconfig) - elixir.setup({ - -- Disable the built-in LSP client to avoid conflicts - elixirls = { enable = false }, - - -- Enable non-LSP features - credo = { enable = true }, - projectionist = { enable = true }, - - -- Configure the test runner - test_runner = { - enabled = true, - runner = 'exunit', -- or 'exunit_individual' for individual test runs - }, - - -- Enable mix integration - mix = { - enabled = true, - format_on_save = false, -- Disabled to prevent file changed warnings - }, - }) - - -- Keymaps are now in core/keymaps.lua with lx prefix - end, - }, -} diff --git a/lua/plugins/lsp/servers.lua b/lua/plugins/lsp/servers.lua index 89327ed16bd..d498272da6a 100644 --- a/lua/plugins/lsp/servers.lua +++ b/lua/plugins/lsp/servers.lua @@ -8,6 +8,17 @@ local gopls_build_flags = go_flags ~= '' and { '-tags=' .. go_flags } or {} return { -- Python pyright = {}, + + -- Bash/Shell + bashls = { + filetypes = { 'sh', 'bash', 'zsh' }, + settings = { + bashIde = { + globPattern = '*@(.sh|.inc|.bash|.command)', + shellcheckPath = 'shellcheck', + }, + }, + }, -- Go gopls = { settings = { @@ -131,17 +142,4 @@ return { }, }, }, - - -- Elixir - elixirls = { - cmd = { 'elixir-ls' }, - settings = { - elixirLS = { - dialyzerEnabled = true, - fetchDeps = true, - enableTestLenses = true, - suggestSpecs = true, - } - } - } } diff --git a/lua/plugins/lsp/setup.lua b/lua/plugins/lsp/setup.lua index c5014867b2a..40db6b09ad4 100644 --- a/lua/plugins/lsp/setup.lua +++ b/lua/plugins/lsp/setup.lua @@ -63,11 +63,8 @@ function M.setup() M.default_on_attach = function(client, bufnr) require('core.keymaps').setup_lsp_keymaps(bufnr) - -- Only attach navic if: - -- 1. The client supports document symbols - -- 2. The client isn't elixirls (handled by elixir-tools.nvim) - if client.server_capabilities.documentSymbolProvider - and client.name ~= 'elixirls' then + -- Attach navic if client supports document symbols + if client.server_capabilities.documentSymbolProvider then local status_ok, _ = pcall(require, 'nvim-navic') if status_ok then require('nvim-navic').attach(client, bufnr) diff --git a/lua/plugins/null-ls/setup.lua b/lua/plugins/null-ls/setup.lua index 2159d2d3b5b..fcc220ab222 100644 --- a/lua/plugins/null-ls/setup.lua +++ b/lua/plugins/null-ls/setup.lua @@ -8,44 +8,45 @@ function M.setup() local formatting = null_ls.builtins.formatting local diagnostics = null_ls.builtins.diagnostics - null_ls.setup { + local sources = { + formatting.gofumpt.with({ extra_args = { "-extra" } }), + formatting.goimports.with({ args = { "-local", "", "-w", "$FILENAME" } }), + diagnostics.golangci_lint.with({ + diagnostics_format = '#{m}', + extra_args = { + '--fast', + '--max-issues-per-linter', '30', + '--max-same-issues', '4', + '--max-same-issues-per-linter', '0', + '--fix=false', + '--tests=false', + '--print-issued-lines=false', + '--timeout=10s', + '--out-format=json', + }, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + timeout = 10000, + }), + formatting.prettier.with { + filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, + extra_args = { + '--bracket-same-line', + '--trailing-comma', 'all', + '--tab-width', '2', + '--semi', + '--single-quote', + }, + }, + formatting.shfmt.with { extra_args = { '-i', '2', '-ci', '-bn' } }, + formatting.sqlfluff.with { extra_args = { '--dialect', 'tsql' } }, + } + null_ls.setup { root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), timeout = 10000, debounce = 250, update_in_insert = false, - sources = { - formatting.gofumpt.with({ extra_args = { "-extra" } }), - formatting.goimports.with({ args = { "-local", "", "-w", "$FILENAME" } }), - diagnostics.golangci_lint.with({ - diagnostics_format = '#{m}', - extra_args = { - '--fast', - '--max-issues-per-linter', '30', - '--max-same-issues', '4', - '--max-same-issues-per-linter', '0', - '--fix=false', - '--tests=false', - '--print-issued-lines=false', - '--timeout=10s', - '--out-format=json', - }, - method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - timeout = 10000, - }), - formatting.prettier.with { - filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, - extra_args = { - '--bracket-same-line', - '--trailing-comma', 'all', - '--tab-width', '2', - '--semi', - '--single-quote', - }, - }, - formatting.shfmt.with { extra_args = { '-i', '2', '-ci', '-bn' } }, - formatting.sqlfluff.with { extra_args = { '--dialect', 'tsql' } }, - }, + sources = sources, } end diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index 88ae0cf2d9c..8926b656f27 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -44,6 +44,7 @@ return { require('mason-tool-installer').setup { ensure_installed = { 'lua-language-server', + 'stylua', -- Lua formatter 'marksman', -- Go tools 'gopls', -- Go LSP @@ -64,8 +65,10 @@ return { 'debugpy', -- Python debugger -- SQL tools 'sqls', -- Advanced SQL LSP - -- Elixir - 'elixir-ls' -- Elixir LSP + -- Shell tools + 'bash-language-server', -- Bash LSP + 'shellcheck', -- Shell linter + 'shfmt', -- Shell formatter }, auto_update = true, run_on_start = true, diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua index 0a38e72d853..0e7f0b0a349 100644 --- a/lua/plugins/nvim-treesitter.lua +++ b/lua/plugins/nvim-treesitter.lua @@ -1,54 +1,53 @@ return { - -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - }, - build = function() - local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) - ts_update() - -- Install C++ parser explicitly to avoid tarball issues - vim.cmd('silent! TSInstall cpp') - end, - main = 'nvim-treesitter.configs', -- Sets main module to use for opts - -- [[ Configure Treesitter ]] See `:help nvim-treesitter` - opts = { - -- List of languages to ensure are installed - ensure_installed = { - 'bash', 'c', 'cpp', 'diff', 'html', 'lua', 'luadoc', - 'markdown', 'markdown_inline', 'python', 'rust', - 'javascript', 'typescript', 'json', 'yaml', 'query', - 'vim', 'vimdoc', 'comment', 'regex' - }, - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - -- Automatically install missing parsers when entering buffer - auto_install = true, - -- List of parsers to ignore installing (for "all") - ignore_install = { 'phpdoc' }, + { + 'nvim-treesitter/nvim-treesitter', + branch = 'main', + lazy = false, + build = ':TSUpdate', + config = function() + local parsers = { + 'bash', 'c', 'cpp', 'diff', 'html', 'lua', 'luadoc', + 'markdown', 'markdown_inline', 'python', 'rust', + 'javascript', 'typescript', 'tsx', 'json', 'yaml', 'query', + 'vim', 'vimdoc', 'comment', 'regex', 'go', 'gomod', 'gosum', + } + + local nts = require('nvim-treesitter') + local installed = nts.get_installed and nts.get_installed('parsers') or {} + local have = {} + for _, p in ipairs(installed) do have[p] = true end + local missing = {} + for _, p in ipairs(parsers) do + if not have[p] then table.insert(missing, p) end + end + if #missing > 0 then nts.install(missing) end + + local max_filesize = 100 * 1024 + vim.api.nvim_create_autocmd('FileType', { + callback = function(args) + local buf = args.buf + local lang = vim.treesitter.language.get_lang(vim.bo[buf].filetype) + if not lang then return end + local ok_p = pcall(vim.treesitter.language.add, lang) + if not ok_p then return end - highlight = { - enable = true, - -- Additional filetypes to enable highlighting for - additional_vim_regex_highlighting = { 'ruby' }, - -- Disable for large files - disable = function(_, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - }, - indent = { - enable = true, - disable = { 'ruby', 'yaml' } - }, + local fname = vim.api.nvim_buf_get_name(buf) + local ok, stats = pcall(vim.loop.fs_stat, fname) + if ok and stats and stats.size > max_filesize then return end + + pcall(vim.treesitter.start, buf, lang) + + if lang ~= 'yaml' then + vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, + }) + end, + }, + { + 'nvim-treesitter/nvim-treesitter-textobjects', + branch = 'main', + dependencies = { 'nvim-treesitter/nvim-treesitter' }, + event = 'VeryLazy', }, - -- There are additional nvim-treesitter modules that you can use to interact - -- with nvim-treesitter. You should go explore a few and see what interests you: - -- - -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` - -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects }