-
-
Notifications
You must be signed in to change notification settings - Fork 84
structural editing when cursor is right outside the structure #436
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
Comments
Heyo, I might pick this one up. I'll put a PR up and I think perhaps add some testing infrastructure within the parse project as well. |
I'm looking at this a bit more and am not sure that the whitespace approach will work for all languages. In typescript for example, there is a non-whitespace statement terminator,
These terminators/separators could be specified if we want but all of that configuration happens in the other package. I'm going to hold off on this for a bit and think about it further. I took a cursory look at the alternate approach. If I understand it correctly, what would happen is:
I'm still not sure this will work in every case and in every language. I think it will work with in the case of a variable definition in Ruby, but in the case below, I don't think there is an overlap for "take funk".
I guess what I'm saying is that we might need to know more about the language to be able to make a smart choice here, unless I'm thinking about this incorrectly. Slightly unrelated, for futureWould it ever make sense to pass both down to allow for smarter inference based on the modifiers of an action? This is not a suggestion for this issue but just an observation that it might allow for more power in situations where objects are nested, such as:
Being able to say |
Fair point re white space. I guess the issue is
And you say I think this does argue for the alternate approach, though I'm not sure if you're interpreted that one correctly The alternative approach would happen in cursorless, rather than in parse tree extension, fwiw. Cursorless would first do its normal thing, walking up the ancestor tree from the token to the right of the cursor, yielding either a matching node or no match. But it would then move selection one left and do it's normal thing again walking from there, either getting a matching node or not.
So in your "funk" example, only the left one matches, so you'd return it, as desired. Note that if the function were nested in a bigger function, they'd both match, but the one we want is the smaller one, so we're still ok I believe the above nicely handles the case where the input to the modifier has zero length. When the input is a range (eg "funk air"), I think the easy thing is to just walk up from the token to the right of the start of the range, like we do today. Make sense? |
Yep, definitely makes sense. We've got a reference to a I'm likely going to operate at the In any event, I've got a good idea about how to proceed, thanks. |
I would start by only applying to |
Just a note - #629 should fix and close this. |
- Partially addresses #616 - Partially addresses #436 - Depends on #1396 ## Todo - [x] **[DISCUSS]** What to do about fallback `iterationScope`? That's the only thing that is a regression here. - [x] File issues for FIXMEs - [x] File issue for defining iteration scopes. Can probably reuse most of the code from the regular scope handler other than creating the target - [x] File issue to add unit tests for scope handlers - [x] File issue to add some Python scope types where multiple can end at the same point (due to lack of closing brackets) - [x] Add test that checks no scope types are duplicated between legacy and new definition, or file issue to add test - [x] File PR for my 7783da6 (Add support for domain, leading, trailing, interior) #1427 - [x] Look through comments on this thread for anything worth filing / doing - [x] Open as new PR? - [x] Remove extraneous test cases - [x] Double check #629 (comment); a lot of those tests we already have for the generic modifier code - [x] Make sure changes to parse-tree-extension are shipped - [x] Close #785 if we fix that - [x] Comment on #484 saying the process has started and providing link to example - [x] Close #797 if we fix that --------- Co-authored-by: Pokey Rule <[email protected]>
closed by #629 |
The problem
Consider something like
and suppose the cursor is at the end of the print statement, after the
)
.Currently
take funk
does not select the function when the cursor is at that position, though it does work if the cursor is anywhere before the final)
.edit (@pokey):
Why does this happen?
Cursorless relies on the Parse tree extension to get the current node, and then walks up from there. The problem is that this function just passes a position to web-tree-sitter's
rootNode.descendantForPosition
, which will always look to the right, so if there is whitespace to the right, it will go way up the tree to find a node that contains the given whitespace.The solution
We should probably fix this one inside the parse tree extension. In
getNodeAtLocation
, we will proceed by trying to find an appropriate position to pass to web-tree-sitter, rather than just directly using the given position:We then take the position and pass it to
rootNode.descendantForPosition
, like we do todayAlternate solution
If the above doesn't work for some reason, we could instead always instead first ask for the node from position like today, but then subtract one from position and ask again, and if they overlap, take the smaller one
The text was updated successfully, but these errors were encountered: