mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
- Java completions are now sorted
This commit is contained in:
@@ -17,6 +17,8 @@ import io.github.rosemoe.editor.text.TextAnalyzeResult;
|
||||
import io.github.rosemoe.editor.widget.CodeEditor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class JavaAutoComplete implements AutoCompleteProvider {
|
||||
|
||||
@@ -47,10 +49,18 @@ public class JavaAutoComplete implements AutoCompleteProvider {
|
||||
Either<SuggestItem, CompletionItem> either = Either.forLeft(new CompletionItemWrapper(item, prefix));
|
||||
result.add(either);
|
||||
}
|
||||
|
||||
Collections.sort(result, RESULT_SORTER);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return new ArrayList<Either<SuggestItem, CompletionItem>>();
|
||||
}
|
||||
|
||||
private static final Comparator<Either<SuggestItem, CompletionItem>> RESULT_SORTER = new Comparator<Either<SuggestItem, CompletionItem>>(){
|
||||
|
||||
@Override
|
||||
public int compare(Either<SuggestItem, CompletionItem> p1, Either<SuggestItem, CompletionItem> p2) {
|
||||
return p1.getLeft().getSortText().compareTo(p2.getLeft().getSortText());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.github.rosemoe.editor.text.CharPosition;
|
||||
import io.github.rosemoe.editor.text.Cursor;
|
||||
import io.github.rosemoe.editor.widget.CodeEditor;
|
||||
|
||||
public class CompletionItemWrapper implements SuggestItem {
|
||||
public class CompletionItemWrapper implements SuggestItem, Comparable {
|
||||
|
||||
private CompletionItem item;
|
||||
private String prefix;
|
||||
@@ -43,8 +43,8 @@ public class CompletionItemWrapper implements SuggestItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuggestionPriority() {
|
||||
return item.kind;
|
||||
public String getSortText() {
|
||||
return item.kind + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,6 +66,15 @@ public class CompletionItemWrapper implements SuggestItem {
|
||||
Logger.instance("CompletionItemWrapper").e("onSelectThis, Error: ", ThrowableUtils.getFullStackTrace(th));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object p1) {
|
||||
if(p1 instanceof CompletionItemWrapper) {
|
||||
CompletionItemWrapper that = (CompletionItemWrapper) p1;
|
||||
return this.getSortText().compareTo(that.getSortText());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private int getInsertLength() {
|
||||
if (prefix.endsWith(".")) return 0;
|
||||
|
||||
@@ -37,11 +37,11 @@ public class GradleSuggestItem implements SuggestItem {
|
||||
public char getTypeHeader() {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuggestionPriority() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSortText() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectThis(CodeEditor editor) {
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.itsaky.androidide.models;
|
||||
import io.github.rosemoe.editor.widget.CodeEditor;
|
||||
|
||||
public interface SuggestItem {
|
||||
public String getName();
|
||||
public String getDescription();
|
||||
public String getReturnType();
|
||||
public char getTypeHeader();
|
||||
public int getSuggestionPriority();
|
||||
public void onSelectThis(CodeEditor editor);
|
||||
String getName();
|
||||
String getDescription();
|
||||
String getReturnType();
|
||||
String getSortText();
|
||||
|
||||
char getTypeHeader();
|
||||
|
||||
void onSelectThis(CodeEditor editor);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.itsaky.androidide.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
|
||||
public class SourceJavaFileObject extends SimpleJavaFileObject {
|
||||
|
||||
private File file;
|
||||
private String source;
|
||||
|
||||
public SourceJavaFileObject(File file, String source) {
|
||||
super(URI.create("source"), Kind.SOURCE);
|
||||
this.file = file;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCharContent(boolean p1) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,4 @@ package com.itsaky.lsp;
|
||||
public class FormattingOptions {
|
||||
public int tabSize;
|
||||
public boolean insertSpaces;
|
||||
// TODO other properties embedded at same level
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user