Skip to content

First draft of new closeHangingIndent option #128

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coredumperror
Copy link

PR for #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

  • 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.

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 } doesn't put the }) at the start of the line. And pressing Enter before the ) mysteriously puts it right under the "e" in Wrapper, even if you've already pressed Enter before the }. Not sure what to do about that.

Also, the complex hanging indent case mentioned in the comments in 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
          ],
]
```

I imagine this is undesired, but I don't know 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()).
@kbrose
Copy link
Owner

kbrose commented May 4, 2025

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!)

@coredumperror
Copy link
Author

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!

@kbrose
Copy link
Owner

kbrose commented May 4, 2025

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.

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

Successfully merging this pull request may close these issues.

2 participants