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

[Feature request] Formatter selection / formatting options #303

Open
dr-eme opened this issue Aug 6, 2021 · 4 comments
Open

[Feature request] Formatter selection / formatting options #303

dr-eme opened this issue Aug 6, 2021 · 4 comments
Labels
enhancement New feature or request formatting Related to source code formatting

Comments

@dr-eme
Copy link

dr-eme commented Aug 6, 2021

Motivation

We use ktfmt (aka google java style) formatting, and it would be great if to have different formatters options, or at least a way to configure the default one, for instance the default indentation.

Description

Be able to select formatters (e.g. see the ones supported by spotless)

Alternatives considered

Configure formatting options

@dr-eme dr-eme changed the title [Feature request] [Feature request] Formatter selection / formatting options Aug 6, 2021
@fwcd fwcd transferred this issue from fwcd/vscode-kotlin Aug 6, 2021
@fwcd fwcd added enhancement New feature or request formatting Related to source code formatting labels Aug 6, 2021
@dewijones92
Copy link

@dr-eme is https://github.com/pinterest/ktlint what you are after?

@stenzengel
Copy link

ktlint allows to change some formatting options via the file .editorconfig (https://github.com/pinterest/ktlint#editorconfig). I was not able to make this work. What did actually work, was changing the VS Code setting editor.tabSize. Unfortunately I was not able to configure other formatiing options (e.g. max_line_length) of ktlint. I had a quick look at the source code (https://github.com/fwcd/kotlin-language-server/blob/main/server/src/main/kotlin/org/javacs/kt/formatting/Formatter.kt). This seems currently not to be possible or did someone manage that?

@rami3l
Copy link

rami3l commented Feb 19, 2022

@stenzengel
As you might have noticed, in #238 the ktlint dependency has been swapped with ktfmt, and there is a default formatting configuration. This might be a choice of personal taste, but I wonder if it should be the default config since this will conflict with both ktlint and ktfmt when options.tabSize == 4.

See:

): String = format(KtfmtOptions(
style = KtfmtOptions.Style.GOOGLE,
blockIndent = options.tabSize,
continuationIndent = 2 * options.tabSize
), code)

... and, in the original initializer in ktfmt:

val blockIndent: Int = 2,
val continuationIndent: Int = 4,

PS: If this plugin wants to be opinionated in formatting configurations, its best shot might be to stick with the official style guide, which has been added in ktfmt as a preset:

  /** A format that attempts to reflect https://kotlinlang.org/docs/coding-conventions.html. */
  @JvmField
  val KOTLINLANG_FORMAT = FormattingOptions(style = GOOGLE, blockIndent = 4, continuationIndent = 4)

... and if we follow this path, there is currently a workaround to configure the formatter in a per-project basis if you're using VSCode: Custom Local Formatters.

@tats-u
Copy link

tats-u commented Aug 27, 2023

It's ideal if we can choose ktlint or ktfmt in settings.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request formatting Related to source code formatting
Projects
None yet
Development

No branches or pull requests

6 participants