Skip to content

Commit fb588e3

Browse files
committed
fix(devins-cpp): move test config for Intellij IDEA 223 only, which is C++ test configurations and test discovery #100
This commit introduces a new class, `CppAutoTestService`, which provides support for C++ test configurations and test discovery within the IntelliJ platform. The `CppAutoTestService` class is responsible for creating and managing test files for C++ source files, as well as identifying relevant test classes and methods. The commit also includes a rename of the `CppAutoTestService.kt` file to `CppAutoTestService.kt` within the `233` directory, reflecting a new version or configuration specific to C++ development. Additionally, the `build.gradle.kts` file has been modified to include the `com.intellij.nativeDebug` plugin for C++ debugging support when the platform version is set to 233. These changes are part of the ongoing effort to enhance the C++ development experience within the IntelliJ platform, specifically for version 233.
1 parent 9dd5c48 commit fb588e3

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ val clionPlugins = listOf(
7070
prop("rustPlugin"),
7171
"org.toml.lang"
7272
)
73-
val cppPlugins = listOf(
73+
var cppPlugins: List<String> = listOf(
7474
"com.intellij.cidr.lang",
7575
"com.intellij.clion",
7676
"com.intellij.cidr.base",
77-
"com.intellij.nativeDebug",
7877
"org.jetbrains.plugins.clion.test.google",
7978
"org.jetbrains.plugins.clion.test.catch"
8079
)
80+
8181
val rustPlugins = listOf(
8282
prop("rustPlugin"),
8383
"org.toml.lang"
@@ -517,6 +517,10 @@ project(":rust") {
517517
}
518518

519519
project(":cpp") {
520+
if (platformVersion == 233) {
521+
cppPlugins += "com.intellij.nativeDebug"
522+
}
523+
520524
intellij {
521525
version.set(clionVersion)
522526
plugins.set(cppPlugins)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package cc.unitmesh.cpp.provider.testing
2+
3+
import cc.unitmesh.cpp.util.CppContextPrettify
4+
import cc.unitmesh.devti.context.ClassContext
5+
import cc.unitmesh.devti.provider.AutoTestService
6+
import cc.unitmesh.devti.provider.context.TestFileContext
7+
import com.intellij.execution.configurations.RunConfiguration
8+
import com.intellij.execution.configurations.RunProfile
9+
import com.intellij.openapi.application.WriteAction
10+
import com.intellij.openapi.project.Project
11+
import com.intellij.openapi.project.guessProjectDir
12+
import com.intellij.openapi.vfs.VirtualFile
13+
import com.intellij.psi.PsiElement
14+
import com.intellij.psi.PsiFile
15+
import com.jetbrains.cidr.lang.OCLanguage
16+
import com.jetbrains.cidr.lang.psi.OCFunctionDeclaration
17+
import java.io.File
18+
19+
class CppAutoTestService : AutoTestService() {
20+
// TODO in Cpp233 and Cpp222 the RunProfile is different, maybe we can use the same RunProfile in future
21+
override fun runConfigurationClass(project: Project): Class<out RunProfile>? = null
22+
override fun isApplicable(element: PsiElement): Boolean = element.language is OCLanguage
23+
24+
override fun findOrCreateTestFile(sourceFile: PsiFile, project: Project, element: PsiElement): TestFileContext? {
25+
// 1. check project root test folder, if not exist, create it
26+
val baseDir = project.guessProjectDir() ?: return null
27+
28+
val sourceVirtualFile = sourceFile.virtualFile
29+
30+
val testFilePath = getTestFilePath(sourceVirtualFile)
31+
val testFile = WriteAction.computeAndWait<VirtualFile?, Throwable> {
32+
baseDir.findOrCreateChildData(this, testFilePath)
33+
} ?: return null
34+
35+
val currentClass = when (element) {
36+
is OCFunctionDeclaration -> {
37+
CppContextPrettify.printParentStructure(element)
38+
}
39+
40+
else -> null
41+
}
42+
43+
val relatedClasses = lookupRelevantClass(project, element)
44+
45+
return TestFileContext(
46+
true,
47+
testFile,
48+
relatedClasses,
49+
"",
50+
sourceFile.language,
51+
currentClass,
52+
emptyList()
53+
)
54+
}
55+
56+
private fun getTestFilePath(file: VirtualFile) = file.nameWithoutExtension + "_test" + "." + file.extension
57+
58+
override fun lookupRelevantClass(project: Project, element: PsiElement): List<ClassContext> {
59+
return listOf()
60+
}
61+
}

cpp/src/main/kotlin/cc/unitmesh/cpp/provider/testing/CppAutoTestService.kt renamed to cpp/src/233/main/kotlin/cc/unitmesh/cpp/provider/testing/CppAutoTestService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.jetbrains.cidr.lang.psi.OCFunctionDeclaration
1818
import java.io.File
1919

2020
class CppAutoTestService : AutoTestService() {
21-
// TODO in Cpp233 and Cpp222 the RunProfile is different, maybe we can use the same RunProfile in future
2221
override fun runConfigurationClass(project: Project): Class<out RunProfile>? = null
2322
override fun isApplicable(element: PsiElement): Boolean = element.language is OCLanguage
2423

0 commit comments

Comments
 (0)