kbrose / vsc-python-indent

Correctly indent python code on the fly, in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent
MIT License
82 stars 19 forks source link

Vendor in the parser so we can track ifs/trys etc. across multiple lines #101

Closed kbrose closed 2 years ago

kbrose commented 2 years ago

Checklist

Description

Fixes #98

In order to dedent a given else, elif, etc., we look for its corresponding if, try, etc.. This was done naively just looking for colons and the corresponding if, try on the same line, so if a multi-line if/try was used we wouldn't find it.

This MR vendors in the parser from https://github.com/DSpeckhals/python-indent-parser and updates it to track the last observed line for the different indentation keywords.

The logic for dedenting is updated to use this last-observed line for the corresponding indenting keywords.