vknabel / vscode-swiftformat

SwiftFormat for VS Code
https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swiftformat
MIT License
43 stars 8 forks source link

Better Format Selection #27

Closed MahdiBM closed 1 year ago

MahdiBM commented 1 year ago

When you do "Format Selection" in VSCode, it'll format the selection out of context of the file, which can make it look weird because it won't properly take care of indentation etc...

It should instead take the whole file context into account, but only modify the selected lines.

Steps to reproduce

1:

Screenshot 2023-08-11 at 2 32 17 AM

2:

Screenshot 2023-08-11 at 2 32 24 AM

3:

Screenshot 2023-08-11 at 2 32 34 AM

4:

Screenshot 2023-08-11 at 2 32 48 AM

As you can see, in 4 indentation of the function is broken compared to the parent struct. There is also a weird extra space below the function after the indentation, not sure why.

Usage?

When working on team projects you might want to keep your own code-style clean, but don't force it on others. Without a feature like this you always need to format the whole file instead of just the few lines you wrote.

vknabel commented 1 year ago

Thanks for opening this issue! I totally get the use case and I definitely will have a look on this.

MahdiBM commented 1 year ago

I just noticed this issue in swift-format repo: https://github.com/apple/swift-format/issues/297. I thought it doesn't hurt to mention that they basically want to natively support what this issue requests.

MahdiBM commented 1 year ago

I just notice this is the repository for Nick Lokwood's swift-format, but actually that makes the issue even better because i've now moved to the Nick Lockwood's swiftformat because Apple's swift-format doesn't seem actually useable in practically formatting stuff properly.

vknabel commented 1 year ago

Thanks for the upcoming comments! If I get this right, there is no issue in this repo and for the apple formatter extension, this is an upstream issue.