mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-10 03:59:43 +00:00
fix: do not trigger code completions when active lookup present
This commit is contained in:
parent
8f7c38c705
commit
4611a21ac3
2 changed files with 21 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ import com.intellij.codeInsight.inline.completion.*
|
|||
import com.intellij.codeInsight.inline.completion.elements.InlineCompletionElement
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSingleSuggestion
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSuggestion
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.openapi.application.runInEdt
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
|
|
@ -18,6 +19,7 @@ import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings
|
|||
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings
|
||||
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings
|
||||
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings
|
||||
import ee.carlrobert.codegpt.util.StringUtil.extractUntilNewline
|
||||
import kotlinx.coroutines.channels.ProducerScope
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
|
|
@ -50,14 +52,6 @@ class DebouncedCodeCompletionProvider : DebouncedInlineCompletionProvider() {
|
|||
override val providerPresentation: InlineCompletionProviderPresentation
|
||||
get() = CodeCompletionProviderPresentation()
|
||||
|
||||
private fun String.extractUntilNewline(): String {
|
||||
val index = this.indexOf('\n')
|
||||
if (index == -1) {
|
||||
return this
|
||||
}
|
||||
return this.substring(0, index + 1)
|
||||
}
|
||||
|
||||
override suspend fun getSuggestionDebounced(request: InlineCompletionRequest): InlineCompletionSuggestion {
|
||||
val editor = request.editor
|
||||
val remainingCompletion = REMAINING_EDITOR_COMPLETION.get(editor)
|
||||
|
|
@ -74,8 +68,12 @@ class DebouncedCodeCompletionProvider : DebouncedInlineCompletionProvider() {
|
|||
return InlineCompletionSingleSuggestion.build(elements = emptyFlow())
|
||||
}
|
||||
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
return InlineCompletionSingleSuggestion.build(elements = emptyFlow())
|
||||
}
|
||||
|
||||
return InlineCompletionSingleSuggestion.build(elements = channelFlow {
|
||||
REMAINING_EDITOR_COMPLETION.set(request, "")
|
||||
REMAINING_EDITOR_COMPLETION.set(request.editor, "")
|
||||
IS_FETCHING_COMPLETION.set(request.editor, true)
|
||||
|
||||
request.editor.project?.messageBus
|
||||
|
|
@ -83,8 +81,7 @@ class DebouncedCodeCompletionProvider : DebouncedInlineCompletionProvider() {
|
|||
?.loading(true)
|
||||
|
||||
val infillRequest = InfillRequestUtil.buildInfillRequest(request)
|
||||
val call = project
|
||||
.service<CodeCompletionService>()
|
||||
val call = project.service<CodeCompletionService>()
|
||||
.getCodeCompletionAsync(
|
||||
infillRequest,
|
||||
getEventListener(request.editor, infillRequest)
|
||||
|
|
@ -116,6 +113,10 @@ class DebouncedCodeCompletionProvider : DebouncedInlineCompletionProvider() {
|
|||
return false
|
||||
}
|
||||
|
||||
if (LookupManager.getActiveLookup(event.toRequest()?.editor) != null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val containsActiveCompletion =
|
||||
REMAINING_EDITOR_COMPLETION.get(event.toRequest()?.editor)?.isNotEmpty() ?: false
|
||||
|
||||
|
|
@ -198,4 +199,4 @@ class DebouncedCodeCompletionProvider : DebouncedInlineCompletionProvider() {
|
|||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,12 @@ object StringUtil {
|
|||
|
||||
return completionLine
|
||||
}
|
||||
|
||||
fun String.extractUntilNewline(): String {
|
||||
val index = this.indexOf('\n')
|
||||
if (index == -1) {
|
||||
return this
|
||||
}
|
||||
return this.substring(0, index + 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue