You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding basic support of treesitter for calculating `commentstring` which works most of the time and might be all that someone needs. But due to the nature of the parsed tree, this implementation has some known limitations.
1. No `jsx/tsx` support. Its implementation was quite complicated.
2. Invalid comment on the region where one language ends and the other starts. See #62 (comment)
For more advance use cases you should use https://github.com/JoosepAlviste/nvim-ts-context-commentstring. See hooks section.
First you need to call the `setup()` method to create the default mappings.
46
46
47
-
-Lua
47
+
- Lua
48
48
49
49
```lua
50
50
require('Comment').setup()
51
51
```
52
52
53
-
-VimL
53
+
- VimL
54
54
55
55
```vim
56
56
lua << EOF
@@ -138,7 +138,7 @@ When you call [`setup()`](#setup) method, `Comment.nvim` sets up some basic mapp
138
138
139
139
These mappings are enabled by default. (config: `mappings.basic`)
140
140
141
-
-NORMAL mode
141
+
- NORMAL mode
142
142
143
143
```help
144
144
`gcc` - Toggles the current line using linewise comment
@@ -152,7 +152,7 @@ These mappings are enabled by default. (config: `mappings.basic`)
152
152
153
153
> NOTE: Dot repeat is not supported with `[count]gcc`
154
154
155
-
-VISUAL mode
155
+
- VISUAL mode
156
156
157
157
```help
158
158
`gc` - Toggles the region using linewise comment
@@ -163,7 +163,7 @@ These mappings are enabled by default. (config: `mappings.basic`)
163
163
164
164
These mappings are enabled by default. (config: `mappings.extra`)
165
165
166
-
-NORMAL mode
166
+
- NORMAL mode
167
167
168
168
```help
169
169
`gco` - Insert comment to the next line and enters INSERT mode
@@ -175,7 +175,7 @@ These mappings are enabled by default. (config: `mappings.extra`)
175
175
176
176
These mappings are disabled by default. (config: `mappings.extended`)
177
177
178
-
-NORMAL mode
178
+
- NORMAL mode
179
179
180
180
```help
181
181
`g>[count]{motion}` - (Op-pending) Comments the region using linewise comment
@@ -186,7 +186,7 @@ These mappings are disabled by default. (config: `mappings.extended`)
186
186
`g<b`- Uncomments the current line using blockwise comment
187
187
```
188
188
189
-
-VISUAL mode
189
+
- VISUAL mode
190
190
191
191
```help
192
192
`g>` - Comments the region using single line
@@ -234,13 +234,24 @@ require('Comment').toggle()
234
234
235
235
Read [API](./API.md) for more crazy stuff.
236
236
237
+
<aid="treesitter"></a>
238
+
239
+
### 🌳 Treesitter
240
+
241
+
This plugin also has the basic support of treesitter for calculating `commentstring` which works most of the time and might be all that someone needs. But due to the nature of the parsed tree, this implementation has some known limitations.
242
+
243
+
1. No `jsx/tsx` support. Its implementation was quite complicated.
244
+
2. Invalid comment on the region where one language ends and the other starts. [Read more](https://github.com/numToStr/Comment.nvim/pull/62#issuecomment-972790418)
245
+
246
+
For more advance use cases you should use [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring). See [hooks](#hooks) section.
247
+
237
248
<aid="hooks"></a>
238
249
239
250
### 🎣 Hooks
240
251
241
252
There are two hook methods i.e `pre_hook` and `post_hook` which are called before comment and after comment respectively. Both should be provided during [`setup()`](#setup).
242
253
243
-
-`pre_hook` - This method is called with a [`ctx`](#comment-context) argument before comment/uncomment is started. It can be used to return a custom `commentstring` which will be used for comment/uncomment the lines. You can use something like [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring) to compute the commentstring using treesitter.
254
+
-`pre_hook` - This method is called with a [`ctx`](#comment-context) argument before comment/uncomment is started. It can be used to return a custom `commentstring` which will be used for comment/uncomment the lines. You can use something like [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring) to compute the commentstring using treesitter.
244
255
245
256
```lua
246
257
-- NOTE: The example below is a proper integration and it is RECOMMENDED.
@@ -285,7 +296,7 @@ Also, you can set the `commentstring` from here but [**i won't recommend it**](#
285
296
}
286
297
```
287
298
288
-
-`post_hook` - This method is called after commenting is done. It receives the same 1) [`ctx`](#comment-context), the lines range 2) `start_row` 3) `end_row` 4) `start_col` 5) `end_col`.
299
+
-`post_hook` - This method is called after commenting is done. It receives the same 1) [`ctx`](#comment-context), the lines range 2) `start_row` 3) `end_row` 4) `start_col` 5) `end_col`.
289
300
290
301
> NOTE: If [methods](#methods) are used, then `post_hook` will receives only two arguments 1) [`ctx`](#comment-context) and 2) `-1` indicating the current line
291
302
@@ -316,7 +327,7 @@ You can use `ignore` to ignore certain lines during comment/uncomment. It can ta
316
327
317
328
> NOTE: Ignore only works when with linewise comment. This is by design. As ignoring lines in block comments doesn't make that much sense.
Although, `Comment.nvim` supports neovim's `commentstring` but unfortunately it has the least priority. The commentstring is taken from the following place in the respective order.
393
404
394
-
-[`pre_hook`](#hooks) - If a string is returned from this method then it will be used for commenting.
405
+
-[`pre_hook`](#hooks) - If a string is returned from this method then it will be used for commenting.
395
406
396
-
-[`ft_table`](#languages) - If the current filetype is found in the table, then the string there will be used.
407
+
-[`ft_table`](#languages) - If the current filetype is found in the table, then the string there will be used.
397
408
398
-
-`commentstring` - Neovim's native commentstring for the filetype
409
+
-`commentstring` - Neovim's native commentstring for the filetype
399
410
400
411
<aid="commentstring-caveat"></a>
401
412
@@ -412,6 +423,7 @@ The following object is provided as an argument to `pre_hook` and `post_hook` fu
412
423
```lua
413
424
---Comment context
414
425
---@classCtx
426
+
---@fieldlangstring: The name of the language where the cursor is
415
427
---@fieldctypeCType
416
428
---@fieldcmodeCMode
417
429
---@fieldcmotionCMotion
@@ -433,27 +445,14 @@ There are multiple ways to contribute reporting/fixing bugs, feature requests. Y
433
445
434
446
### 💐 Credits
435
447
436
-
-[tcomment]() - To be with me forever and motivated me to write this.
437
-
-[nvim-comment](https://github.com/terrortylor/nvim-comment) - Little and less powerful cousin. Also I took some code from it.
438
-
-[kommentary](https://github.com/b3nj5m1n/kommentary) - Nicely done plugin but lacks some features. But it helped me to design this plugin.
448
+
-[tcomment]() - To be with me forever and motivated me to write this.
449
+
-[nvim-comment](https://github.com/terrortylor/nvim-comment) - Little and less powerful cousin. Also I took some code from it.
450
+
-[kommentary](https://github.com/b3nj5m1n/kommentary) - Nicely done plugin but lacks some features. But it helped me to design this plugin.
0 commit comments