Skip to content

Commit d23aa0f

Browse files
committed
refactor(vcs): improve finding example commit messages
1 parent 4d2cb73 commit d23aa0f

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

goland/src/main/kotlin/cc/unitmesh/go/provider/testing/GoWriteTestService.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.goide.GoLanguage
1010
import com.goide.execution.testing.GoTestRunConfiguration
1111
import com.goide.psi.*
1212
import com.intellij.execution.configurations.RunProfile
13+
import com.intellij.openapi.application.ReadAction
1314
import com.intellij.openapi.application.runReadAction
1415
import com.intellij.openapi.project.Project
1516
import com.intellij.openapi.roots.TestSourcesFilter
@@ -40,20 +41,22 @@ class GoWriteTestService : WriteTestService() {
4041
importList.map { it.text }
4142
}
4243

43-
val currentObject = when (underTestElement) {
44-
is GoTypeDeclaration,
45-
is GoTypeSpec -> {
46-
GoStructContextBuilder().getClassContext(underTestElement, false)?.format()
44+
val currentObject = ReadAction.compute<String, Throwable> {
45+
return@compute when (underTestElement) {
46+
is GoTypeDeclaration,
47+
is GoTypeSpec -> {
48+
GoStructContextBuilder().getClassContext(underTestElement, false)?.format()
49+
}
50+
51+
is GoFunctionOrMethodDeclaration -> GoMethodContextBuilder().getMethodContext(
52+
underTestElement,
53+
false,
54+
false
55+
)
56+
?.format()
57+
58+
else -> null
4759
}
48-
49-
is GoFunctionOrMethodDeclaration -> GoMethodContextBuilder().getMethodContext(
50-
underTestElement,
51-
false,
52-
false
53-
)
54-
?.format()
55-
56-
else -> null
5760
}
5861

5962
return TestFileContext(

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
8787
}
8888
}
8989

90+
/**
91+
* Finds example commit messages based on the project's VCS log, takes the first three commits.
92+
* If the no user or user has not committed anything yet, the current branch name is used instead.
93+
*
94+
* @param project The project for which to find example commit messages.
95+
* @return A string containing example commit messages, or null if no example messages are found.
96+
*/
9097
private fun findExampleCommitMessages(project: Project): String? {
9198
val logProviders = VcsProjectLog.getLogProviders(project)
9299
val entry = logProviders.entries.firstOrNull() ?: return null
@@ -125,7 +132,8 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
125132
val commitIds = commits.map { it.id.asString() }
126133

127134
logProvider.readMetadata(root, commitIds) {
128-
builder.append(it.fullMessage).append("\n")
135+
val shortMsg = it.fullMessage.split("\n").firstOrNull() ?: it.fullMessage
136+
builder.append(shortMsg).append("\n")
129137
}
130138

131139
return builder.toString()

0 commit comments

Comments
 (0)