Skip to content
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

Allow configuring tree traversal start location #27

Closed
JoosepAlviste opened this issue Nov 3, 2021 · 0 comments · Fixed by #28
Closed

Allow configuring tree traversal start location #27

JoosepAlviste opened this issue Nov 3, 2021 · 0 comments · Fixed by #28
Labels
enhancement New feature or request

Comments

@JoosepAlviste
Copy link
Owner

JoosepAlviste commented Nov 3, 2021

Original issue / problem: numToStr/Comment.nvim#10 (comment)

Add a way to customize the location where the treesitter tree traversal is started (currently only on the first non-blank char on the cursor's line). This would make it possible to comment something like this in JSX when running gciW:

<View /* style={styles.foobar} */ />

I think that it would make sense if update_commentstring would accept the position as an argument. If nothing passed in, then the cursor start of line, but if there is some location passed in, then we can use that one. For example, the Comment.nvim integration can use getpos("'<") to get the visual selection start location instead of the cursor location. Or if there's no visual selection, then for the above example use the cursor location (or motion start location somehow?).

@JoosepAlviste JoosepAlviste added the enhancement New feature or request label Nov 3, 2021
@JoosepAlviste JoosepAlviste changed the title Allow configuring tree traversal Allow configuring tree traversal start location Nov 3, 2021
JoosepAlviste added a commit that referenced this issue Nov 3, 2021
Make it possible to configure where the `commentstring` detection logic
starts in the treesitter AST. The default is to start at the start of
the cursor's line (first non-blank character). However, this is not 100%
correct when commenting with motions.

`update_commentstring` now accepts a location where to start the
analysis so that when integrating with a commenting plugin, more
granular control is possible.

Additionally, a few useful helper functions are exported from
`ts_context_commentstring.utils` which make it simpler to pass in a
location.

Resolves #27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant