Skip to content

Commit

Permalink
feat: udpate for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 1, 2023
1 parent 8c9fec0 commit 947ffbe
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
@@ -0,0 +1,20 @@
package cc.unitmesh.devti.intentions

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.editor.inlay.LLMInlayManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile

class CodeCompletionInlayIntention : AbstractChatIntention() {
override fun getText(): String = AutoDevBundle.message("intentions.chat.inlay.complete.name")
override fun getFamilyName(): String = AutoDevBundle.message("intentions.chat.inlay.complete.family.name")
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
if (editor == null || file == null) return
val offset = editor.caretModel.offset

val llmInlayManager = LLMInlayManager.getInstance()
llmInlayManager
.editorModified(editor, offset)
}
}
@@ -1,11 +1,13 @@
package cc.unitmesh.devti.intentions

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.editor.inlay.LLMInlayManager
import cc.unitmesh.devti.intentions.task.CodeCompletionTask
import cc.unitmesh.devti.intentions.task.CompletionTaskRequest
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actions.EditorActionUtil
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiFile
Expand Down Expand Up @@ -43,12 +45,12 @@ class CodeCompletionIntention : AbstractChatIntention() {
val suffix = document.getText(TextRange(offset, suffixEnd))

val request = CompletionTaskRequest.create(editor, offset, element, prefix) ?: return
// val task = CodeCompletionTask(request)
// ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
val task = CodeCompletionTask(request)
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))

val llmInlayManager = LLMInlayManager.getInstance()
llmInlayManager
.editorModified(editor, offset)
// val llmInlayManager = LLMInlayManager.getInstance()
// llmInlayManager
// .editorModified(editor, offset)
}

companion object {
Expand Down
Expand Up @@ -77,21 +77,22 @@ class CodeCompletionTask(
private fun promptText(): String {
val prefix = request.documentContent.substring(0, request.offset)
val prompt = if (chunksString == null) {
prefix
"complete code for given code: \n$prefix"
} else {
"code complete for follow code: \n$commentPrefix${request.fileUri}\n$chunksString\n$prefix"
"complete code for given code: \n$commentPrefix${request.fileUri}\n$chunksString\n$prefix"
}

return prompt
}

fun execute(onFirstCompletion: Consumer<String>?) {
val prompt = promptText()

logger.warn("Prompt: $prompt")
LLMCoroutineScopeService.scope(project).launch {
val flow: Flow<String> = connectorFactory.connector(project).stream(prompt, "")
val suggestion = StringBuilder()
flow.collect {
print(it)
suggestion.append(it)
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/META-INF/autodev-core.xml
Expand Up @@ -43,7 +43,8 @@

<highlightErrorFilter implementation="cc.unitmesh.devti.gui.error.CodeBlockHighlightErrorFilter"/>
<daemon.highlightInfoFilter implementation="cc.unitmesh.devti.gui.error.CodeBlockHighlightingFilter"/>
<defaultHighlightingSettingProvider implementation="cc.unitmesh.devti.gui.error.CodeBlockHighlightingSettingsProvider"/>
<defaultHighlightingSettingProvider
implementation="cc.unitmesh.devti.gui.error.CodeBlockHighlightingSettingsProvider"/>
<daemon.intentionActionFilter implementation="cc.unitmesh.devti.gui.error.CodeBlockIntentionActionFilter"/>

</extensions>
Expand Down Expand Up @@ -122,6 +123,11 @@
<bundleName>messages.AutoDevBundle</bundleName>
<categoryKey>intention.category.llm</categoryKey>
</aiAssistantIntention>
<aiAssistantIntention>
<className>cc.unitmesh.devti.intentions.CodeCompletionInlayIntention</className>
<bundleName>messages.AutoDevBundle</bundleName>
<categoryKey>intention.category.llm</categoryKey>
</aiAssistantIntention>
<aiAssistantIntention>
<className>cc.unitmesh.devti.intentions.WriteTestIntention</className>
<bundleName>messages.AutoDevBundle</bundleName>
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -24,7 +24,9 @@ intentions.chat.code.test.family.name=Test this
intentions.assistant.name=AutoDev AI Assistant
Intention.category.llm=AutoDev LLM
intentions.assistant.popup.title=AutoDev AI Assistant
intentions.chat.code.test.step.prepare-context=Prepre context
intentions.chat.code.test.step.prepare-context=Prepare context
intentions.chat.code.test.step.prompt=Prompting to LLM
intentions.chat.code.test.step.write-test=Writing testing
intentions.chat.code.test.step.collect-context=Collect prompt context
intentions.chat.inlay.complete.family.name=AutoDev: Inlay Code complete
intentions.chat.inlay.complete.name=AutoDev: Inlay Code complete

0 comments on commit 947ffbe

Please sign in to comment.