fwcd / fwcd/kotlin-language-server

[Proposal] Refactor formatting logic to use external command(s)

Open
#329 2 comments 0 reactions 0 assignees View on GitHub
formatting
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

After reading several issues about code formatting support (https://github.com/fwcd/kotlin-language-server/issues/29, https://github.com/fwcd/kotlin-language-server/issues/303, https://github.com/fwcd/kotlin-language-server/issues/304), I think it might be feasible to just make a configurable subprocess command and launch it when code formatting is triggered, in the following steps (to be completed):

1. Fix the default formatting style (of the plugin and of the codebase): https://github.com/fwcd/kotlin-language-server/pull/330.
2. Add option to customize formatting: TODO.

This proposal is made with the following considerations in mind:

- There are various ways of formatting a Kotlin codebase. Apart from the [`ktlint`](https://github.com/pinterest/ktlint) vs. [`ktfmt`](https://github.com/facebookincubator/ktfmt) debate, each has different installation options (for just Gradle for example, there are existing Gradle plugins like [`ktlint-gradle`](https://github.com/JLLeitschuh/ktlint-gradle) and [`ktfmt-gradle`](https://github.com/cortinico/ktfmt-gradle), and there's also [`spotless`](https://github.com/diffplug/spotless)).

- This has been done in similar projects. For example, [`rust-analyzer`](https://github.com/rust-analyzer/rust-analyzer/blob/0808ade4e43157f96ddaca8fa39f436038c3ede0/crates/rust-analyzer/src/handlers.rs#L1697) simply launches [`rustfmt`](https://github.com/rust-lang/rustfmt) to handle this.

- However, given the fact that there is no `rustfmt` equivalent in the Kotlin world, and that some might want to use this plugin without an explicit per-project formatter config, it's acceptable to keep the embed `ktfmt` as the default formatter.

What do you think of this idea? :)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the linked formatting issues and pull request 330 to understand the existing formatting behavior and default style. No implementation files or tests are named, so the first task is to locate the formatting-trigger entry point and determine how a configurable subprocess would fit. Done means the proposal is resolved with a defined configuration option and documented behavior for the embedded default formatter.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.