Skip to content

Commit 8875c93

Browse files
committed
refactor: introduce a FOOTER_SEPARATOR lexer token type
1 parent 82f81ae commit 8875c93

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

src/main/kotlin/com/github/lppedd/cc/editor/CommitTabAction.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ internal class CommitTabAction : TabAction() {
5656
) {
5757
editor.putUserData(moveCaretKey, 1)
5858
return true
59-
} else if (elementAtCaret is ConventionalCommitSeparatorPsiElement) {
59+
} else if (
60+
elementAtCaret is ConventionalCommitSeparatorPsiElement ||
61+
elementAtCaret is ConventionalCommitFooterSeparatorPsiElement
62+
) {
6063
// Let's find where the subject/footer value text begins,
6164
// or just place the cursor at the right place if it doesn't exist yet
6265
val nextSibling = elementAtCaret.nextSibling

src/main/kotlin/com/github/lppedd/cc/language/lexer/ConventionalCommitTokenType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ConventionalCommitTokenType(debugName: String) : IElementType(debug
1818
@JvmField public val BODY: IElementType = ConventionalCommitTokenType("BODY")
1919
@JvmField public val FOOTER_TYPE: IElementType = ConventionalCommitTokenType("FOOTER_TYPE")
2020
@JvmField public val FOOTER_TYPE_BREAKING_CHANGE: IElementType = ConventionalCommitTokenType("FOOTER_TYPE_BREAKING_CHANGE")
21+
@JvmField public val FOOTER_SEPARATOR: IElementType = ConventionalCommitTokenType("FOOTER_SEPARATOR")
2122
@JvmField public val FOOTER_VALUE: IElementType = ConventionalCommitTokenType("FOOTER_VALUE")
2223
}
2324
}

src/main/kotlin/com/github/lppedd/cc/language/lexer/conventionalCommit.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ FooterType = [^:\s]+ | BREAKING\ CHANGE
177177

178178
: {
179179
yybegin(FOOTER_VALUE);
180-
return ConventionalCommitTokenType.SEPARATOR;
180+
return ConventionalCommitTokenType.FOOTER_SEPARATOR;
181181
}
182182
}
183183

src/main/kotlin/com/github/lppedd/cc/language/parser/ConventionalCommitASTFactory.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.lppedd.cc.language.parser
22

33
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.BODY
44
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.BREAKING_CHANGE
5+
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.FOOTER_SEPARATOR
56
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.FOOTER_TYPE
67
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.FOOTER_TYPE_BREAKING_CHANGE
78
import com.github.lppedd.cc.language.lexer.ConventionalCommitTokenType.Companion.FOOTER_VALUE
@@ -34,6 +35,7 @@ internal class ConventionalCommitASTFactory : ASTFactory() {
3435
tokensMap[BODY] = ::ConventionalCommitBodyPsiElement
3536
tokensMap[FOOTER_TYPE] = ::ConventionalCommitFooterTypePsiElement
3637
tokensMap[FOOTER_TYPE_BREAKING_CHANGE] = ::ConventionalCommitFooterTypePsiElement
38+
tokensMap[FOOTER_SEPARATOR] = ::ConventionalCommitFooterSeparatorPsiElement
3739
tokensMap[FOOTER_VALUE] = ::ConventionalCommitFooterValuePsiElement
3840
}
3941

src/main/kotlin/com/github/lppedd/cc/language/parser/ConventionalCommitPsiParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class ConventionalCommitPsiParser : PsiParser {
4848
val marker = builder.mark()
4949
var token = builder.advanceAndGet()
5050

51-
if (token == ConventionalCommitTokenType.SEPARATOR) {
51+
if (token == ConventionalCommitTokenType.FOOTER_SEPARATOR) {
5252
token = builder.advanceAndGet()
5353
}
5454

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.lppedd.cc.language.psi
2+
3+
import com.intellij.psi.impl.source.tree.LeafPsiElement
4+
import com.intellij.psi.tree.IElementType
5+
6+
/**
7+
* @author Edoardo Luppi
8+
*/
9+
public class ConventionalCommitFooterSeparatorPsiElement(
10+
type: IElementType,
11+
text: CharSequence,
12+
) : LeafPsiElement(type, text) {
13+
override fun toString(): String =
14+
"ConventionalCommitFooterSeparatorPsiElement"
15+
}

0 commit comments

Comments
 (0)