codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.76k stars 368 forks source link

Python language parser does not properly indent else clause in for and while loops #1363

Closed sergeichestakov closed 6 months ago

sergeichestakov commented 6 months ago

Describe the issue

It seems the Python parser does not correctly handle for/else loops and while/else loops, particularly with respect to indentation in nested blocks.

Admittedly, I myself only just found this out but turns out an else clause in a while or for loop is valid Python code (see docs and examples) so I believe the Python parser should handle it appropriately and indent else clauses the same as it does with a matching if statement.

See repro gif below to showcase what I mean:

python-for-while-indentation-bug

Browser and platform

latest MacOS, Firefox (but should repro in all)

Reproduction link

https://replit.com/@SergeiChestakov/cm-py-indentation-bug

marijnh commented 6 months ago

Attached patch adds indentation logic that should handle this.