-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Text object for comments #11
Comments
This is interesting and also useful. I probably go with the treesitter to implement this :) |
I made some progress on treesitter but now I am stuck. And I need ideas. Consider the following comment regions, they all are separated by empty lines. Should I treat them as one or three different regions? -- Hello treesitter
-- a bunch of comment
-- stack together
-- so we can catch
-- them at once
--[[
One block comment
--]] |
We need |
-- Hello treesitter
-- a bunch of comment
-- stack together
-- so we can catch
-- them at once
--[[
One block comment
--]] and 2) this will be a single region -- Hello treesitter
-- a bunch of comment
--
-- stack together
-- so we can catch
-- them at once
--
--[[
One block comment
--]] Regarding blockwise comments, I am considering all of them as separate regions. Even if they are attached. In the following, they will be treated as 3 different regions. --[[
1 block comment
--]]
--[[
2 block comment
--]]
--[[
3 block comment
--]] The only exception is when a block comment starts immediately after a linewise comment region then it will be treated as a part of the line comment region. Just like 2) example of line comment above. |
I think this should be three regions. I agree with the examples you made. |
https://github.com/RRethy/nvim-treesitter-textsubjects has single and multiline comment support in the |
@RRethy If that is possible then it would be great ;) |
I just discovered that https://github.com/nvim-treesitter/nvim-treesitter-textobjects also have (Also mentioned at #77 (comment)) |
Unfortunately, it doesn't work with line comments very well:
|
@ouuan Yes, it doesn't work with line comments. Although it works very well with block comments. Regarding the feature itself, I am still confused as to whether should I implement this myself or let the other plugins like https://github.com/nvim-treesitter/nvim-treesitter-textobjects or https://github.com/RRethy/nvim-treesitter-textsubjects provide the text objects. If any of the plugins can achieve this #11 (comment) behavior then I would recommend using that plugin. |
I agree that Comment.nvim doesn't need to implement this feature. It could be a part of another plugin or a new plugin. |
There's also a problem with multiline block comments.
/**
* multiline comment
*/ |
I think you are using the |
@ouuan Also make sure that the plugin contains queries for comments. The last time I checked https://github.com/nvim-treesitter/nvim-treesitter-textobjects was missing comments queries for some languages. |
Yes, and help is welcome :) |
There's a bug in tree-sitter queries which is blocking on this, you can see it with this query: (((_) @head . (comment) @_start . (comment)+ @_end (_) @tail)
(#not-has-type? @tail "comment")
(#not-has-type? @head "comment")
(#make-range! "range" @_start @_end)) It will find a match in this file: def foo
# foo
# foo
# foo
puts 'hello'
end But it will fail to find a match in this file with more comments, even though there should be a match. def foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
# foo
puts 'hello'
end I haven't filed anything yet, just been busy. Edit: I came across this when looking to implement a |
Temporary solution for linewise comments: #22 (comment) |
mini.comment already has this, perhaps inspirations can be drawn there? I'm not aware of the architecture but this would be really helpful, since as of now I have to choose between block comments or comment text objects, or make some Chimera of the two, none of which is ideal. |
Basically the same as tomtom/tcomment_vim#237
The text was updated successfully, but these errors were encountered: