Skip to content

Commit

Permalink
feat: update for listener
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 19, 2023
1 parent 76f3952 commit 71c426d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Expand Up @@ -3,10 +3,11 @@ package cc.unitmesh.devti.editor
import cc.unitmesh.devti.actions.LLMApplyInlaysAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorCustomElementRenderer
import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.keymap.KeymapUtil

class LLMInlayGotItListener : LLMInlayListener {
override fun inlaysUpdated(editor: Editor, insertedInlays: List<EditorCustomElementRenderer>) {
override fun inlaysUpdated(editor: Editor, insertedInlays: List<Inlay<EditorCustomElementRenderer>?>) {
if (insertedInlays.isEmpty()) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/editor/LLMInlayListener.kt
Expand Up @@ -2,12 +2,13 @@ package cc.unitmesh.devti.editor

import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorCustomElementRenderer
import com.intellij.openapi.editor.Inlay
import com.intellij.util.messages.Topic

interface LLMInlayListener {
fun inlaysUpdated(
editor: Editor,
insertedInlays: List<EditorCustomElementRenderer>,
insertedInlays: List<Inlay<EditorCustomElementRenderer>?>,
)

companion object {
Expand Down
@@ -1,19 +1,18 @@
package cc.unitmesh.devti.intentions.editor

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.editor.LLMInlayListener
import cc.unitmesh.devti.editor.LLMInlayManager
import cc.unitmesh.devti.editor.presentation.LLMInlayRenderer
import cc.unitmesh.devti.models.ConnectorFactory
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorCustomElementRenderer
import com.intellij.openapi.editor.actions.EditorActionUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
Expand Down Expand Up @@ -107,17 +106,15 @@ class CodeCompletionIntention : AbstractChatIntention() {
)

logger.warn("Prompt: $prompt")
Disposer.dispose( inlay as Disposable)
WriteCommandAction.runWriteCommandAction(editor.project!!) {
insertStringAndSaveChange(editor.project!!, text, editor.document, offset, false)

}

// val instance = LLMInlayManager.getInstance()
// instance.applyCompletion(editor.project!!, editor)
// ApplicationManager.getApplication().messageBus
// .syncPublisher(LLMInlayListener.TOPIC)
// .inlaysUpdated(editor, listOf(renderer))
val instance = LLMInlayManager.getInstance()
instance.applyCompletion(editor.project!!, editor)
//
// ApplicationManager.getApplication().messageBus.syncPublisher(LLMInlayListener.TOPIC)
// .inlaysUpdated(editor, listOf(inlay))
}

private val connectorFactory = ConnectorFactory.getInstance()
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/autodev-core.xml
Expand Up @@ -9,9 +9,9 @@
id="cc.unitmesh.devti.settings.AutoDevSettingsConfigurable"
displayName="AutoDev"/>

<applicationService
serviceInterface="cc.unitmesh.devti.editor.LLMInlayManager"
serviceImplementation="cc.unitmesh.devti.editor.LLMInlayManagerImpl" />
<!-- <applicationService-->
<!-- serviceInterface="cc.unitmesh.devti.editor.LLMInlayManager"-->
<!-- serviceImplementation="cc.unitmesh.devti.editor.LLMInlayManagerImpl" />-->

<applicationService serviceImplementation="cc.unitmesh.devti.settings.AutoDevSettingsState"/>

Expand Down

0 comments on commit 71c426d

Please sign in to comment.