question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

structural editing when cursor is right outside the structure

See original GitHub issue

The problem

Consider something like

def test():
    print("a")

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:

  1. If the position is at the end of the file, subtract one from the position, unless the file is empty, in which case just use the position
  2. Otherwise, inspect the character to the right of the position
  3. If it is whitespace, subtract one from the position
  4. Otherwise, use position

We then take the position and pass it to rootNode.descendantForPosition, like we do today

Alternate 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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pokeycommented, Mar 11, 2022

I would start by only applying to containingScope, as I don’t think it buys us anything for other modifiers, at the expense of added complexity / unpredictability

0reactions
Will-Sommerscommented, May 28, 2022

Just a note - #629 should fix and close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Structural Editing
A general principle of structural editing is to ensure that all forms are balanced at all times. This is immediately apparent when creating...
Read more >
Structural Editing · Clojure development with Spacemacs & ...
Structural Editing is a way to navigate and refactor your code without breaking parenthesis or other characters that define the structure of your...
Read more >
Forest: Structural Code Editing with Multiple Cursors
Abstract. Software developers frequently refactor code. Often, a single logical refactoring change involves changing multiple related.
Read more >
Structural Editing - Cursive
Cursive, the Clojure IDE that understands your code. Advanced structural editing, refactorings, VCS integration and much more, all out of the box.
Read more >
What text editor supports positioning the cursor anywhere ...
Virtual editing means that the cursor can be positioned where there is no actual character. This can be halfway into a tab or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found