Search in sources :

Example 1 with RangeDTO

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

the class LanguageServerAnnotationModel method createPositionFromDiagnostic.

protected Position createPositionFromDiagnostic(final DiagnosticDTO diagnostic) {
    DocumentHandle documentHandle = getDocumentHandle();
    Document document = documentHandle.getDocument();
    RangeDTO range = diagnostic.getRange();
    int start = document.getIndexFromPosition(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()));
    int end = document.getIndexFromPosition(new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
    if (start == -1 && end == -1) {
        return new Position(0);
    }
    if (start == -1) {
        return new Position(end);
    }
    if (end == -1) {
        return new Position(start);
    }
    int length = end - start;
    if (length < 0) {
        return null;
    }
    return new Position(start, length);
}
Also used : DocumentHandle(org.eclipse.che.ide.api.editor.document.DocumentHandle) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)

Example 2 with RangeDTO

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

the class IncrementalTextDocumentSynchronize method syncTextDocument.

@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
    Document document = event.getDocument().getDocument();
    TextPosition startPosition = document.getPositionFromIndex(event.getOffset());
    TextPosition endPosition;
    if (event.getRemoveCharCount() != 0) {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount());
    } else {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter());
    }
    DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class);
    String uri = document.getFile().getLocation().toString();
    changeDTO.setUri(uri);
    VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class);
    versionedDocId.setUri(uri);
    versionedDocId.setVersion(version);
    changeDTO.setTextDocument(versionedDocId);
    RangeDTO range = dtoFactory.createDto(RangeDTO.class);
    PositionDTO start = dtoFactory.createDto(PositionDTO.class);
    start.setLine(startPosition.getLine());
    start.setCharacter(startPosition.getCharacter());
    PositionDTO end = dtoFactory.createDto(PositionDTO.class);
    end.setLine(endPosition.getLine());
    end.setCharacter(endPosition.getCharacter());
    range.setStart(start);
    range.setEnd(end);
    TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
    actualChange.setRange(range);
    actualChange.setText(event.getText());
    changeDTO.setContentChanges(Collections.singletonList(actualChange));
    textDocumentService.didChange(changeDTO);
}
Also used : VersionedTextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO) TextDocumentContentChangeEventDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO) DidChangeTextDocumentParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 3 with RangeDTO

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

the class OpenLocationPresenter method onLocationSelected.

@Override
public void onLocationSelected(LocationDTO location) {
    RangeDTO range = location.getRange();
    helper.openFile(location.getUri(), new TextRange(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()), new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter())));
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextRange(org.eclipse.che.ide.api.editor.text.TextRange) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)

Example 4 with RangeDTO

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

Example 5 with RangeDTO

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

the class LanguageServerFormatter method formatRange.

private void formatRange(TextRange selectedRange, Document document) {
    DocumentRangeFormattingParamsDTO params = dtoFactory.createDto(DocumentRangeFormattingParamsDTO.class);
    TextDocumentIdentifierDTO identifier = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifier.setUri(document.getFile().getLocation().toString());
    params.setTextDocument(identifier);
    params.setOptions(getFormattingOptions());
    RangeDTO range = dtoFactory.createDto(RangeDTO.class);
    PositionDTO start = dtoFactory.createDto(PositionDTO.class);
    PositionDTO end = dtoFactory.createDto(PositionDTO.class);
    start.setLine(selectedRange.getFrom().getLine());
    start.setCharacter(selectedRange.getFrom().getCharacter());
    end.setLine(selectedRange.getTo().getLine());
    end.setCharacter(selectedRange.getTo().getCharacter());
    range.setStart(start);
    range.setEnd(end);
    params.setRange(range);
    Promise<List<TextEditDTO>> promise = client.rangeFormatting(params);
    handleFormatting(promise, document);
}
Also used : TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) List(java.util.List) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO) DocumentRangeFormattingParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO)

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