From b99f7b5386f6a1b73a9f9d3f640e1e0e99a3cf4b Mon Sep 17 00:00:00 2001 From: jasmine Date: Thu, 25 Sep 2025 11:20:44 +0800 Subject: [PATCH 1/2] update completions logic --- config/plugins/cmp/cmp.nix | 89 +++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/config/plugins/cmp/cmp.nix b/config/plugins/cmp/cmp.nix index 73a9348..6db0159 100644 --- a/config/plugins/cmp/cmp.nix +++ b/config/plugins/cmp/cmp.nix @@ -6,47 +6,76 @@ # Options provided to the require('cmp').setup function. settings = { + # Disable autocompletion by default + completion.autocomplete = false; + # The sources to use sources = [ - { # Language Server Protocol - name = "nvim_lsp"; - } + # Language Server Protocol + { name = "nvim_lsp"; } - { # Buffer Words - name = "buffer"; - } + # Buffer Words + { name = "buffer"; } - { # Filesystem paths - name = "path"; - } + # Filesystem paths + { name = "path"; } - { # Markdown - name = "render_markdown"; - } + # Markdown + { name = "render_markdown"; } - { # VimTex - name = "vimtex"; - } + # VimTex + { name = "vimtex"; } - { # Neorg - name = "neorg"; - } + # Neorg + { name = "neorg"; } ]; # Key mappings for the completion menu. mapping = { - "" = - # Lua - "cmp.mapping.close()"; - "" = - # Lua - "cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})"; - "" = - # Lua - "cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})"; - "" = - # Lua - "cmp.mapping.confirm({ select = true })"; + # Confirm candidate on TAB immediately when there's only one completion entry + "" = /* lua */ '' + cmp.mapping(function(fallback) + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + + -- When the selection menu is open select the next item + if cmp.visible() then + cmp.select_next_item({behavior = cmp.SelectBehavior.Select}) + -- Ensure we are mid word + elseif col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil then + -- Open the selection menu + cmp.complete() + -- Autocomplete when there is only 1 selection available + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true }) + end + -- Select the firt item + cmp.select_next_item({behavior = cmp.SelectBehavior.Select}) + -- Keep regular functionality of tab + else + fallback() + end + end, {'i', 's'}) + ''; + + # Confirm selection + "" = /* lua */ '' + cmp.mapping.confirm({ select = true }) + ''; + + # Select the next item in the menu + "" = /* lua */ '' + cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'}) + ''; + + # Select the prev item in the menu + "" = /* lua */ '' + cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'}) + ''; + + # Exit the completion menu + "" = /* lua */ '' + cmp.mapping.close() + ''; }; }; }; From 48b93a848e5132c007cfbd0075f264a7719d75a8 Mon Sep 17 00:00:00 2001 From: jasmine Date: Thu, 25 Sep 2025 11:21:07 +0800 Subject: [PATCH 2/2] remove dap --- config/default.nix | 14 +-- config/plugins/dap/dap-python.nix | 53 --------- config/plugins/dap/dap-ui.nix | 19 ---- config/plugins/dap/dap-virtual-text.nix | 5 - config/plugins/dap/dap.nix | 143 ------------------------ 5 files changed, 4 insertions(+), 230 deletions(-) delete mode 100644 config/plugins/dap/dap-python.nix delete mode 100644 config/plugins/dap/dap-ui.nix delete mode 100644 config/plugins/dap/dap-virtual-text.nix delete mode 100644 config/plugins/dap/dap.nix diff --git a/config/default.nix b/config/default.nix index a2315b0..ed1e517 100644 --- a/config/default.nix +++ b/config/default.nix @@ -11,15 +11,13 @@ ./plugins/collections/mini.nix ./plugins/collections/snacks.nix + # LSP and Formatting + ./plugins/lsp/conform.nix + ./plugins/lsp/lsp.nix + # Completion & AI Assistancee ./plugins/cmp/cmp.nix - # Debugging (DAP) - ./plugins/dap/dap.nix - ./plugins/dap/dap-ui.nix - ./plugins/dap/dap-virtual-text.nix - ./plugins/dap/dap-python.nix - # Editor Enhancements ./plugins/editor/commentary.nix ./plugins/editor/harpoon.nix @@ -34,10 +32,6 @@ ./plugins/ui/web-devicons.nix ./plugins/ui/whichkey.nix - # LSP and Formatting - ./plugins/lsp/conform.nix - ./plugins/lsp/lsp.nix - # Git Integration ./plugins/git/fugitive.nix ./plugins/git/gitsigns.nix diff --git a/config/plugins/dap/dap-python.nix b/config/plugins/dap/dap-python.nix deleted file mode 100644 index d71888f..0000000 --- a/config/plugins/dap/dap-python.nix +++ /dev/null @@ -1,53 +0,0 @@ -{ ... }: { - plugins.dap-python = { - enable = true; - }; - - keymaps = [ - { - mode = ["n" "v"]; - key = "dP"; - action = ""; - options = { - silent = true; - desc = "+python"; - }; - } - - { - mode = ["n"]; - key = "dPm"; - action = { - __raw = "require('dap-python').test_method"; - }; - options = { - silent = true; - desc = "Test method"; - }; - } - - { - mode = ["n"]; - key = "dPc"; - action = { - __raw = "require('dap-python').test_class"; - }; - options = { - silent = true; - desc = "Test Class"; - }; - } - - { - mode = ["v"]; - key = "dPs"; - action = { - __raw = "require('dap-python').debug_selection"; - }; - options = { - silent = true; - desc = "Debug selection"; - }; - } - ]; -} diff --git a/config/plugins/dap/dap-ui.nix b/config/plugins/dap/dap-ui.nix deleted file mode 100644 index 48cc272..0000000 --- a/config/plugins/dap/dap-ui.nix +++ /dev/null @@ -1,19 +0,0 @@ -{...}: { - plugins.dap-ui = { - enable = true; - }; - - keymaps = [ - { - mode = ["n"]; - key = "du"; - action = { - __raw = "require('dapui').toggle"; - }; - options = { - silent = true; - desc = "Toggle UI"; - }; - } - ]; -} diff --git a/config/plugins/dap/dap-virtual-text.nix b/config/plugins/dap/dap-virtual-text.nix deleted file mode 100644 index 9f7b378..0000000 --- a/config/plugins/dap/dap-virtual-text.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ ... }: { - plugins.dap-virtual-text = { - enable = true; - }; -} diff --git a/config/plugins/dap/dap.nix b/config/plugins/dap/dap.nix deleted file mode 100644 index a9dcd94..0000000 --- a/config/plugins/dap/dap.nix +++ /dev/null @@ -1,143 +0,0 @@ -{...}: { - plugins.dap = { - enable = true; - }; - - keymaps = [ - # Prefix: dap - { - mode = ["n" "v"]; - key = "d"; - action = ""; - options = { - silent = true; - desc = "+dap"; - }; - } - - - # Session management: - { - mode = ["n"]; - key = "dc"; - action = "DapContinue"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dq"; - action = "DapDisconnect"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dn"; - action = "DapNew"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dQ"; - action = "DapTerminate"; - options = { - silent = true; - }; - } - - - # Stepping: - { - mode = ["n"]; - key = "dr"; - action = "DapRestartFrame"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "di"; - action = "DapStepInto"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dO"; - action = "DapStepOut"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "do"; - action = "DapStepOver"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dp"; - action = "DapPause"; - options = { - silent = true; - }; - } - - - # Repl: - { - mode = ["n"]; - key = "dE"; - action = "DapEval"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "dR"; - action = "DapToggleRepl"; - options = { - silent = true; - }; - } - - - # Breakpoints: - { - mode = ["n"]; - key = "dB"; - action = "DapClearBreakpoints"; - options = { - silent = true; - }; - } - - { - mode = ["n"]; - key = "db"; - action = "DapToggleBreakpoint"; - options = { - silent = true; - }; - } - ]; -}