mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-11 13:10:50 +00:00
fix: edit code popover loading state
This commit is contained in:
parent
d41bb317e5
commit
ffc667d17e
3 changed files with 21 additions and 23 deletions
|
|
@ -36,6 +36,7 @@ class EditCodeCompletionListener(
|
|||
}
|
||||
|
||||
override fun onError(error: ErrorDetails, ex: Throwable) {
|
||||
observableProperties.loading.set(false)
|
||||
OverlayUtil.showNotification(
|
||||
"Something went wrong while requesting completion. Please try again.",
|
||||
NotificationType.ERROR
|
||||
|
|
|
|||
|
|
@ -20,32 +20,28 @@ class EditCodeSubmissionHandler(
|
|||
private val previousSourceRef = AtomicReference<String?>(null)
|
||||
|
||||
suspend fun handleSubmit(userPrompt: String) {
|
||||
try {
|
||||
observableProperties.loading.set(true)
|
||||
observableProperties.submitted.set(true)
|
||||
observableProperties.loading.set(true)
|
||||
observableProperties.submitted.set(true)
|
||||
|
||||
previousSourceRef.getAndSet(editor.document.text)
|
||||
val (selectionTextRange, selectedText) = readAction {
|
||||
editor.selectionModel.run {
|
||||
Pair(
|
||||
TextRange(selectionStart, selectionEnd),
|
||||
editor.selectionModel.selectedText ?: ""
|
||||
)
|
||||
}
|
||||
previousSourceRef.getAndSet(editor.document.text)
|
||||
val (selectionTextRange, selectedText) = readAction {
|
||||
editor.selectionModel.run {
|
||||
Pair(
|
||||
TextRange(selectionStart, selectionEnd),
|
||||
editor.selectionModel.selectedText ?: ""
|
||||
)
|
||||
}
|
||||
runInEdt { editor.selectionModel.removeSelection() }
|
||||
|
||||
// TODO: Support other providers
|
||||
CompletionClientProvider.getCodeGPTClient().getChatCompletionAsync(
|
||||
CompletionRequestProvider.buildEditCodeRequest(
|
||||
"$userPrompt\n\n$selectedText",
|
||||
service<CodeGPTServiceSettings>().state.chatCompletionSettings.model
|
||||
),
|
||||
EditCodeCompletionListener(editor, observableProperties, selectionTextRange)
|
||||
)
|
||||
} finally {
|
||||
observableProperties.loading.set(false)
|
||||
}
|
||||
runInEdt { editor.selectionModel.removeSelection() }
|
||||
|
||||
// TODO: Support other providers
|
||||
CompletionClientProvider.getCodeGPTClient().getChatCompletionAsync(
|
||||
CompletionRequestProvider.buildEditCodeRequest(
|
||||
"$userPrompt\n\n$selectedText",
|
||||
service<CodeGPTServiceSettings>().state.chatCompletionSettings.model
|
||||
),
|
||||
EditCodeCompletionListener(editor, observableProperties, selectionTextRange)
|
||||
)
|
||||
}
|
||||
|
||||
fun handleAccept() {
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ class EditCodePopover(private val editor: Editor) {
|
|||
popup.cancel()
|
||||
}
|
||||
.visibleIf(observableProperties.submitted)
|
||||
.enabledIf(observableProperties.loading.not())
|
||||
cell(AsyncProcessIcon("edit_code_spinner")).visibleIf(observableProperties.loading)
|
||||
link(CodeGPTBundle.get("shared.discard")) {
|
||||
submissionHandler.handleReject()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue