11package com.github.lppedd.cc.commitlint
22
33import com.github.lppedd.cc.api.*
4- import com.github.lppedd.cc.api.CommitTokenElement.CommitTokenRendering
54import com.intellij.openapi.project.Project
65import com.intellij.openapi.project.guessProjectDir
76import org.json.JSONArray
@@ -10,27 +9,33 @@ import org.json.JSONTokener
109import java.nio.charset.StandardCharsets.UTF_8
1110import java.nio.file.Files
1211import java.nio.file.Paths
12+ import javax.swing.Icon
1313
1414/* *
1515 * @author Edoardo Luppi
1616 */
17- private class CommitlintTokensProvider (private val project : Project ) :
17+ @Suppress(" UnstableApiUsage" )
18+ internal class CommitlintTokensProvider (private val project : Project ) :
1819 CommitTypeProvider ,
1920 CommitScopeProvider {
21+ companion object {
22+ const val ID : String = " 37415b03-9388-4c55-b949-8c4526f6934d"
23+ }
24+
2025 override fun getId (): String =
21- PROVIDER_ID
26+ ID
2227
2328 override fun getPresentation (): ProviderPresentation =
24- PROVIDER_PRESENTATION
29+ CommitlintProviderPresentation
2530
26- override fun getCommitTypes (prefix : String? ): Collection <CommitType > =
31+ override fun getCommitTypes (prefix : String ): Collection <CommitType > =
2732 readRuleValuesFromConfigFile(" type-enum" )
28- .map(::CommitlintCommitType )
33+ .map(::CommitlintCommitToken )
2934 .toList()
3035
31- override fun getCommitScopes (commitType : String? ): Collection <CommitScope > =
36+ override fun getCommitScopes (commitType : String ): Collection <CommitScope > =
3237 readRuleValuesFromConfigFile(" scope-enum" )
33- .map(::CommitlintCommitScope )
38+ .map(::CommitlintCommitToken )
3439 .toList()
3540
3641 private fun readRuleValuesFromConfigFile (ruleName : String ): Sequence <String > {
@@ -58,7 +63,7 @@ private class CommitlintTokensProvider(private val project: Project) :
5863
5964 private fun getConfigFilePath (): String? =
6065 project.guessProjectDir()
61- ?.findChild(CONFIG_FILE_NAME )
66+ ?.findChild(CommitlintConstants . ConfigFileName )
6267 ?.path
6368
6469 private inline fun <T > noException (block : () -> T ): T ? =
@@ -67,14 +72,31 @@ private class CommitlintTokensProvider(private val project: Project) :
6772 } catch (ignored: Exception ) {
6873 null
6974 }
70- }
7175
72- private val TOKEN_RENDERING = CommitTokenRendering (icon = ICON_COMMITLINT )
76+ private object CommitlintProviderPresentation : ProviderPresentation {
77+ override fun getName (): String =
78+ " Commitlint"
7379
74- private class CommitlintCommitType ( text : String ) : CommitType(text, " " ) {
75- override fun getRendering () = TOKEN_RENDERING
76- }
80+ override fun getIcon (): Icon =
81+ CommitlintIcons . Logo
82+ }
7783
78- private class CommitlintCommitScope (text : String ) : CommitScope(text, " " ) {
79- override fun getRendering () = TOKEN_RENDERING
84+ private object CommitlintTokenPresentation : TokenPresentation {
85+ override fun getIcon (): Icon =
86+ CommitlintIcons .Logo
87+ }
88+
89+ private class CommitlintCommitToken (private val text : String ) : CommitType, CommitScope {
90+ override fun getText (): String =
91+ text
92+
93+ override fun getValue (): String =
94+ getText()
95+
96+ override fun getDescription (): String =
97+ " "
98+
99+ override fun getPresentation (): TokenPresentation =
100+ CommitlintTokenPresentation
101+ }
80102}
0 commit comments