-
Notifications
You must be signed in to change notification settings - Fork 630
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
Spaces are incorrectly added before indented parameters while formatting a fragment #1738
Comments
I believe SwiftFormat expects all input to be syntactically-valid Swift code, and the behavior of rules is more of less undefined when passing in invalid Swift code. Since this input code isn't valid Swift code, to me it isn't unexpected that the output would be unusual: foo: bar,
foo1: bar2,
foo2: bar3 Do you have a repro case for this where the indentation is incorrect when passing in text that is valid Swift code? |
@calda This fragment is part of valid Swift Code, and the expectation is that since This scenario can occur in editors like VSCode which have a In this case, the following parameters are part of valid Swift Code. For example, assume that a user made changes to the parameters of an existing function call in a document. In that case, a fragment containing the parameters will need to be formatted. Fragment:
Context:
|
@calda yeah @vinocher-bc is correct. I think the simplest fix here is just to disable the wrap rule when running in --fragment mode (there are probably many other rules that also should be disabled but currently aren't) |
@vinocher-bc that said, I think the vs-code extension should not be using --fragment. It was originally introduced for this purpose as part of the SwiftFormat Xcode extension, but I replaced it with --linerange instead, which is much more reliable because it takes the entire file into account for parsing but limits any changes to just the selected region. |
@nicklockwood I'm seeing some weirdness with
|
@calda a similar issue occurs with method chaining. The indentation is removed. Expected: the indentation should not be removed.
It is formatted correctly when the context is provided:
|
@vinocher-bc --linerange assumes the entire file is passed as input, but only applies changes to the specified range. If you are passing only a fragment of the file then --fragment is the correct argument to use |
@vinocher-bc --fragment support for indent is fixed in 0.54.1 |
Spaces are incorrectly added before indented parameters while formatting the parameters of a function call in a fragment. This was reproduced on Windows.
Repro:
(Use
Ctrl+Z, Enter
to signalEOF
in stdin):Note the spaces added before
foo1
&foo2
The formatting of the indentation is correct if the entire function call is provided:
The text was updated successfully, but these errors were encountered: