generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devins-cpp): move test config for Intellij IDEA 223 only, which i…
…s 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.
- Loading branch information
Showing
4 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cpp/src/222/main/kotlin/cc/unitmesh/cpp/provider/testing/CppAutoTestService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cc.unitmesh.cpp.provider.testing | ||
|
||
import cc.unitmesh.cpp.util.CppContextPrettify | ||
import cc.unitmesh.devti.context.ClassContext | ||
import cc.unitmesh.devti.provider.AutoTestService | ||
import cc.unitmesh.devti.provider.context.TestFileContext | ||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.execution.configurations.RunProfile | ||
import com.intellij.openapi.application.WriteAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.guessProjectDir | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import com.jetbrains.cidr.lang.OCLanguage | ||
import com.jetbrains.cidr.lang.psi.OCFunctionDeclaration | ||
import java.io.File | ||
|
||
class CppAutoTestService : AutoTestService() { | ||
// TODO in Cpp233 and Cpp222 the RunProfile is different, maybe we can use the same RunProfile in future | ||
override fun runConfigurationClass(project: Project): Class<out RunProfile>? = null | ||
override fun isApplicable(element: PsiElement): Boolean = element.language is OCLanguage | ||
|
||
override fun findOrCreateTestFile(sourceFile: PsiFile, project: Project, element: PsiElement): TestFileContext? { | ||
// 1. check project root test folder, if not exist, create it | ||
val baseDir = project.guessProjectDir() ?: return null | ||
|
||
val sourceVirtualFile = sourceFile.virtualFile | ||
|
||
val testFilePath = getTestFilePath(sourceVirtualFile) | ||
val testFile = WriteAction.computeAndWait<VirtualFile?, Throwable> { | ||
baseDir.findOrCreateChildData(this, testFilePath) | ||
} ?: return null | ||
|
||
val currentClass = when (element) { | ||
is OCFunctionDeclaration -> { | ||
CppContextPrettify.printParentStructure(element) | ||
} | ||
|
||
else -> null | ||
} | ||
|
||
val relatedClasses = lookupRelevantClass(project, element) | ||
|
||
return TestFileContext( | ||
true, | ||
testFile, | ||
relatedClasses, | ||
"", | ||
sourceFile.language, | ||
currentClass, | ||
emptyList() | ||
) | ||
} | ||
|
||
private fun getTestFilePath(file: VirtualFile) = file.nameWithoutExtension + "_test" + "." + file.extension | ||
|
||
override fun lookupRelevantClass(project: Project, element: PsiElement): List<ClassContext> { | ||
return listOf() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.