use of org.eclipse.che.plugin.languageserver.ide.filters.Match in project che by eclipse.
the class FindSymbolAction method toSymbolEntries.
private List<SymbolEntry> toSymbolEntries(List<SymbolInformationDTO> types, String value) {
List<SymbolEntry> result = new ArrayList<>();
for (SymbolInformationDTO element : types) {
if (!SUPPORTED_OPEN_TYPES.contains(symbolKindHelper.from(element.getKind()))) {
continue;
}
List<Match> matches = fuzzyMatches.fuzzyMatch(value, element.getName());
if (matches != null) {
LocationDTO location = element.getLocation();
if (location != null && location.getUri() != null) {
String filePath = location.getUri();
RangeDTO locationRange = location.getRange();
TextRange range = null;
if (locationRange != null) {
range = new TextRange(new TextPosition(locationRange.getStart().getLine(), locationRange.getStart().getCharacter()), new TextPosition(locationRange.getEnd().getLine(), locationRange.getEnd().getCharacter()));
}
result.add(new SymbolEntry(element.getName(), "", filePath, filePath, symbolKindHelper.from(element.getKind()), range, symbolKindHelper.getIcon(element.getKind()), editorHelper, matches));
}
}
}
//TODO add sorting
return result;
}
use of org.eclipse.che.plugin.languageserver.ide.filters.Match in project che by eclipse.
the class CompletionItemBasedCompletionProposal method getDisplayString.
@Override
public String getDisplayString() {
SafeHtmlBuilder builder = new SafeHtmlBuilder();
String label = completionItem.getLabel();
int pos = 0;
for (Match highlight : highlights) {
if (highlight.getStart() == highlight.getEnd()) {
continue;
}
if (pos < highlight.getStart()) {
appendPlain(builder, label.substring(pos, highlight.getStart()));
}
appendHighlighted(builder, label.substring(highlight.getStart(), highlight.getEnd()));
pos = highlight.getEnd();
}
if (pos < label.length()) {
appendPlain(builder, label.substring(pos));
}
if (completionItem.getDetail() != null) {
appendDetail(builder, completionItem.getDetail());
}
return builder.toSafeHtml().asString();
}
use of org.eclipse.che.plugin.languageserver.ide.filters.Match in project che by eclipse.
the class LanguageServerCodeAssistProcessor method computeProposals.
private void computeProposals(String currentWord, int offset, CodeAssistCallback callback) {
List<CompletionProposal> proposals = newArrayList();
for (CompletionItemDTO item : latestCompletionResult.getCompletionList().getItems()) {
List<Match> highlights = filter(currentWord, item);
if (highlights != null) {
proposals.add(new CompletionItemBasedCompletionProposal(item, documentServiceClient, latestCompletionResult.getDocumentId(), resources, imageProvider.getIcon(item.getKind()), serverCapabilities, highlights, offset));
}
}
callback.proposalComputed(proposals);
}
use of org.eclipse.che.plugin.languageserver.ide.filters.Match in project che by eclipse.
the class GoToSymbolAction method toQuickOpenEntries.
private List<SymbolEntry> toQuickOpenEntries(List<SymbolInformationDTO> items, final String value) {
List<SymbolEntry> result = new ArrayList<>();
String normalValue = value;
if (value.startsWith(SCOPE_PREFIX)) {
normalValue = normalValue.substring(SCOPE_PREFIX.length());
}
for (SymbolInformationDTO item : items) {
String label = item.getName().trim();
List<Match> highlights = fuzzyMatches.fuzzyMatch(normalValue, label);
if (highlights != null) {
String description = null;
if (item.getContainerName() != null) {
description = item.getContainerName();
}
RangeDTO range = item.getLocation().getRange();
TextRange textRange = new TextRange(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()), new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
//TODO add icons
result.add(new SymbolEntry(label, symbolKindHelper.from(item.getKind()), description, textRange, (TextEditor) editorAgent.getActiveEditor(), highlights, symbolKindHelper.getIcon(item.getKind())));
}
}
if (!value.isEmpty()) {
if (value.startsWith(SCOPE_PREFIX)) {
Collections.sort(result, new Comparator<SymbolEntry>() {
@Override
public int compare(SymbolEntry o1, SymbolEntry o2) {
return sortScoped(value.toLowerCase(), o1, o2);
}
});
} else {
Collections.sort(result, new Comparator<SymbolEntry>() {
@Override
public int compare(SymbolEntry o1, SymbolEntry o2) {
return sortNormal(value.toLowerCase(), o1, o2);
}
});
}
}
if (!result.isEmpty() && value.startsWith(SCOPE_PREFIX)) {
String currentType = null;
SymbolEntry currentEntry = null;
int counter = 0;
for (int i = 0; i < result.size(); i++) {
SymbolEntry res = result.get(i);
if (!res.getType().equals(currentType)) {
if (currentEntry != null) {
currentEntry.setGroupLabel(typeToLabel(currentType, counter));
}
currentType = res.getType();
currentEntry = res;
counter = 1;
res.setWithBorder(i > 0);
} else {
counter++;
}
}
if (currentEntry != null) {
currentEntry.setGroupLabel(typeToLabel(currentType, counter));
}
} else if (!result.isEmpty()) {
result.get(0).setGroupLabel(localization.goToSymbolSymbols(result.size()));
}
return result;
}
Aggregations