Merge pull request #4417 from lkk214/refactor/widget-initialization
refactor: Optimize widget initialization and loading state
This commit is contained in:
commit
331aa85623
3 changed files with 26 additions and 32 deletions
|
|
@ -134,6 +134,13 @@ export class CompletionProvider {
|
|||
token: AbortSignal | undefined,
|
||||
): Promise<AutocompleteOutcome | undefined> {
|
||||
try {
|
||||
// Create abort signal if not given
|
||||
if (!token) {
|
||||
const controller = this.loggingService.createAbortController(
|
||||
input.completionId,
|
||||
);
|
||||
token = controller.signal;
|
||||
}
|
||||
const startTime = Date.now();
|
||||
const options = await this._getAutocompleteOptions();
|
||||
|
||||
|
|
@ -158,14 +165,6 @@ export class CompletionProvider {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Create abort signal if not given
|
||||
if (!token) {
|
||||
const controller = this.loggingService.createAbortController(
|
||||
input.completionId,
|
||||
);
|
||||
token = controller.signal;
|
||||
}
|
||||
|
||||
const [snippetPayload, workspaceDirs] = await Promise.all([
|
||||
getAllSnippets({
|
||||
helper,
|
||||
|
|
|
|||
|
|
@ -54,17 +54,15 @@ fun Editor.addInlayElement(
|
|||
class AutocompleteService(private val project: Project) {
|
||||
var pendingCompletion: PendingCompletion? = null
|
||||
private val autocompleteLookupListener = project.service<AutocompleteLookupListener>()
|
||||
private var widget: AutocompleteSpinnerWidget? = null
|
||||
private val widget: AutocompleteSpinnerWidget? by lazy {
|
||||
WindowManager.getInstance().getStatusBar(project)
|
||||
?.getWidget(AutocompleteSpinnerWidget.ID) as? AutocompleteSpinnerWidget
|
||||
}
|
||||
|
||||
// To avoid triggering another completion on partial acceptance,
|
||||
// we need to keep track of whether the last change was a partial accept
|
||||
var lastChangeWasPartialAccept = false
|
||||
|
||||
init {
|
||||
val statusBar = WindowManager.getInstance().getStatusBar(project)
|
||||
widget = statusBar.getWidget("AutocompleteSpinnerWidget") as? AutocompleteSpinnerWidget
|
||||
}
|
||||
|
||||
fun triggerCompletion(editor: Editor) {
|
||||
val settings =
|
||||
ServiceManager.getService(ContinueExtensionSettings::class.java)
|
||||
|
|
@ -80,13 +78,14 @@ class AutocompleteService(private val project: Project) {
|
|||
val completionId = uuid()
|
||||
val offset = editor.caretModel.primaryCaret.offset
|
||||
pendingCompletion = PendingCompletion(editor, offset, completionId, null)
|
||||
widget?.setLoading(true)
|
||||
|
||||
// Request a completion from the core
|
||||
val virtualFile = FileDocumentManager.getInstance().getFile(editor.document)
|
||||
|
||||
val uri = virtualFile?.toUriOrNull() ?: return
|
||||
|
||||
widget?.setLoading(true)
|
||||
|
||||
val line = editor.caretModel.primaryCaret.logicalPosition.line
|
||||
val column = editor.caretModel.primaryCaret.logicalPosition.column
|
||||
val input = mapOf(
|
||||
|
|
@ -106,7 +105,9 @@ class AutocompleteService(private val project: Project) {
|
|||
input,
|
||||
null,
|
||||
({ response ->
|
||||
widget?.setLoading(false)
|
||||
if (pendingCompletion == null || pendingCompletion?.completionId == completionId) {
|
||||
widget?.setLoading(false)
|
||||
}
|
||||
|
||||
val responseObject = response as Map<*, *>
|
||||
val completions = responseObject["content"] as List<*>
|
||||
|
|
|
|||
|
|
@ -23,17 +23,7 @@ class AutocompleteSpinnerWidget(project: Project) : EditorBasedWidget(project),
|
|||
private val iconLabel = JLabel()
|
||||
private var isLoading = false
|
||||
|
||||
private val animatedIcon = AnimatedIcon(
|
||||
100,
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading1(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading2(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading3(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading4(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading5(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading6(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading7(RiderLight).svg", javaClass),
|
||||
IconLoader.getIcon("/icons/AnimationLoadingIcon/AnimationLoading8(RiderLight).svg", javaClass),
|
||||
)
|
||||
private val animatedIcon = AnimatedIcon.Default()
|
||||
|
||||
init {
|
||||
Disposer.register(ContinuePluginDisposable.getInstance(project), this)
|
||||
|
|
@ -47,10 +37,10 @@ class AutocompleteSpinnerWidget(project: Project) : EditorBasedWidget(project),
|
|||
override fun dispose() {}
|
||||
|
||||
override fun ID(): String {
|
||||
return "AutocompleteSpinnerWidget"
|
||||
return ID
|
||||
}
|
||||
|
||||
override fun getTooltipText(): String? {
|
||||
override fun getTooltipText(): String {
|
||||
val enabled = service<ContinueExtensionSettings>().state.enableTabAutocomplete
|
||||
return if (enabled) "Continue autocomplete enabled" else "Continue autocomplete disabled"
|
||||
}
|
||||
|
|
@ -80,9 +70,13 @@ class AutocompleteSpinnerWidget(project: Project) : EditorBasedWidget(project),
|
|||
updateIcon()
|
||||
}
|
||||
|
||||
override fun getPresentation(): StatusBarWidget.WidgetPresentation? {
|
||||
override fun getPresentation(): StatusBarWidget.WidgetPresentation {
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ID = "AutocompleteSpinnerWidget"
|
||||
}
|
||||
}
|
||||
|
||||
class AutocompleteSpinnerWidgetFactory : StatusBarWidgetFactory {
|
||||
|
|
@ -91,7 +85,7 @@ class AutocompleteSpinnerWidgetFactory : StatusBarWidgetFactory {
|
|||
}
|
||||
|
||||
override fun getId(): String {
|
||||
return "AutocompleteSpinnerWidget"
|
||||
return AutocompleteSpinnerWidget.ID
|
||||
}
|
||||
|
||||
override fun getDisplayName(): String {
|
||||
|
|
@ -103,7 +97,7 @@ class AutocompleteSpinnerWidgetFactory : StatusBarWidgetFactory {
|
|||
}
|
||||
|
||||
override fun createWidget(project: Project): StatusBarWidget {
|
||||
return AutocompleteSpinnerWidget(project)
|
||||
return create(project)
|
||||
}
|
||||
|
||||
override fun disposeWidget(p0: StatusBarWidget) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue