Search in sources :

Example 16 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition 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)

Example 17 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class DtoBuildHelper method createTDPP.

public TextDocumentPositionParamsDTO createTDPP(Document document, int cursorOffset) {
    TextDocumentPositionParamsDTO paramsDTO = dtoFactory.createDto(TextDocumentPositionParamsDTO.class);
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(document.getFile().getLocation().toString());
    PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
    TextPosition position = document.getPositionFromIndex(cursorOffset);
    positionDTO.setCharacter(position.getCharacter());
    positionDTO.setLine(position.getLine());
    paramsDTO.setUri(document.getFile().getLocation().toString());
    paramsDTO.setTextDocument(identifierDTO);
    paramsDTO.setPosition(positionDTO);
    return paramsDTO;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 18 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class OrionDocument method getSelectedTextRange.

@Override
public TextRange getSelectedTextRange() {
    final OrionSelectionOverlay selection = this.textViewOverlay.getSelection();
    final int start = selection.getStart();
    final TextPosition startPosition = getPositionFromIndex(start);
    final int end = selection.getEnd();
    final TextPosition endPosition = getPositionFromIndex(end);
    return new TextRange(startPosition, endPosition);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) OrionSelectionOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionSelectionOverlay) TextRange(org.eclipse.che.ide.api.editor.text.TextRange)

Example 19 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class OrionEditorPresenter method showQuickAssist.

protected void showQuickAssist() {
    if (quickAssistant == null) {
        return;
    }
    PositionConverter positionConverter = getPositionConverter();
    if (positionConverter != null) {
        TextPosition cursor = getCursorPosition();
        PositionConverter.PixelCoordinates pixelPos = positionConverter.textToPixel(cursor);
        quickAssistant.showPossibleQuickAssists(getCursorModel().getCursorPosition().getOffset(), pixelPos.getX(), pixelPos.getY());
    }
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter)

Example 20 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class OrionCursorModel method setCursorPosition.

@Override
public void setCursorPosition(int offset) {
    TextPosition position = document.getPositionFromIndex(offset);
    document.setCursorPosition(position);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition)

Aggregations

TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)34 Position (org.eclipse.che.ide.api.editor.text.Position)9 TextChange (org.eclipse.che.ide.api.editor.changeintercept.TextChange)8 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)7 Test (org.junit.Test)7 Document (org.eclipse.che.ide.api.editor.document.Document)6 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)5 Ignore (org.junit.Ignore)4 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 Element (elemental.dom.Element)2 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 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)2 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)2 File (org.eclipse.che.ide.api.resources.File)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 Optional (com.google.common.base.Optional)1 Timer (com.google.gwt.user.client.Timer)1