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.
feat(js): init test service container
- Loading branch information
Showing
6 changed files
with
87 additions
and
28 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
25 changes: 0 additions & 25 deletions
25
webstorm/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/JavaScriptCodeModifier.kt
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...m/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/testing/JavaScriptTestCodeModifier.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,7 @@ | ||
package cc.unitmesh.ide.webstorm.provider.testing | ||
|
||
import cc.unitmesh.devti.context.builder.CodeModifier | ||
|
||
abstract class JavaScriptTestCodeModifier(val framework: String): CodeModifier { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...m/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/testing/JavaScriptWriteTestService.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,31 @@ | ||
package cc.unitmesh.ide.webstorm.provider.testing | ||
|
||
import cc.unitmesh.devti.context.ClassContext | ||
import cc.unitmesh.devti.provider.TestFileContext | ||
import cc.unitmesh.devti.provider.WriteTestService | ||
import cc.unitmesh.ide.webstorm.LanguageApplicableUtil | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.util.PlatformUtils | ||
|
||
class JavaScriptWriteTestService : WriteTestService() { | ||
override fun isApplicable(element: PsiElement): Boolean { | ||
if (PlatformUtils.isWebStorm()) return true | ||
|
||
val sourceFile: PsiFile = element.containingFile ?: return false | ||
return LanguageApplicableUtil.isJavaScriptApplicable(sourceFile.language) | ||
} | ||
|
||
override fun findOrCreateTestFile(sourceFile: PsiFile, project: Project, element: PsiElement): TestFileContext? { | ||
// find `__tests__` directory in root dir | ||
|
||
// find `__tests__` directory in current dir | ||
return null | ||
} | ||
|
||
override fun lookupRelevantClass(project: Project, element: PsiElement): List<ClassContext> { | ||
return emptyList() | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
webstorm/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/testing/JestCodeModifier.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,44 @@ | ||
package cc.unitmesh.ide.webstorm.provider.testing | ||
|
||
import cc.unitmesh.ide.webstorm.LanguageApplicableUtil | ||
import com.intellij.lang.Language | ||
import com.intellij.lang.javascript.psi.JSFile | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiManager | ||
import com.intellij.util.PlatformUtils | ||
|
||
class JestCodeModifier : JavaScriptTestCodeModifier("jest") { | ||
override fun isApplicable(language: Language): Boolean { | ||
if (PlatformUtils.isWebStorm()) return true | ||
|
||
return LanguageApplicableUtil.isJavaScriptApplicable(language) | ||
} | ||
|
||
override fun insertTestCode(sourceFile: VirtualFile, project: Project, code: String): Boolean { | ||
if (code.startsWith("import") && code.contains("test ")) { | ||
return insertClass(sourceFile, project, code) | ||
} | ||
|
||
insertMethod(sourceFile, project, code) | ||
return true | ||
} | ||
|
||
override fun insertMethod(sourceFile: VirtualFile, project: Project, code: String): Boolean { | ||
val file = PsiManager.getInstance(project).findFile(sourceFile) as JSFile | ||
ApplicationManager.getApplication().invokeLater { | ||
val rootElement = runReadAction { | ||
|
||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
override fun insertClass(sourceFile: VirtualFile, project: Project, code: String): Boolean { | ||
return true | ||
} | ||
|
||
} |
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