Skip to content

Commit 5244384

Browse files
committed
Add context commentstring
1 parent cc74fb5 commit 5244384

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lua/custom/plugins/Comment.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
return {
22
-- use "gc" to comment visual regions/lines
33
'numToStr/Comment.nvim',
4-
config = function() require('Comment').setup() end
4+
dependencies = { 'JoosepAlviste/nvim-ts-context-commentstring' },
5+
config = function() require('Comment').setup({
6+
pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
7+
})
8+
end
59
}
610

lua/custom/plugins/Comment.nvim

Lines changed: 0 additions & 3 deletions
This file was deleted.

lua/custom/plugins/nvim-treesitter.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ return { -- Highlight, edit, and navigate code
44
event = {'BufReadPre', 'BufNewFile'},
55
dependencies = {
66
'nvim-treesitter/nvim-treesitter-textobjects',
7+
'JoosepAlviste/nvim-ts-context-commentstring' -- language/context aware comment strings (ex: for JSX)
78
},
89
config = function()
910
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
return {
2+
-- Context aware comment strings.
3+
-- For instance JSX has two types of comments, // for regular javascript/typescript, and { /* ... */ } for JSX
4+
-- This treesitter extension allows to set the correct comment string based on code context
5+
-- Use Comment.nvim to apply the commentstrings easyly (with 'gcc')
6+
"JoosepAlviste/nvim-ts-context-commentstring",
7+
lazy = true, -- Only loaded when treesitter loads (since it is specified as a dependency of treesitter)
8+
config = function()
9+
require('ts_context_commentstring').setup {
10+
enable_autocmd = false,
11+
}
12+
end,
13+
}

0 commit comments

Comments
 (0)