-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
Have not tested at all, no idea if it will even "compile".
|
||
# If there's a remainder, `editor.buildIndentString` requires the tab to | ||
# be set past the desired indentation level, thus the ceiling. | ||
# TODO: is the conditional necessary? Maybe to avoid floating point errors? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is because of the possibility that rem
could be 0, which is totally acceptable. I remember this when testing through everything, though I can't remember the exact scenario.
I made some basic comments on what you have here. Excellent work so far. These kinds of improvements would make the package much better. Thanks! Edit: I was making some changes/major refactors in the past hour or so. I might merge them this week. They don't really change logic...just module structure/organization. Just keep on working with what you've got, and I can always fix any conflicts that come from your branch later. |
Sounds good. |
Per the suggestion by DSpeckhals.
Sort of works with function definitions as well. More to come on that later.
Ok, as of db36a0b this is working on all of the test cases (which are all in BTW, I also had a ~600 line python file that I played around with and noticed no performance issues. |
lastFunctionRow = parseOutput.lastFunctionRow | ||
|
||
if shouldHang | ||
console.log('here') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can probably guess, you'll want to take out the log statements.
I left some more comments. This is getting pretty close! When you're happy with me testing this for a day or 2 in real life, let me know; then I'll pull your branch, resolve conflicts, and try it out. |
Added documentation, fixed some style concerns. Only keep track of the last place a bracket was closed instead of a whole stack since that's all that's needed for the parsing. Rearranged logic for when hanging indent should be used to accomodate comments on the line before a hanging indent is used.
Added more documentation to the parsing section, fixed the style suggestions, and made a couple other minor changes (one performance based, the other should allow hanging indents to be correctly triggered when a comment was entered before pressing enter for the newline that should have the hanging indent). I believe this version (cd8814a) should be ready for you to test. |
Super! I'll hammer away at it tomorrow. |
I resolved the conflicts without much trouble, and will test over the next 24 hours or so. I should be able to release tomorrow. The reason I originally put this package together was for purely selfish reasons. I was surprised by the response and help from everyone. Your contributions have made it magnitudes better. I look forward to using it "out in the wild." Thanks so much, again! 👏 |
Overview
This PR is a work in progress.
This version of the code does a rudimentary parsing of the python source code, keeping track of brackets and doing _very_ rudimentary bracket matching (if the python source code is not well-formed then bad things could happen).
Implementation notes
(A note on terminology, I use "bracket" to refer to any of the
[](){}
characters.)Essentially, simple parsing is performed to keep a stack of the column-location of open brackets (one of
[({
). When an opening bracket is read, it adds to the stack indicating the column where the bracket is located, when a closing bracket (one of})]
) is read, it pops the latest element (it does not do any checking to make sure the closing bracket matches the opening bracket - this is why it assumes the python source code is well-formed). If there is anything in the stack after parsing the python file up to the cursor location, then that means there is an open bracket. We can see what column the most recent addition to the stack was on, and then set the indent from that.TODO
Ordered in what I perceive to be most important (top) to least important (bottom):
test/test_file.py
) that has all of the more pathological cases I could think of. Is it possible to automate a test based on this somehow? Don't really know much about testing or testing frameworks.Finished