use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class GutterAnnotationRenderer method removeAnnotationItem.
private void removeAnnotationItem(final AnnotationModelEvent event, final Annotation annotation) {
final Position position = event.getPositionOfRemovedAnnotation(annotation);
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final Element annotationItem = this.hasGutter.getGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
if (AnnotationGroupImpl.isAnnotation(annotationItem)) {
final AnnotationGroup group = AnnotationGroupImpl.create(annotationItem);
group.removeAnnotation(annotation, position.getOffset());
if (group.getAnnotationCount() != 0) {
return;
}
}
// else
this.hasGutter.removeGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
}
use of org.eclipse.che.ide.api.editor.text.Position 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.text.Position in project che by eclipse.
the class OrionEditorWidget method showErrors.
public void showErrors(AnnotationModelEvent event) {
List<Annotation> addedAnnotations = event.getAddedAnnotations();
JsArray<OrionProblemOverlay> jsArray = JsArray.createArray().cast();
AnnotationModel annotationModel = event.getAnnotationModel();
OrionAnnotationSeverityProvider severityProvider = null;
if (annotationModel instanceof OrionAnnotationSeverityProvider) {
severityProvider = (OrionAnnotationSeverityProvider) annotationModel;
}
for (Annotation annotation : addedAnnotations) {
Position position = annotationModel.getPosition(annotation);
OrionProblemOverlay problem = JavaScriptObject.createObject().cast();
problem.setDescription(annotation.getText());
problem.setStart(position.getOffset());
problem.setEnd(position.getOffset() + position.getLength());
problem.setId("che-annotation");
problem.setSeverity(getSeverity(annotation.getType(), severityProvider));
jsArray.push(problem);
}
editorOverlay.showProblems(jsArray);
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class OrionCursorModel method getCursorPosition.
@Override
public Position getCursorPosition() {
TextPosition position = document.getCursorPosition();
int offset = document.getIndexFromPosition(position);
return new Position(offset);
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class LanguageServerAnnotationModel method reportDiagnostic.
private void reportDiagnostic() {
boolean temporaryProblemsChanged = false;
if (!generatedAnnotations.isEmpty()) {
temporaryProblemsChanged = true;
super.clear();
generatedAnnotations.clear();
}
if (diagnostics != null && !diagnostics.isEmpty()) {
for (final DiagnosticDTO diagnostic : diagnostics) {
final Position position = createPositionFromDiagnostic(diagnostic);
if (position != null) {
final DiagnosticAnnotation annotation = new DiagnosticAnnotation(diagnostic);
addAnnotation(annotation, position, false);
generatedAnnotations.add(annotation);
temporaryProblemsChanged = true;
}
}
}
if (temporaryProblemsChanged) {
fireModelChanged();
}
}
Aggregations