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.
- Loading branch information
Showing
5 changed files
with
69 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
15 changes: 15 additions & 0 deletions
15
csharp/src/main/kotlin/cc/unitmesh/csharp/context/CsharpClassContextBuilder.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,15 @@ | ||
package cc.unitmesh.csharp.context | ||
|
||
import cc.unitmesh.devti.context.ClassContext | ||
import cc.unitmesh.devti.context.builder.ClassContextBuilder | ||
import com.intellij.psi.PsiElement | ||
import com.jetbrains.rider.ideaInterop.fileTypes.csharp.psi.CSharpBlock | ||
|
||
class CsharpClassContextBuilder : ClassContextBuilder { | ||
override fun getClassContext(psiElement: PsiElement, gatherUsages: Boolean): ClassContext? { | ||
if (psiElement !is CSharpBlock) return null | ||
|
||
return null | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
csharp/src/main/kotlin/cc/unitmesh/csharp/provider/CsharpContextPrompter.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,39 @@ | ||
package cc.unitmesh.csharp.provider | ||
|
||
import cc.unitmesh.devti.gui.chat.ChatActionType | ||
import cc.unitmesh.devti.provider.ContextPrompter | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.temporary.similar.chunks.SimilarChunksWithPaths | ||
|
||
class CsharpContextPrompter : ContextPrompter() { | ||
private var additionContext: String = "" | ||
|
||
companion object { | ||
val log = logger<CsharpContextPrompter>() | ||
} | ||
|
||
override fun initContext( | ||
actionType: ChatActionType, | ||
selectedText: String, | ||
file: PsiFile?, | ||
project: Project, | ||
offset: Int, | ||
element: PsiElement? | ||
) { | ||
super.initContext(actionType, selectedText, file, project, offset, element) | ||
additionContext = SimilarChunksWithPaths.createQuery(file!!) ?: "" | ||
} | ||
|
||
override fun displayPrompt(): String { | ||
return "$action\n```${lang}\n$selectedText\n```" | ||
} | ||
|
||
override fun requestPrompt(): String { | ||
val prompt = "$action\n```${lang}\n$additionContext\n$selectedText\n```" | ||
log.info("final prompt: $prompt") | ||
return prompt | ||
} | ||
} |
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,13 @@ | ||
<idea-plugin package="cc.unitmesh.csharp"> | ||
<!--suppress PluginXmlValidity --> | ||
<dependencies> | ||
<plugin id="com.intellij.modules.rider"/> | ||
</dependencies> | ||
|
||
<extensions defaultExtensionNs="cc.unitmesh"> | ||
<classContextBuilder language="C#" | ||
implementationClass="cc.unitmesh.csharp.context.CsharpClassContextBuilder"/> | ||
|
||
<contextPrompter language="C#" implementation="cc.unitmesh.csharp.provider.CsharpContextPrompter"/> | ||
</extensions> | ||
</idea-plugin> |
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