cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

New text-based `"item"` doesn't play nicely with comments

Open pokey opened this issue 2 years ago • 1 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".

pokey avatar Jul 28 '22 17:07 pokey

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

AndreasArvidsson avatar Sep 14 '22 06:09 AndreasArvidsson

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

pokey avatar Nov 18 '22 16:11 pokey

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.

AndreasArvidsson avatar Nov 18 '22 17:11 AndreasArvidsson

How would you propose to fix this bug for textual item? Just don't allow strings to cross lines?

pokey avatar Dec 05 '22 13:12 pokey

I was thinking that we should at least look for a matching pair. A single ' should just be ignored.

AndreasArvidsson avatar Dec 05 '22 14:12 AndreasArvidsson

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

AndreasArvidsson avatar Jul 02 '23 12:07 AndreasArvidsson