Skip to content
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

Add formatter options to format multiple parameters with new lines #2483

Open
slezhnin opened this issue May 30, 2022 · 1 comment
Open

Add formatter options to format multiple parameters with new lines #2483

slezhnin opened this issue May 30, 2022 · 1 comment

Comments

@slezhnin
Copy link

I'd like my code to be formatted with new lines for annotation, constructor or method call or declaration with multiple parameters.

For instance:

@Parameter(
    in = ParameterIn.PATH,
    name = "resourceName",
    description = "Resource Name",
    required = true,
    example = "1",
    schema = @Schema(type = SchemaType.STRING, minLength = 1)
)

Current formatter makes a one-liner like this:

@Parameter(in = ParameterIn.PATH, name = "resourceName", description = "Resource Name", required = true, example = "1", schema = @Schema(type = SchemaType.STRING, minLength = 1))

So the formatter should insert new line after the opening brace and comma and before the closing brace.

Environment
  • Operating System: MacOs Monterey 12.3
  • JDK version: openjdk version "11.0.15" 2022-04-19
  • Visual Studio Code version: 1.67.2
  • Java extension version: v1.6.0
Steps To Reproduce
  1. Add annotation with multiple parameters
  2. Format the code
  3. In my current formatter version it should compact it to one line
Current Result
@Parameter(in = ParameterIn.PATH, name = "resourceName", description = "Resource Name", required = true, example = "1", schema = @Schema(type = SchemaType.STRING, minLength = 1))
Expected Result
@Parameter(
    in = ParameterIn.PATH,
    name = "resourceName",
    description = "Resource Name",
    required = true,
    example = "1",
    schema = @Schema(type = SchemaType.STRING, minLength = 1)
)
@slezhnin slezhnin changed the title Add formatter options to format parameters with new lines Add formatter options to format multiple parameters with new lines May 30, 2022
@rgrunber
Copy link
Member

rgrunber commented May 31, 2022

You could try what's referenced in eclipse-jdtls/eclipse.jdt.ls#1717 (comment) . There are many different formatting options supported.

I found that I needed to set it to org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=49 (instead of 48) to force the setting. Otherwise it's optional.

You could also create your own formatter as described in https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings . The option would be <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="49"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants