Skip to content

Commit 61b30da

Browse files
committed
refactor: clean up CCConfigService
1. Always persist the component version attribute 2. Remove outdated TODO
1 parent cd11bf7 commit 61b30da

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

src/main/kotlin/com/github/lppedd/cc/configuration/CCConfigService.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class CCConfigService : PersistentStateComponent<CCConfigService> {
3232
}
3333

3434
@Attribute
35-
private var version: Int = 2
35+
private var version: Int = 0
3636

3737
var completionType: CompletionType = CompletionType.POPUP
3838
var enableLanguageSupport: Boolean = true
@@ -50,42 +50,42 @@ internal class CCConfigService : PersistentStateComponent<CCConfigService> {
5050
keyAttributeName = "providerId",
5151
valueAttributeName = "order"
5252
)
53-
private var typeProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
53+
private var typeProvidersMap = ConcurrentHashMap<String, Int>()
5454

5555
@XMap(
5656
propertyElementName = "commitScopes",
5757
keyAttributeName = "providerId",
5858
valueAttributeName = "order"
5959
)
60-
private var scopeProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
60+
private var scopeProvidersMap = ConcurrentHashMap<String, Int>()
6161

6262
@XMap(
6363
propertyElementName = "commitSubjects",
6464
keyAttributeName = "providerId",
6565
valueAttributeName = "order"
6666
)
67-
private var subjectProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
67+
private var subjectProvidersMap = ConcurrentHashMap<String, Int>()
6868

6969
@XMap(
7070
propertyElementName = "commitBodies",
7171
keyAttributeName = "providerId",
7272
valueAttributeName = "order"
7373
)
74-
private var bodyProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
74+
private var bodyProvidersMap = ConcurrentHashMap<String, Int>()
7575

7676
@XMap(
7777
propertyElementName = "commitFooterTypes",
7878
keyAttributeName = "providerId",
7979
valueAttributeName = "order"
8080
)
81-
private var footerTypeProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
81+
private var footerTypeProvidersMap = ConcurrentHashMap<String, Int>()
8282

8383
@XMap(
8484
propertyElementName = "commitFooterValues",
8585
keyAttributeName = "providerId",
8686
valueAttributeName = "order"
8787
)
88-
private var footerValueProvidersMap: MutableMap<String, Int> = ConcurrentHashMap<String, Int>()
88+
private var footerValueProvidersMap = ConcurrentHashMap<String, Int>()
8989

9090
init {
9191
noStateLoaded()
@@ -152,22 +152,20 @@ internal class CCConfigService : PersistentStateComponent<CCConfigService> {
152152
footerValueProvidersMap.putIfAbsent(VcsCommitTokenProvider.ID, 2)
153153
}
154154

155+
// For reference, this method is called only when the service is requested the first time.
156+
// There is no eager loading (well, in newer IDEA versions "preload" exists, but it is
157+
// better not to rely on it), so the updates below are applied only if a user actually
158+
// uses completion or opens the settings panel.
159+
//
160+
// NOTE: use ConverterProvider in case settings must be migrated to an entirely different format.
155161
override fun initializeComponent() {
156-
// For reference this method is called only when the service
157-
// is requested the first time. There is no eager loading (well,
158-
// in newer IDEA versions "preload" exists but it's better to
159-
// not rely on it) so the updates below are applied only if a user
160-
// actually uses completion or opens the settings panel.
161-
// TODO: think about a better strategy to update settings as soon
162-
// as the IDE starts but without nagging/scaring the user with
163-
// the ConverterProvider's popup. And maybe without having to deal
164-
// with XML itself
165162
if (version < 1) {
166163
// 0.17.0
167164
version++
168165
}
169166

170167
if (version < 2) {
168+
// 0.21.0
171169
version++
172170
}
173171

@@ -217,7 +215,7 @@ internal class CCConfigService : PersistentStateComponent<CCConfigService> {
217215
HIDE_SELECTED
218216
}
219217

220-
class PresentableNameGetter : State.NameGetter() {
218+
private class PresentableNameGetter : State.NameGetter() {
221219
override fun get() = "Conventional Commit Configuration"
222220
}
223221
}

0 commit comments

Comments
 (0)