init.lua
init.lua copied to clipboard
Disable LSP while in a comment
Can anyone point me in the right direction on which setting needs to be set/which plugin needs to be looked at for this?
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)