First draft of new closeHangingIndent option
PR for https://github.com/kbrose/vsc-python-indent/issues/127
Based on manual testing, this change does what I want, except in one situation, and has one bug that I'm not sure how to fix.
From this:
some_long_function_name("test")
You get this just by pressing Enter in the right places:
some_long_function_name(
"test"
)
From this:
some_long_function_name({"logger": {"info": logger.info}})
You can get this from just Enter as well:
some_long_function_name(
{
"logger": {
"info": logger.info
}
}
)
However, from this:
some_long_function_name({
"WSGIErrorsWrapper": WSGIErrorsWrapper})
Pressing Enter before the }) gives you this:
some_long_function_name({
"WSGIErrorsWrapper": WSGIErrorsWrapper
})
Which I was hoping would be this:
some_long_function_name({
"WSGIErrorsWrapper": WSGIErrorsWrapper
})
And pressing Enter before the ) mysteriously puts it right under the "e" in Wrapper, even if you've already pressed Enter before the }.
some_long_function_name({
"WSGIErrorsWrapper": WSGIErrorsWrapper
}
)
Unfortunately, the complex hanging indent case mentioned in the comments inside nextIndentationLevel() no longer works as intended.
x = [
0, 1, 2, [3, 4, 5,
6, 7, 8],
]
Becomes this after pressing Enter between 8 and ] :
x = [
0, 1, 2, [3, 4, 5,
6, 7, 8
],
]
When it's supposed to be this:
x = [
0, 1, 2, [3, 4, 5,
6, 7, 8
],
]
I'm not sure how to accomplish my goal without breaking this. The code path for my two successes and this failure are the same (the first if block at the end of nextIndentationLevel()).
Checklist
- [X] Relevant issues have been referenced
- [ ] CHANGELOG.md has been updated (bullet points added to the Unreleased section)
- [ ] Tests have been added, or are not relevant
I had to use optional arguments to move dedentIfHanging around within the code without breaking the tests. I have no prior experience with TypeScript, so I was pretty baffled about what to do to update them. I'll try to get that figured out next week.
I'm also not 100% sure my description for the new setting is quite right.
Thanks @coredumperror! I have a busy week this week, so I will try and review some time next week. If it's been a while and I haven't responded, feel free to remind me.
It also sounds like you were able to set up a dev environment, so hopefully that means you can generate the VSIX file, which you can install manually to get the behavior you desire sooner. (I know the pain of using an editor that doesn't behave exactly how I want!)
Yeah, I followed the guide from VS Code's docs for making a new extension, and then used what I learned from that to get Python Indent dev up and running. Had to install some node stuff to make the build work, but that wasn't too hard to figure out.
Thanks for the heads up about VSIX. I hadn't heard of that, but I assume you mean what they talk about here? https://code.visualstudio.com/api/working-with-extensions/publishing-extension Being able to install my updated version of the extension into my normal VS Code environment will definitely be nice!
Yes, specifically the part under the header https://code.visualstudio.com/api/working-with-extensions/publishing-extension#packaging-extensions
If you're able to run the 'vsce package' command that will create a file version of the extension that can be installed directly.
Did you ever get a chance to look at this PR? I was just reminded of it because I had to re-install VS Code this week.
Hey @coredumperror sorry for the super long delay. The changes look overall reasonable to me. I do have a few comments, though. Can you let me know if you have the bandwidth / will to look at them?
Yeah sure, I would love to get this feature fully fleshed out and merged. That said, I'm going on a trip in a few hours, so I won't really be able to do any programing until Monday.