fix: use custom CompletionPublisher to avoid recreating completion list in IDELanguage

This commit is contained in:
Akash Yadav
2023-09-24 20:13:42 +05:30
parent dcc625f75b
commit 73be7f5259
3 changed files with 49 additions and 2 deletions
@@ -19,6 +19,7 @@ package com.itsaky.androidide.editor.language;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.itsaky.androidide.editor.api.IEditor;
import com.itsaky.androidide.editor.ui.IDECompletionPublisher;
import com.itsaky.androidide.lookup.Lookup;
import com.itsaky.androidide.lsp.api.ILanguageServer;
import com.itsaky.androidide.preferences.internal.EditorPreferencesKt;
@@ -84,7 +85,8 @@ public abstract class IDELanguage implements Language {
completionProvider.complete(content, file, position, this::checkIsCompletionChar);
publisher.setUpdateThreshold(1);
publisher.addItems(new ArrayList<>(completionItems));
((IDECompletionPublisher) publisher).addLSPItems(completionItems);
}
protected ILanguageServer getLanguageServer() {
@@ -123,7 +123,7 @@ class EditorCompletionWindow(val editor: IDEEditor) : EditorAutoCompletion(edito
currentSelection = -1
publisher =
CompletionPublisher(
IDECompletionPublisher(
editor.handler,
{
val items = publisher.items
@@ -0,0 +1,45 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.editor.ui
import android.os.Handler
import io.github.rosemoe.sora.lang.completion.CompletionItem
import io.github.rosemoe.sora.lang.completion.CompletionPublisher
/**
* [CompletionPublisher] implementation for AndroidIDE.
*
* @author Akash Yadav
*/
class IDECompletionPublisher(
handler: Handler,
callback: Runnable,
languageInterruptionLevel: Int
) : CompletionPublisher(handler, callback, languageInterruptionLevel) {
init {
setUpdateThreshold(1)
}
/**
* Adds the given [completion items][items] to the completion list.
*/
fun <CompletionItemT : CompletionItem> addLSPItems(items: Collection<CompletionItemT>) {
super.addItems(items)
}
}