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: init basic js context provider
- Loading branch information
Showing
10 changed files
with
125 additions
and
120 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
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
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
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
19 changes: 0 additions & 19 deletions
19
kotlin/src/main/kotlin/cc/unitmesh/kotlin/provider/KotlinVersionProvider.kt
This file was deleted.
Oops, something went wrong.
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
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
117 changes: 117 additions & 0 deletions
117
webstorm/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/JavaScriptContextProvider.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,117 @@ | ||
package cc.unitmesh.ide.webstorm.provider | ||
|
||
import cc.unitmesh.devti.prompting.code.TestStack | ||
import cc.unitmesh.devti.provider.context.ChatContextItem | ||
import cc.unitmesh.devti.provider.context.ChatContextProvider | ||
import cc.unitmesh.devti.provider.context.ChatCreationContext | ||
import com.intellij.javascript.nodejs.PackageJsonData | ||
import com.intellij.javascript.nodejs.PackageJsonDependency | ||
import com.intellij.json.JsonLanguage | ||
import com.intellij.lang.html.HTMLLanguage | ||
import com.intellij.lang.javascript.JavaScriptSupportLoader | ||
import com.intellij.lang.javascript.JavascriptLanguage | ||
import com.intellij.lang.javascript.buildTools.npm.PackageJsonUtil | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.openapi.project.guessProjectDir | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.util.PlatformUtils | ||
|
||
class JavaScriptContextProvider : ChatContextProvider { | ||
private val supportedLanguages = setOf(JavascriptLanguage.INSTANCE.id, JavaScriptSupportLoader.TYPESCRIPT.id) | ||
override fun isApplicable(project: Project, creationContext: ChatCreationContext): Boolean { | ||
if (PlatformUtils.isWebStorm()) return true | ||
|
||
val sourceFile: PsiFile = creationContext.sourceFile ?: return false | ||
val language = sourceFile.language | ||
|
||
return supportedLanguages.contains(language.id) || language is HTMLLanguage || language is JsonLanguage | ||
} | ||
|
||
override suspend fun collect(project: Project, creationContext: ChatCreationContext): List<ChatContextItem> { | ||
val techStack = prepareLibrary() | ||
|
||
val results = mutableListOf<ChatContextItem>() | ||
if (techStack.coreFrameworks().isNotEmpty()) { | ||
results.add( | ||
ChatContextItem( | ||
JavaScriptContextProvider::class, | ||
"The project uses the following JavaScript component frameworks: ${techStack.coreFrameworks()}" | ||
) | ||
) | ||
} | ||
|
||
if (techStack.testFrameworks().isNotEmpty()) { | ||
results.add( | ||
ChatContextItem( | ||
JavaScriptContextProvider::class, | ||
"The project uses ${techStack.testFrameworks()} to test." | ||
) | ||
) | ||
} | ||
|
||
return results | ||
} | ||
|
||
|
||
fun prepareLibrary(): TestStack { | ||
val project = ProjectManager.getInstance().openProjects.firstOrNull() ?: return TestStack() | ||
|
||
val baseDir = project.guessProjectDir() ?: return TestStack() | ||
val packageFile = PackageJsonUtil.findUpPackageJson(baseDir) ?: return TestStack() | ||
val packageJsonData = PackageJsonData.getOrCreate(packageFile) | ||
|
||
val devDependencies = mutableMapOf<String, String>() | ||
val dependencies = mutableMapOf<String, String>() | ||
|
||
val frameworks = mutableMapOf<String, Boolean>() | ||
val testFrameworks = mutableMapOf<String, Boolean>() | ||
|
||
packageJsonData.allDependencyEntries.forEach { (name, entry) -> | ||
entry.dependencyType.let { | ||
when (it) { | ||
PackageJsonDependency.dependencies -> { | ||
// also remove `eslint` | ||
if (!name.startsWith("@types/")) { | ||
devDependencies[name] = entry.versionRange | ||
} | ||
|
||
JsWebFrameworks.values().forEach { framework -> | ||
if (name.startsWith(framework.name) || name == framework.name) { | ||
frameworks[framework.name] = true | ||
} | ||
} | ||
JsTestFrameworks.values().forEach { testFramework -> | ||
if (name.startsWith(testFramework.name) || name == testFramework.name) { | ||
testFrameworks[testFramework.name] = true | ||
} | ||
} | ||
} | ||
|
||
PackageJsonDependency.devDependencies -> { | ||
devDependencies[name] = entry.versionRange | ||
|
||
JsWebFrameworks.values().forEach { frameworkName -> | ||
if (name.startsWith(frameworkName.name) || name == frameworkName.name) { | ||
frameworks[frameworkName.name] = true | ||
} | ||
} | ||
JsTestFrameworks.values().forEach { testFramework -> | ||
if (name.startsWith(testFramework.name) || name == testFramework.name) { | ||
testFrameworks[testFramework.name] = true | ||
} | ||
} | ||
} | ||
|
||
PackageJsonDependency.peerDependencies -> {} | ||
PackageJsonDependency.optionalDependencies -> {} | ||
PackageJsonDependency.bundledDependencies -> { | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
return TestStack(frameworks, testFrameworks, dependencies, devDependencies) | ||
} | ||
} |
91 changes: 0 additions & 91 deletions
91
webstorm/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/JavaScriptTechStackService.kt
This file was deleted.
Oops, something went wrong.
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