From 4e7bfd6866399754001e7c3328d5815fb73b6d5d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 30 Mar 2022 23:23:27 +0200 Subject: [PATCH] Disabling autocompletion on comments --- nvim/nvim/config/new/lua/documentation.lua | 7 ++++++- nvim/nvim/config/new/lua/lsp/cmp.lua | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nvim/nvim/config/new/lua/documentation.lua b/nvim/nvim/config/new/lua/documentation.lua index ee3568d..837884c 100644 --- a/nvim/nvim/config/new/lua/documentation.lua +++ b/nvim/nvim/config/new/lua/documentation.lua @@ -16,7 +16,12 @@ neogen.setup({ local wk = require("which-key") wk.register({ - n = { "Neogen any", "Generate documentation" }, + n = { + name = "Generate documentation", + f = { "Neogen func", "Function" }, + c = { "Neogen class", "Class" }, + t = { "Neogen type", "Type" }, + }, }, { prefix = "", }) diff --git a/nvim/nvim/config/new/lua/lsp/cmp.lua b/nvim/nvim/config/new/lua/lsp/cmp.lua index cd41068..7468b85 100644 --- a/nvim/nvim/config/new/lua/lsp/cmp.lua +++ b/nvim/nvim/config/new/lua/lsp/cmp.lua @@ -47,6 +47,17 @@ cmp.setup({ require('luasnip').lsp_expand(args.body) end, }, + enabled = function() + -- disable completion in comments + local context = require 'cmp.config.context' + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == 'c' then + return true + else + return not context.in_treesitter_capture("comment") + and not context.in_syntax_group("Comment") + end + end, mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), @@ -69,7 +80,7 @@ cmp.setup({ else fallback() end - end, { "i", "s" }), + end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then