-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da6dc0f
commit 3aca373
Showing
6 changed files
with
36 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
server/src/main/kotlin/org/javacs/kt/formatting/Formatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,8 @@ | ||
package org.javacs.kt.formatting | ||
|
||
import org.javacs.kt.Configuration | ||
import org.javacs.kt.FormattingConfiguration | ||
import org.eclipse.lsp4j.FormattingOptions as LspFromattingOptions | ||
|
||
private const val DEFAULT_INDENT = 4 | ||
|
||
class FormattingService(private val config: FormattingConfiguration) { | ||
|
||
private val formatter: Formatter get() = when (config.formatter) { | ||
"ktfmt" -> KtFmtFormatter(config.ktFmt) | ||
"none" -> NopFormatter | ||
else -> KtFmtFormatter(config.ktFmt) | ||
} | ||
|
||
fun formatKotlinCode( | ||
code: String, | ||
options: LspFromattingOptions = LspFromattingOptions(DEFAULT_INDENT, true) | ||
): String = this.formatter.format(code, options) | ||
} | ||
|
||
|
||
interface Formatter { | ||
fun format(code: String, options: LspFromattingOptions): String | ||
} | ||
|
||
object NopFormatter : Formatter { | ||
override fun format(code: String, options: LspFromattingOptions): String = code | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
server/src/main/kotlin/org/javacs/kt/formatting/FormattingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.javacs.kt.formatting | ||
|
||
import org.javacs.kt.Configuration | ||
import org.javacs.kt.FormattingConfiguration | ||
import org.eclipse.lsp4j.FormattingOptions as LspFromattingOptions | ||
|
||
private const val DEFAULT_INDENT = 4 | ||
|
||
class FormattingService(private val config: FormattingConfiguration) { | ||
|
||
private val formatter: Formatter get() = when (config.formatter) { | ||
"ktfmt" -> KtfmtFormatter(config.ktfmt) | ||
"none" -> NopFormatter | ||
else -> KtfmtFormatter(config.ktfmt) | ||
} | ||
|
||
fun formatKotlinCode( | ||
code: String, | ||
options: LspFromattingOptions = LspFromattingOptions(DEFAULT_INDENT, true) | ||
): String = this.formatter.format(code, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
server/src/main/kotlin/org/javacs/kt/formatting/NopFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.javacs.kt.formatting | ||
|
||
import org.eclipse.lsp4j.FormattingOptions as LspFormattingOptions | ||
|
||
object NopFormatter : Formatter { | ||
override fun format(code: String, options: LspFormattingOptions): String = code | ||
} | ||
|