Search in sources :

Example 16 with Position

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);
}
Also used : 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) Element(elemental.dom.Element)

Example 17 with Position

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);
}
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 18 with Position

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);
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) OrionProblemOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionProblemOverlay) AnnotationModel(org.eclipse.che.ide.api.editor.annotation.AnnotationModel) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 19 with Position

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);
}
Also used : 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)

Example 20 with Position

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();
    }
}
Also used : DiagnosticDTO(org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position)

Aggregations

Position (org.eclipse.che.ide.api.editor.text.Position)36 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)14 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)14 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)8 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)7 ArrayList (java.util.ArrayList)6 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)3 Element (elemental.dom.Element)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 DiagnosticDTO (org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 EditorWithAutoSave (org.eclipse.che.ide.api.editor.EditorWithAutoSave)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1