Skip to content

Commit 67e372b

Browse files
tKemeta-codesync[bot]
authored andcommitted
fix(idea_plugin): fix custom comma management strategy not being applied (#593)
Summary: The ktfmt settings controls were putting the `toString` of the `TrailingCommaManagementStrategy` instead of the `.name` which was expected by the formatting options creation code. Pull Request resolved: #593 Reviewed By: cortinico Differential Revision: D92171530 Pulled By: hick209 fbshipit-source-id: 6ddb28047df42bbf097427b16dc6222310606724
1 parent bcd9241 commit 67e372b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1414

1515
### Changed
1616

17+
### Fixed
18+
- Idea Plugin not applying custom trailing commas management strategy (https://github.com/facebook/ktfmt/pull/593)
19+
1720

1821
## [0.61]
1922

ktfmt_idea_plugin/src/main/kotlin/com/facebook/ktfmt/intellij/KtfmtConfigurable.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ class KtfmtConfigurable(project: Project) :
102102
.component
103103
}
104104

105-
lateinit var trailingCommaManagementStrategy: JComboBox<String>
105+
lateinit var trailingCommaManagementStrategy: JComboBox<TrailingCommaManagementStrategy>
106106
row("Trailing commas management") {
107107
trailingCommaManagementStrategy =
108-
comboBox(TrailingCommaManagementStrategy.values().map { it.toString() })
108+
comboBox(TrailingCommaManagementStrategy.entries)
109109
.bindItem(
110110
getter = { settings.customTrailingCommaManagementStrategy },
111-
setter = { settings.customTrailingCommaManagementStrategy = it.orEmpty() },
111+
setter = {
112+
settings.customTrailingCommaManagementStrategy =
113+
it ?: TrailingCommaManagementStrategy.NONE
114+
},
112115
)
113116
.component
114117
}
@@ -174,13 +177,13 @@ private fun FormattingOptions.updateFields(
174177
maxLineLength: JTextField,
175178
blockIndent: JTextField,
176179
continuationIndent: JTextField,
177-
trailingCommaManagementStrategy: JComboBox<String>,
180+
trailingCommaManagementStrategy: JComboBox<TrailingCommaManagementStrategy>,
178181
removeUnusedImports: JCheckBox,
179182
) {
180183
maxLineLength.text = maxWidth.toString()
181184
blockIndent.text = this.blockIndent.toString()
182185
continuationIndent.text = this.continuationIndent.toString()
183-
trailingCommaManagementStrategy.selectedItem = this.trailingCommaManagementStrategy.toString()
186+
trailingCommaManagementStrategy.selectedItem = this.trailingCommaManagementStrategy
184187
removeUnusedImports.isSelected = this.removeUnusedImports
185188
}
186189

ktfmt_idea_plugin/src/main/kotlin/com/facebook/ktfmt/intellij/KtfmtSettings.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ internal class KtfmtSettings(private val project: Project) :
7878
state.customContinuationIndent = continuationIndent.coerceAtLeast(1)
7979
}
8080

81-
var customTrailingCommaManagementStrategy: String
82-
get() = state.customTrailingCommaManagementStrategy
81+
var customTrailingCommaManagementStrategy: TrailingCommaManagementStrategy
82+
get() = state.customTrailingCommaManagementStrategy.toTrailingCommaManagementStrategy()
8383
set(value) {
84-
state.customTrailingCommaManagementStrategy = value
84+
state.customTrailingCommaManagementStrategy = value.name
8585
}
8686

8787
var customRemoveUnusedImports: Boolean
@@ -168,8 +168,8 @@ internal class KtfmtSettings(private val project: Project) :
168168
private fun String.toTrailingCommaManagementStrategy(
169169
defaultValue: TrailingCommaManagementStrategy = TrailingCommaManagementStrategy.NONE,
170170
): TrailingCommaManagementStrategy =
171-
runCatching { TrailingCommaManagementStrategy.valueOf(this.uppercase()) }
172-
.getOrDefault(defaultValue)
171+
TrailingCommaManagementStrategy.entries.find { it.name == this || it.toString() == this }
172+
?: defaultValue
173173

174174
companion object {
175175
@JvmStatic

0 commit comments

Comments
 (0)