Completions order for non-java context. Bean completions score.
This commit is contained in:
@@ -16,6 +16,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
@@ -78,5 +79,19 @@ public class CompositeCompletionEngine implements ICompletionEngine {
|
||||
return new InternalCompletionList(completions.build(), isIncomplete);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean keepCompletionsOrder(IDocument doc) {
|
||||
Collection<ICompletionEngine> engines = subEngines.get(doc.getLanguageId());
|
||||
if (engines != null) {
|
||||
for (ICompletionEngine e : engines) {
|
||||
if (e.keepCompletionsOrder(doc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.completion;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
@@ -19,4 +20,6 @@ public interface ICompletionEngine {
|
||||
|
||||
InternalCompletionList getCompletions(TextDocument document, int offset) throws Exception;
|
||||
|
||||
default boolean keepCompletionsOrder(IDocument doc) { return false; };
|
||||
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
boolean isIncomplete = rawCompletionList.isIncomplete();
|
||||
|
||||
List<CompletionItem> items = new ArrayList<>(completions.size());
|
||||
SortKeys sortkeys = new SortKeys();
|
||||
Optional<SortKeys> sortkeysOpt = engine.keepCompletionsOrder(doc) ? Optional.of(new SortKeys()) : Optional.empty();
|
||||
int count = 0;
|
||||
|
||||
for (ICompletionProposal c : completions) {
|
||||
@@ -237,7 +237,7 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
items.add(adaptItem(doc, c, sortkeys));
|
||||
items.add(adaptItem(doc, c, sortkeysOpt));
|
||||
} catch (Exception e) {
|
||||
log.error("error computing completion", e);
|
||||
}
|
||||
@@ -274,11 +274,11 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
return SimpleTextDocumentService.NO_COMPLETIONS;
|
||||
}
|
||||
|
||||
private CompletionItem adaptItem(TextDocument doc, ICompletionProposal completion, SortKeys sortkeys) throws Exception {
|
||||
private CompletionItem adaptItem(TextDocument doc, ICompletionProposal completion, Optional<SortKeys> sortkeysOpt) throws Exception {
|
||||
CompletionItem item = new CompletionItem();
|
||||
item.setLabel(completion.getLabel());
|
||||
item.setKind(completion.getKind());
|
||||
item.setSortText(sortkeys.next());
|
||||
sortkeysOpt.ifPresent(sortkeys -> item.setSortText(sortkeys.next()));
|
||||
item.setFilterText(completion.getFilterText());
|
||||
item.setInsertTextMode(InsertTextMode.AsIs);
|
||||
item.setLabelDetails(completion.getLabelDetails());
|
||||
|
||||
@@ -113,7 +113,7 @@ public class DefaultCompletionFactory implements CompletionFactory {
|
||||
|
||||
@Override
|
||||
public CompletionItemKind getKind() {
|
||||
return CompletionItemKind.Keyword;
|
||||
return CompletionItemKind.Value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -480,4 +480,10 @@ public class YamlCompletionEngine implements ICompletionEngine {
|
||||
throw new IllegalStateException("Missing case");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keepCompletionsOrder(IDocument doc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -585,21 +585,6 @@ public class Editor {
|
||||
public List<CompletionItem> getCompletions() throws Exception {
|
||||
CompletionList cl = harness.getCompletions(this.doc, this.getCursor());
|
||||
ArrayList<CompletionItem> items = new ArrayList<>(cl.getItems());
|
||||
Collections.sort(items, new Comparator<CompletionItem>() {
|
||||
|
||||
@Override
|
||||
public int compare(CompletionItem o1, CompletionItem o2) {
|
||||
return sortKey(o1).compareTo(sortKey(o2));
|
||||
}
|
||||
|
||||
private String sortKey(CompletionItem item) {
|
||||
String k = item.getSortText();
|
||||
if (k == null) {
|
||||
k = item.getLabel();
|
||||
}
|
||||
return k;
|
||||
}
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user