Search in sources :

Example 6 with RangeDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO in project che by eclipse.

the class LanguageServerFormatter method applyEdits.

private void applyEdits(List<TextEditDTO> edits, Document document) {
    HandlesUndoRedo undoRedo = null;
    if (editor instanceof UndoableEditor) {
        undoRedo = ((UndoableEditor) editor).getUndoRedo();
    }
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        // #2437: apply the text edits from last to first to avoid messing up the document
        Collections.reverse(edits);
        for (TextEditDTO change : edits) {
            RangeDTO range = change.getRange();
            document.replace(range.getStart().getLine(), range.getStart().getCharacter(), range.getEnd().getLine(), range.getEnd().getCharacter(), change.getNewText());
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) TextEditDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with RangeDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO 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;
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) ArrayList(java.util.ArrayList) TextRange(org.eclipse.che.ide.api.editor.text.TextRange) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) Match(org.eclipse.che.plugin.languageserver.ide.filters.Match) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition)

Aggregations

RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)7 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)5 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)3 ArrayList (java.util.ArrayList)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)2 Document (org.eclipse.che.ide.api.editor.document.Document)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 List (java.util.List)1 DidChangeTextDocumentParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO)1 DocumentRangeFormattingParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO)1 LocationDTO (org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO)1 TextDocumentContentChangeEventDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO)1 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)1 TextEditDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO)1 VersionedTextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)1 Position (org.eclipse.che.ide.api.editor.text.Position)1 HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)1