use of org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO 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.PositionDTO in project che by eclipse.
the class DtoBuildHelper method createTDPP.
public TextDocumentPositionParamsDTO createTDPP(Document document, TextPosition position) {
TextDocumentPositionParamsDTO paramsDTO = dtoFactory.createDto(TextDocumentPositionParamsDTO.class);
TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
identifierDTO.setUri(document.getFile().getLocation().toString());
PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
positionDTO.setCharacter(position.getCharacter());
positionDTO.setLine(position.getLine());
paramsDTO.setUri(document.getFile().getLocation().toString());
paramsDTO.setTextDocument(identifierDTO);
paramsDTO.setPosition(positionDTO);
return paramsDTO;
}
use of org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO 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);
}
use of org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO 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;
}
use of org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO in project che by eclipse.
the class FindReferencesAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
//TODO replace this
if (!(activeEditor instanceof TextEditor)) {
return;
}
TextEditor textEditor = ((TextEditor) activeEditor);
String path = activeEditor.getEditorInput().getFile().getLocation().toString();
ReferenceParamsDTO paramsDTO = dtoFactory.createDto(ReferenceParamsDTO.class);
PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
positionDTO.setLine(textEditor.getCursorPosition().getLine());
positionDTO.setCharacter(textEditor.getCursorPosition().getCharacter());
TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
identifierDTO.setUri(path);
ReferenceContextDTO contextDTO = dtoFactory.createDto(ReferenceContextDTO.class);
contextDTO.setIncludeDeclaration(true);
paramsDTO.setUri(path);
paramsDTO.setPosition(positionDTO);
paramsDTO.setTextDocument(identifierDTO);
paramsDTO.setContext(contextDTO);
Promise<List<LocationDTO>> promise = client.references(paramsDTO);
presenter.openLocation(promise);
}
Aggregations