From 753b30e2e26ec75a8b3d596be23d49e7fe96f088 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Mon, 17 Mar 2025 16:40:41 +0800 Subject: [PATCH] feat(nvf): make autocomplete not show up in comments --- users/modules/programs/nvf/input.nix | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/users/modules/programs/nvf/input.nix b/users/modules/programs/nvf/input.nix index f16c19d..24affb8 100644 --- a/users/modules/programs/nvf/input.nix +++ b/users/modules/programs/nvf/input.nix @@ -10,24 +10,51 @@ enable = true; friendly-snippets.enable = true; setupOpts = { - # Disable completion for markdown enabled = lib.generators.mkLuaInline /* lua */ '' + --- Disable completion for markdown function() return not vim.tbl_contains({"markdown"}, vim.bo.filetype) and vim.bo.buftype ~= "prompt" and vim.b.completion ~= false - end + end ''; cmdline = { enabled = true; sources = null; completion.menu.auto_show = false; }; + completion.menu.auto_show = + lib.generators.mkLuaInline + /* + lua + */ + '' + function(ctx) + --- Get the cursor position from the current window + local row, column = unpack(vim.api.nvim_win_get_cursor(0)) + --- Get the current row (1 is Neovim API giving us 1-based indexing) + --- Get the current column but don't return negative numbers + --- ignore_injections are to ignore embedded code + --- success is the result, node is the syntax node object + local success, node = pcall(vim.treesitter.get_node, { + pos = {row - 1, math.max(0, column - 1)}, + ignore_injections = false + }) + --- Types of nodes to ignore + local reject = {"comment", "line_comment", "block_comment", "string_start", "string_content", "string_end" } + --- If the node type is in the reject table, don't show the completion + if success and node and vim.tbl_contains(reject, node:type()) then + return false; + end + -- whatever other logic you want beyond this + return true + end + ''; # menu.auto_show = false; completion.documentation.auto_show_delay_ms = 0; signature.enabled = true;