Handle comment nodes within text objects #548
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While I was editing my config for this very plugin, commenting and uncommenting lines in the config table, I tried to make use of the
@parameter
text objects and noticed some unexpected behaviour around comment nodes. The relevant query, it turns out, naively assumes that table constructors consist of single nodes separated by commas. In reality, there could be any number of nodes between those commas: onefield
, and any number ofcomment
.Unfortunately, due to some limitations of treesitter queries (in particular, the fact that the dot anchor ignores anonymous nodes) I was unable to find a simple modification to the existing queries that would account for all cases. Instead, two new queries had to be added, in addition to some slight modifications to the existing queries. I would really like to discover that I've missed an obvious, more succinct solution.
I suspect there are many other queries across all supported languages that have similar room for improvement, but I don't have the time or energy to fix them all, hence the draft PR. It's my intention to continue improving queries as I encounter more edge cases, and my hope that others can apply a similar approach across other queries in the project.