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

Python syntax tree broken after edit that should have no effect #487

Closed
microbit-matt-hillsdon opened this issue May 14, 2021 · 2 comments
Closed

Comments

@microbit-matt-hillsdon
Copy link
Contributor

Using lang-python, start with this program:

#Amount of text here is significant !

while True:
    if function_call_quite_long():
        if True:
            pass
        else:
            pass

Delete the "else: pass" part. Reinstate it as it was.

Note that the syntax tree now has what I think are error nodes and is different from the original syntax tree.

Original syntax tree toString():

Script(Comment,WhileStatement(while,Boolean,Body(":",IfStatement(if,CallExpression(VariableName,ArgList("(",")")),Body(":",IfStatement(if,Boolean,Body(":",PassStatement(pass)),else,Body(":",PassStatement(pass)))))))) 

Syntax tree toString() after:

Script(Comment,WhileStatement(while,Boolean,Body(":",IfStatement(if,CallExpression(VariableName,ArgList("(",")")),Body(":",IfStatement(if,Boolean,Body(":",PassStatement(pass))),⚠),⚠,else,Body(":",PassStatement(pass)))))) 

There's a sandbox here with a reproduction that dumps out the syntax tree in a debug view plugin:

https://codesandbox.io/s/python-if-else-bug-xs85w

It was hard to further minimise the code. The length of the comment and the function call seemed to be significant, so I wondered whether it might be an incremental parse issue of some sort.

marijnh added a commit to lezer-parser/lr that referenced this issue May 14, 2021
FIX: Fix a bug with overeager reuse of nodes on change boundaries.

Issue codemirror/dev#487
@marijnh
Copy link
Member

marijnh commented May 14, 2021

That was indeed a bug in the incremental parsing. Upgrading to lezer 0.13.5 should help.

@marijnh marijnh closed this as completed May 14, 2021
microbit-matt-hillsdon added a commit to microbit-foundation/python-editor-v3 that referenced this issue May 17, 2021
This should fix codemirror/dev#487 (comment)

which is the cause of #113
microbit-matt-hillsdon added a commit to microbit-foundation/python-editor-v3 that referenced this issue May 17, 2021
@microbit-matt-hillsdon
Copy link
Contributor Author

I've confirmed that 0.13.5 fixes the reproduction above and my more involved original scenario. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants