File tree Expand file tree Collapse file tree 6 files changed +36
-30
lines changed
server/src/main/kotlin/org/javacs/kt Expand file tree Collapse file tree 6 files changed +36
-30
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ data class InlayHintsConfiguration(
5757 var chainedHints : Boolean = false
5858)
5959
60- data class KtFmtConfiguration (
60+ data class KtfmtConfiguration (
6161 var style : String = " google" ,
6262 var indent : Int = 4 ,
6363 var maxWidth : Int = 100 ,
@@ -67,7 +67,7 @@ data class KtFmtConfiguration(
6767
6868data class FormattingConfiguration (
6969 var formatter : String = " ktfmt" ,
70- var ktFmt : KtFmtConfiguration = KtFmtConfiguration ()
70+ var ktfmt : KtfmtConfiguration = KtfmtConfiguration ()
7171)
7272
7373fun getStoragePath (params : InitializeParams ): Path ? {
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ class KotlinWorkspaceService(
110110 formatting.formatter = it
111111 }
112112 get(" ktfmt" )?.asJsonObject?.apply {
113- val ktfmt = formatting.ktFmt
113+ val ktfmt = formatting.ktfmt
114114 get(" style" )?.asString?.let { ktfmt.style = it }
115115 get(" indent" )?.asInt?.let { ktfmt.indent = it }
116116 get(" maxWidth" )?.asInt?.let { ktfmt.maxWidth = it }
Original file line number Diff line number Diff line change 11package org.javacs.kt.formatting
22
3- import org.javacs.kt.Configuration
4- import org.javacs.kt.FormattingConfiguration
53import org.eclipse.lsp4j.FormattingOptions as LspFromattingOptions
64
7- private const val DEFAULT_INDENT = 4
8-
9- class FormattingService (private val config : FormattingConfiguration ) {
10-
11- private val formatter: Formatter get() = when (config.formatter) {
12- " ktfmt" -> KtFmtFormatter (config.ktFmt)
13- " none" -> NopFormatter
14- else -> KtFmtFormatter (config.ktFmt)
15- }
16-
17- fun formatKotlinCode (
18- code : String ,
19- options : LspFromattingOptions = LspFromattingOptions (DEFAULT_INDENT , true)
20- ): String = this .formatter.format(code, options)
21- }
22-
23-
245interface Formatter {
256 fun format (code : String , options : LspFromattingOptions ): String
267}
278
28- object NopFormatter : Formatter {
29- override fun format (code : String , options : LspFromattingOptions ): String = code
30- }
31-
Original file line number Diff line number Diff line change 1+ package org.javacs.kt.formatting
2+
3+ import org.javacs.kt.Configuration
4+ import org.javacs.kt.FormattingConfiguration
5+ import org.eclipse.lsp4j.FormattingOptions as LspFromattingOptions
6+
7+ private const val DEFAULT_INDENT = 4
8+
9+ class FormattingService (private val config : FormattingConfiguration ) {
10+
11+ private val formatter: Formatter get() = when (config.formatter) {
12+ " ktfmt" -> KtfmtFormatter (config.ktfmt)
13+ " none" -> NopFormatter
14+ else -> KtfmtFormatter (config.ktfmt)
15+ }
16+
17+ fun formatKotlinCode (
18+ code : String ,
19+ options : LspFromattingOptions = LspFromattingOptions (DEFAULT_INDENT , true)
20+ ): String = this .formatter.format(code, options)
21+ }
Original file line number Diff line number Diff line change 11package org.javacs.kt.formatting
22
3- import org.javacs.kt.KtFmtConfiguration
4- import com.facebook.ktfmt.format.Formatter as KtFmt
3+ import org.javacs.kt.KtfmtConfiguration
4+ import com.facebook.ktfmt.format.Formatter as Ktfmt
55import com.facebook.ktfmt.format.FormattingOptions as KtfmtOptions
66import org.eclipse.lsp4j.FormattingOptions as LspFormattingOptions
77
8- class KtFmtFormatter (private val config : KtFmtConfiguration ) : Formatter {
8+ class KtfmtFormatter (private val config : KtfmtConfiguration ) : Formatter {
99 override fun format (
1010 code : String ,
1111 options : LspFormattingOptions ,
@@ -16,7 +16,7 @@ class KtFmtFormatter(private val config: KtFmtConfiguration) : Formatter {
1616 " dropbox" -> KtfmtOptions .Style .DROPBOX
1717 else -> KtfmtOptions .Style .GOOGLE
1818 }
19- return KtFmt .format(KtfmtOptions (
19+ return Ktfmt .format(KtfmtOptions (
2020 style = style,
2121 maxWidth = config.maxWidth,
2222 blockIndent = options.tabSize.takeUnless { it == 0 } ? : config.indent,
Original file line number Diff line number Diff line change 1+ package org.javacs.kt.formatting
2+
3+ import org.eclipse.lsp4j.FormattingOptions as LspFormattingOptions
4+
5+ object NopFormatter : Formatter {
6+ override fun format (code : String , options : LspFormattingOptions ): String = code
7+ }
8+
You can’t perform that action at this time.
0 commit comments