mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-10 03:59:43 +00:00
fix: remaining completion when code completion overtyped
This commit is contained in:
parent
5a75d1bfd4
commit
ee4aee2a57
2 changed files with 27 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ import com.intellij.openapi.editor.actionSystem.EditorAction
|
|||
import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.util.concurrency.ThreadingAssertions
|
||||
import ee.carlrobert.codegpt.CodeGPTKeys
|
||||
import ee.carlrobert.codegpt.CodeGPTKeys.REMAINING_EDITOR_COMPLETION
|
||||
|
||||
class CodeCompletionInsertAction :
|
||||
|
|
@ -31,6 +32,12 @@ class CodeCompletionInsertAction :
|
|||
.map { it.element as CodeCompletionTextElement }
|
||||
|
||||
if (elements.isEmpty()) {
|
||||
val textToInsert = context.textToInsert()
|
||||
val remainingCompletion = REMAINING_EDITOR_COMPLETION.get(editor)
|
||||
if (remainingCompletion.isNotEmpty()) {
|
||||
REMAINING_EDITOR_COMPLETION.set(editor, remainingCompletion.removePrefix(textToInsert))
|
||||
}
|
||||
|
||||
InlineCompletion.getHandlerOrNull(editor)?.insert()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,20 @@ import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSug
|
|||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSuggestionUpdateManager.UpdateResult.Changed
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSuggestionUpdateManager.UpdateResult.Invalidated
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionVariant
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import ee.carlrobert.codegpt.CodeGPTKeys.REMAINING_EDITOR_COMPLETION
|
||||
|
||||
class CodeCompletionSuggestionUpdateAdapter :
|
||||
InlineCompletionSuggestionUpdateManager.Default() {
|
||||
|
||||
override fun onDocumentChange(
|
||||
event: InlineCompletionEvent.DocumentChange,
|
||||
variant: InlineCompletionVariant.Snapshot
|
||||
): UpdateResult {
|
||||
updateRemainingCompletion(event.editor, event.typing.typed)
|
||||
return super.onDocumentChange(event, variant)
|
||||
}
|
||||
|
||||
override fun onCustomEvent(
|
||||
event: InlineCompletionEvent,
|
||||
variant: InlineCompletionVariant.Snapshot
|
||||
|
|
@ -23,10 +33,20 @@ class CodeCompletionSuggestionUpdateAdapter :
|
|||
val textToInsert = event.toRequest().run {
|
||||
CompletionSplitter.split(completionText)
|
||||
}
|
||||
|
||||
updateRemainingCompletion(event.toRequest().editor, textToInsert)
|
||||
|
||||
return Changed(
|
||||
variant.copy(
|
||||
listOf(InlineCompletionGrayTextElement(completionText.removePrefix(textToInsert)))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateRemainingCompletion(editor: Editor, textToInsert: String) {
|
||||
val remainingCompletion = REMAINING_EDITOR_COMPLETION.get(editor)
|
||||
if (remainingCompletion.isNotEmpty()) {
|
||||
REMAINING_EDITOR_COMPLETION.set(editor, remainingCompletion.removePrefix(textToInsert))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue