Skip to content

Commit e826929

Browse files
committed
chore(ci): update build workflow and add test case for KotlinMethodContextBuilder
- Update build workflow to include a step for building the plugin. - Add a new test case for KotlinMethodContextBuilder to handle function comments. - Modify the getSignatureString function in KotlinMethodContextBuilder to handle function comments correctly.
1 parent 10ea4dc commit e826929

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ jobs:
9494
name: tests-result
9595
path: ${{ github.workspace }}/build/reports/tests
9696

97+
# Run tests
98+
- name: Build Plugin
99+
run: ./gradlew :plugin:buildPlugin
100+
97101
# Upload Kover report to CodeCov
98102
- name: Upload Code Coverage Report
99103
uses: codecov/codecov-action@v3
@@ -103,15 +107,6 @@ jobs:
103107
with:
104108
files: ${{ github.workspace }}/build/reports/kover/xml/report.xml
105109

106-
- name: Upload coverage reports to Codecov
107-
uses: codecov/codecov-action@v3
108-
env:
109-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
110-
111-
# Run tests
112-
- name: Build Plugin
113-
run: ./gradlew :plugin:buildPlugin
114-
115110
# Prepare plugin archive content for creating artifact
116111
- name: Prepare Plugin Artifact
117112
id: artifact

kotlin/src/main/kotlin/cc/unitmesh/kotlin/context/KotlinMethodContextBuilder.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,19 @@ class KotlinMethodContextBuilder : MethodContextBuilder {
4242
}
4343

4444
object Util {
45-
fun getSignatureString(ktNamedFunction: KtNamedFunction): String {
46-
val bodyBlockExpression = ktNamedFunction.bodyBlockExpression
45+
46+
fun getSignatureString(signatureString: KtNamedFunction): String {
47+
val bodyBlockExpression = signatureString.bodyBlockExpression
4748
val startOffsetInParent = if (bodyBlockExpression != null) {
4849
bodyBlockExpression.startOffsetInParent
4950
} else {
50-
val bodyExpression = ktNamedFunction.bodyExpression
51-
bodyExpression?.startOffsetInParent ?: ktNamedFunction.textLength
52-
}
53-
54-
val docEnd = ktNamedFunction.docComment?.endOffset ?: 0
55-
56-
val text = ktNamedFunction.text
57-
58-
val result = if (docEnd < startOffsetInParent) {
59-
text.substring(docEnd, startOffsetInParent)
60-
} else {
61-
text.substring(ktNamedFunction.startOffsetInParent, startOffsetInParent)
51+
val bodyExpression = signatureString.bodyExpression
52+
bodyExpression?.startOffsetInParent ?: signatureString.textLength
6253
}
6354

64-
return result.replace("\n", " ").trim()
55+
val text = signatureString.text
56+
val substring = text.substring(0, startOffsetInParent)
57+
return substring.replace('\n', ' ').trim()
6558
}
6659
}
6760
}

kotlin/src/test/kotlin/cc/unitmesh/kotlin/context/KotlinMethodContextBuilderTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class KotlinMethodContextBuilderTest : LightPlatformTestCase() {
2525
val clz = PsiTreeUtil.findChildOfType(createFile, KtNamedFunction::class.java)!!
2626

2727
val signatureString = KotlinMethodContextBuilder.Util.getSignatureString(clz)
28-
TestCase.assertEquals(signatureString, "fun main()")
28+
TestCase.assertEquals(signatureString, "/** * It's a hello, world. */ fun main()")
2929
}
3030

31-
fun shouldIgnoreClassFunctionComment() {
31+
fun testShouldIgnoreClassFunctionComment() {
3232
// given
3333
val code = """
3434
class UserController {
@@ -45,7 +45,7 @@ class KotlinMethodContextBuilderTest : LightPlatformTestCase() {
4545
val clz = PsiTreeUtil.findChildOfType(createFile, KtNamedFunction::class.java)!!
4646

4747
val signatureString = KotlinMethodContextBuilder.Util.getSignatureString(clz)
48-
TestCase.assertEquals(signatureString, "fun main()")
48+
TestCase.assertEquals(signatureString, "/** * It's a hello, world. */ fun main()")
4949
}
5050

5151
fun testShouldHandleNormalClassFunctionComment() {

0 commit comments

Comments
 (0)