use of org.eclipse.che.ide.api.editor.document.Document 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.ide.api.editor.document.Document in project che by eclipse.
the class FullTextDocumentSynchronize method syncTextDocument.
@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
Document document = event.getDocument().getDocument();
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);
TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
actualChange.setText(event.getDocument().getDocument().getContents());
changeDTO.setContentChanges(Collections.singletonList(actualChange));
textDocumentService.didChange(changeDTO);
}
use of org.eclipse.che.ide.api.editor.document.Document 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.ide.api.editor.document.Document in project che by eclipse.
the class BasicActiveFileHandler method scrollToLine.
protected void scrollToLine(EditorPartPresenter editor, int lineNumber) {
if (editor instanceof TextEditor) {
TextEditor textEditor = (TextEditor) editor;
Document document = textEditor.getDocument();
if (document != null) {
TextPosition newPosition = new TextPosition(lineNumber, 0);
document.setCursorPosition(newPosition);
}
}
}
use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.
the class TestResultViewImpl method gotoClass.
@Override
public void gotoClass(String packagePath, int line) {
lastWentLine = line;
final Project project = appContext.getRootProject();
String testSrcPath = project.getPath() + "/" + DEFAULT_TEST_SOURCE_FOLDER;
appContext.getWorkspaceRoot().getFile(testSrcPath + packagePath).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
Timer t = new Timer() {
@Override
public void run() {
EditorPartPresenter editorPart = editorAgent.getActiveEditor();
Document doc = ((TextEditor) editorPart).getDocument();
doc.setCursorPosition(new TextPosition(lastWentLine - 1, 0));
}
};
t.schedule(500);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
Log.info(TestResultViewImpl.class, error);
}
});
}
Aggregations