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(
57
57
var chainedHints : Boolean = false
58
58
)
59
59
60
- data class KtFmtConfiguration (
60
+ data class KtfmtConfiguration (
61
61
var style : String = " google" ,
62
62
var indent : Int = 4 ,
63
63
var maxWidth : Int = 100 ,
@@ -67,7 +67,7 @@ data class KtFmtConfiguration(
67
67
68
68
data class FormattingConfiguration (
69
69
var formatter : String = " ktfmt" ,
70
- var ktFmt : KtFmtConfiguration = KtFmtConfiguration ()
70
+ var ktfmt : KtfmtConfiguration = KtfmtConfiguration ()
71
71
)
72
72
73
73
fun getStoragePath (params : InitializeParams ): Path ? {
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ class KotlinWorkspaceService(
110
110
formatting.formatter = it
111
111
}
112
112
get(" ktfmt" )?.asJsonObject?.apply {
113
- val ktfmt = formatting.ktFmt
113
+ val ktfmt = formatting.ktfmt
114
114
get(" style" )?.asString?.let { ktfmt.style = it }
115
115
get(" indent" )?.asInt?.let { ktfmt.indent = it }
116
116
get(" maxWidth" )?.asInt?.let { ktfmt.maxWidth = it }
Original file line number Diff line number Diff line change 1
1
package org.javacs.kt.formatting
2
2
3
- import org.javacs.kt.Configuration
4
- import org.javacs.kt.FormattingConfiguration
5
3
import org.eclipse.lsp4j.FormattingOptions as LspFromattingOptions
6
4
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
-
24
5
interface Formatter {
25
6
fun format (code : String , options : LspFromattingOptions ): String
26
7
}
27
8
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 1
1
package org.javacs.kt.formatting
2
2
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
5
5
import com.facebook.ktfmt.format.FormattingOptions as KtfmtOptions
6
6
import org.eclipse.lsp4j.FormattingOptions as LspFormattingOptions
7
7
8
- class KtFmtFormatter (private val config : KtFmtConfiguration ) : Formatter {
8
+ class KtfmtFormatter (private val config : KtfmtConfiguration ) : Formatter {
9
9
override fun format (
10
10
code : String ,
11
11
options : LspFormattingOptions ,
@@ -16,7 +16,7 @@ class KtFmtFormatter(private val config: KtFmtConfiguration) : Formatter {
16
16
" dropbox" -> KtfmtOptions .Style .DROPBOX
17
17
else -> KtfmtOptions .Style .GOOGLE
18
18
}
19
- return KtFmt .format(KtfmtOptions (
19
+ return Ktfmt .format(KtfmtOptions (
20
20
style = style,
21
21
maxWidth = config.maxWidth,
22
22
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