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);
}
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);
}
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())));
}
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;
}
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);
}
Aggregations