Skip to content
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

Structural editing hangs in specific cases of unbalanced forms #1585

Closed
ghost opened this issue Mar 8, 2022 · 8 comments
Closed

Structural editing hangs in specific cases of unbalanced forms #1585

ghost opened this issue Mar 8, 2022 · 8 comments
Labels
bug Something isn't working token-cursor

Comments

@ghost
Copy link

ghost commented Mar 8, 2022

Works as intended in: v2.0.249
Broken in: v2.0.252

When using Calva and connected to a REPL, if you follow the following steps you will enter a state where you can no longer delete any text, no matter the context (via the delete key, highlighting and replacing with text still works).

To reproduce I do the following:

Connect to a local REPL.
Enter the following form (let [a "123"] a).
Move my cursor to the right of the ] character.
Press backspace until I get (let [a] a).
Highlight and backspace on ].

Now I can no longer delete any other characters in any file. I have to restart/refresh VS code and REPL to regain working functionality.

@PEZ
Copy link
Collaborator

PEZ commented Mar 8, 2022

Thanks for reporting! I started to look at this, but can't reproduce it. Let's hope we can collect some more clues. If you have the time it would be great if you could run Calva in development mode and see if you can catch this in the debugger. There's info on how to hack on Calva in the wiki.

@PEZ PEZ added bug Something isn't working token-cursor labels Mar 8, 2022
@PEZ
Copy link
Collaborator

PEZ commented Mar 8, 2022

Can you see if it seem like Calva is in some infinite loop or something? With #1573 that was the case, but this one sounds a bit different... The way we saw that Calva was stuck in a loop was that one of the cores of the machine got 100% occupied by VS Code.

Also please check if structural editing has stopped working in all files when this happens, or if it is isolated the current one.

PEZ added a commit that referenced this issue Mar 8, 2022
@PEZ
Copy link
Collaborator

PEZ commented Mar 8, 2022

Also please check if structural editing has stopped working in all files when this happens, or if it is isolated the current one.

Sorry, I now also saw:

Now I can no longer delete any other characters in any file.

PEZ added a commit that referenced this issue Mar 8, 2022
PEZ added a commit that referenced this issue Mar 8, 2022
@PEZ
Copy link
Collaborator

PEZ commented Mar 8, 2022

I can reproduce a very similar issue now:

With this text (the vertical bar represents the cursor):

(let [a| a)

Pareedit Barf Sexp Forward

The barf happens:

(let [a|) a

But also... BOOM! One CPU core now occupied 100%, structural editing is dead. (Calva pretty much unusable).

@PEZ
Copy link
Collaborator

PEZ commented Mar 9, 2022

Here's a video of when I reproduce the issue:

calva-cursor-hang-1585.mp4

@PEZ
Copy link
Collaborator

PEZ commented Mar 9, 2022

It happens when we try to find the opening paren while ”inside” the unbalanced vector. This test exposes it:

        it('Moves backward in balanced list when inner list is unbalanced', () => {
            // https://github.com/BetterThanTomorrow/calva/issues/1585
            const a = docFromTextNotation('(let [a|)');
            const b = docFromTextNotation('(let [|a)');
            const cursor: LispTokenCursor = a.getTokenCursor(a.selectionLeft);
            const result = cursor.backwardListOfType('(');
            expect(cursor.offsetStart).toBe(b.selectionLeft);
            expect(result).toBe(true);
        });

image

Not sure we're at the root of the problem yet, but certainly closer.

PEZ added a commit that referenced this issue Mar 9, 2022
@PEZ
Copy link
Collaborator

PEZ commented Mar 9, 2022

Fixed it in my branch now. Will create a PR and we can test the VSIX to get a release out quickly. Then I'll continue looking for more places where we should make similar changes as the ones I did to fix this.

@PEZ PEZ mentioned this issue Mar 9, 2022
14 tasks
@PEZ
Copy link
Collaborator

PEZ commented Mar 9, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working token-cursor
Projects
None yet
Development

No branches or pull requests

1 participant