]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLAnnotationModel.java
(refs #7284) Fixed SCLAnnotationModel to cope invalid error ranges
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / SCLAnnotationModel.java
index 47b203d613e1b871e8a3762f008c11906fb3298b..2a04c41cf1f1169721208c0eabce52ce58c31de2 100644 (file)
@@ -9,6 +9,8 @@ import org.eclipse.jface.text.Position;
 import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.AnnotationModel;
 import org.simantics.scl.compiler.errors.CompilationError;
+import org.simantics.scl.compiler.errors.DoesNotExist;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.errors.Failable;
 import org.simantics.scl.compiler.errors.Failure;
 import org.simantics.scl.compiler.errors.Locations;
@@ -41,19 +43,27 @@ public class SCLAnnotationModel extends AnnotationModel {
             Failure failure = (Failure)result;
             setAnnotations(Arrays.asList(failure.errors));
         }
-        else {
+        else if(result == DoesNotExist.INSTANCE)
             setAnnotations(Collections.<CompilationError>emptyList());
-        }
+        else
+            setAnnotations(Arrays.asList(result.getResult().getWarnings()));
     }
     
     protected void setAnnotations(List<CompilationError> errors) {
         synchronized(getLockObject()) {
             removeAllAnnotations();
             for(CompilationError error : errors) {
-                Annotation annotation = new Annotation("org.eclipse.ui.workbench.texteditor.error", true,
-                        error.description);
+                Annotation annotation = new Annotation(
+                        error.severity == ErrorSeverity.ERROR ?
+                                "org.eclipse.ui.workbench.texteditor.error" :
+                                    "org.eclipse.ui.workbench.texteditor.warning",
+                                    true, error.description);
                 int begin = Locations.beginOf(error.location);
                 int end = Locations.endOf(error.location);
+                if(begin < 0 || end < begin) {
+                    begin = 0;
+                    end = 1;
+                }
                 Position position = new Position(begin, end - begin);
                 addAnnotation(annotation, position);
             }
@@ -70,6 +80,7 @@ public class SCLAnnotationModel extends AnnotationModel {
     @Override
     public void disconnect(IDocument document) {
         connected = false;
+        updateListener.stopListening();
         super.disconnect(document);
     }
 }