Skip to content

Commit 470ec20

Browse files
author
Jia Liu
committed
feat: clean markdown chars and remove unused brace“
1 parent 581e56d commit 470ec20

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/main/kotlin/cc/unitmesh/devti/editor/inlay/LLMInlayManagerImpl.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cc.unitmesh.devti.editor.inlay
33
import com.intellij.temporary.inlay.presentation.LLMInlayRenderer
44
import cc.unitmesh.devti.intentions.action.task.CodeCompletionTask
55
import cc.unitmesh.devti.intentions.action.task.CodeCompletionRequest
6+
import cc.unitmesh.devti.util.parser.Code
7+
import cc.unitmesh.devti.util.parser.PostCodeProcessor
68
import com.intellij.injected.editor.EditorWindow
79
import com.intellij.openapi.Disposable
810
import com.intellij.openapi.application.ApplicationManager
@@ -22,7 +24,6 @@ import com.intellij.openapi.util.TextRange
2224
import com.intellij.psi.util.PsiUtilBase
2325
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
2426
import com.intellij.util.concurrency.annotations.RequiresEdt
25-
import java.util.function.Consumer
2627

2728

2829
class LLMInlayManagerImpl : LLMInlayManager {
@@ -114,13 +115,23 @@ class LLMInlayManagerImpl : LLMInlayManager {
114115

115116
override fun editorModified(editor: Editor, changeOffset: Int) {
116117
disposeInlays(editor, InlayDisposeContext.Typing)
117-
requestCompletions(editor, changeOffset) { completion ->
118-
if (completion.isEmpty()) return@requestCompletions
118+
requestCompletions(editor, changeOffset);
119+
}
120+
121+
@RequiresBackgroundThread
122+
private fun requestCompletions(editor: Editor, changeOffset: Int) {
123+
val element = PsiUtilBase.getElementAtCaret(editor) ?: return
124+
val request = CodeCompletionRequest.create(editor, changeOffset, element, null, null) ?: return
125+
126+
KEY_LAST_REQUEST[editor] = request
127+
CodeCompletionTask(request).execute { completion ->
128+
if (completion.isEmpty()) return@execute
119129

120-
currentCompletion = completion
130+
val completeCode = Code.parse(completion).text
131+
currentCompletion = PostCodeProcessor(request.prefixText, request.suffixText, completeCode).execute()
121132

122133
WriteCommandAction.runWriteCommandAction(editor.project) {
123-
val renderer = LLMInlayRenderer(editor, completion.lines())
134+
val renderer = LLMInlayRenderer(editor, currentCompletion.lines())
124135
renderer.apply {
125136
val inlay: Inlay<EditorCustomElementRenderer>? = editor.inlayModel
126137
.addBlockElement(changeOffset, true, false, 0, this)
@@ -132,15 +143,6 @@ class LLMInlayManagerImpl : LLMInlayManager {
132143
}
133144
}
134145

135-
@RequiresBackgroundThread
136-
private fun requestCompletions(editor: Editor, changeOffset: Int, onFirstCompletion: Consumer<String>?) {
137-
val element = PsiUtilBase.getElementAtCaret(editor) ?: return
138-
val request = CodeCompletionRequest.create(editor, changeOffset, element, null, null) ?: return
139-
140-
KEY_LAST_REQUEST[editor] = request
141-
CodeCompletionTask(request).execute(onFirstCompletion)
142-
}
143-
144146
override fun editorModified(editor: Editor) {
145147
editorModified(editor, editor.caretModel.offset)
146148
}

0 commit comments

Comments
 (0)