cursorless
cursorless copied to clipboard
New text-based `"item"` doesn't play nicely with comments
In the following code:
[
"foo", // this is a comment
"bar",
];
The comment is treated as part of the second item. This behaviour is quite unexpected, even thought it's clear why it's happening. Not entirely sure what to do here. I don't remember for certain, but I believe it used to work with the old "item"
.
We have the same problem with our current argument which use to share implementation with the old item so I don't believe this is a new bug in the text based implementation
Note that this behaviour is even more confusing if there is a '
in the comment, eg // don't do something
, because then the collectionItem
scope starts looking for the other '
and starts eating everything until it sees another '
or the end of the containing pair 😳
Def provides evidence against textual "item"
imo. I wonder if we should split into two scope types and turn spoken form for one of them off by default...
The nice thing about the tree-sitter scope is that tree-sitter does error recovery, whereas the textual scope type can go haywire if it gets tricked. I wonder if we could make the textual one more robust, whether or not we turn it off by default
We could also possibly re-add the old collectionItem
definitions, but still allow it to fall back to textual if it can't find anything
I mean that is just a bug.
If you want to have two different scope types then go ahead, but I'm convinced that we can make the current implementation better.
The fall back support is already there so just adding the language definitions should work. The annoying part of course is that the code to extract leading/trailing range and insertion delimiter is not the same between these two implementations, but that we of course could fix.
How would you propose to fix this bug for textual item? Just don't allow strings to cross lines?
I was thinking that we should at least look for a matching pair. A single '
should just be ignored.
I have now updated the the textual item code to ignore starting delimiter without the closing match. https://github.com/cursorless-dev/cursorless/pull/1559