init.lua icon indicating copy to clipboard operation
init.lua copied to clipboard

Disable LSP while in a comment

Open twiclo opened this issue 3 years ago • 1 comments

Can anyone point me in the right direction on which setting needs to be set/which plugin needs to be looked at for this?

twiclo avatar Dec 22 '22 22:12 twiclo

The plugin that handles autocompletion is nvim-cmp. And it looks like there is a way to check if the cursor is in a comment.

Now, you won't be able to enable that feature using the recommended preset. You'll have to change to lsp-compe and handle the config in another way. Here is a minimal config.

local lsp = require('lsp-zero')
lsp.preset('lsp-compe')

lsp.setup()

vim.opt.completeopt = {'menu', 'menuone', 'noselect'}

local cmp = require('cmp')
local cmp_config = lsp.defaults.cmp_config({})

cmp_config.enabled = function()
  if require('cmp.config.context').in_treesitter_capture('comment') == true
    or require('cmp.config.context').in_syntax_group('Comment') then
    return false
  else
    return true
  end
end

cmp.setup(cmp_config)

VonHeikemen avatar Dec 24 '22 16:12 VonHeikemen