]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7386) Minor SCL tools improvements 68/768/3
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 26 Jul 2017 11:10:42 +0000 (14:10 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 26 Jul 2017 11:42:43 +0000 (14:42 +0300)
* A new error type for failed imports that are shown only after other
errors and have their own icon
* Definition location for data type constructors
* Improved content assist for nested namespaces

Change-Id: Ie2a32f755a2487d8d969bb10c927b39e4d304165

bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java
bundles/org.simantics.scl.ui/icons/import_error.png [new file with mode: 0644]
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionProposal.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java

index 53b601fa2820ea91c640a42d643daff539ca343d..e5ae639355b1087ff16aa48fdfe095a99f408ad7 100644 (file)
@@ -13,6 +13,7 @@ import org.simantics.db.request.Read;
 import org.simantics.scl.compiler.environment.LocalEnvironment;
 import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
 import org.simantics.scl.compiler.errors.CompilationError;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.module.repository.ImportFailure;
 import org.simantics.scl.compiler.module.repository.ImportFailureException;
 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
@@ -47,7 +48,7 @@ public class ComponentTypeScriptRequest implements Read<ComponentTypeScriptResul
                 // at the very start of the editor
                 List<CompilationError> errors = new ArrayList<CompilationError>();
                 for (ImportFailure failure : cause.failures) {
-                    errors.add(new CompilationError(0, failure.toString()));
+                    errors.add(new CompilationError(0, failure.toString(), ErrorSeverity.IMPORT_ERROR));
                 }
                 return new ComponentTypeScriptResult(errors, null);
             }
index fccf2681507466ef7f4c9b6f44dc6aab04f76b04..ff5ee3b2902fa0384258f246776d534dbed0d617 100644 (file)
@@ -61,7 +61,9 @@ import org.simantics.scl.compiler.environment.AmbiguousNameException;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.environment.EnvironmentFactory;
 import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
 import org.simantics.scl.compiler.internal.codegen.effects.ThreadLocalVariable;
@@ -179,7 +181,7 @@ public class Elaboration {
             compilationContext.environment = new EnvironmentOfModule(importedEnvironment, module);
         } catch (ImportFailureException e) {
             for(ImportFailure failure : e.failures)
-                errorLog.log(failure.location, failure.toString());
+                errorLog.log(new CompilationError(failure.location, failure.toString(), ErrorSeverity.IMPORT_ERROR));
             return;
         }
         for(ImportDeclaration importAst : importsAst)
@@ -1113,6 +1115,7 @@ public class Elaboration {
             int constructorTag = 0;
             for(Constructor constructor : dataType.constructors) {
                 SCLValue value = new SCLValue(constructor.name);
+                value.definitionLocation = constructor.loc;
                 SCLConstructor sclConstructor = 
                         new SCLConstructor(
                                 constructor.name.name,
index 3be214d2d6bd69f66aa4ae59347adeba2b5cb572..2ce0ced5bd5e46438a93a54b3c7651fab130cba9 100644 (file)
@@ -241,6 +241,8 @@ public class Environments {
             Namespace childNamespace = namespace.getNamespace(prefix.substring(0, p));
             if(childNamespace != null)
                 findValuesForPrefix(childNamespace, prefix.substring(p+1), proc);
+            else
+                namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
         }
         else
             namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
index 62d5d8c3de021defc1648d90c15f8ad55998440d..0e61a1644ef961bd99b9ae4a770eda46ffadf87e 100644 (file)
@@ -16,7 +16,7 @@ public class ErrorLog {
     
     public void log(CompilationError error) {
         errors.add(error);
-        if(error.severity == ErrorSeverity.ERROR)
+        if(error.severity != ErrorSeverity.WARNING)
                ++errorCount;
     }
     
index 9f65cb3e8662c739d36db66ba175fe8a6c511f58..101e0f9e5cdb04bbcd26f21aea7f3e9a3e33cb02 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.errors;
 
 public enum ErrorSeverity {
-       ERROR,
-       WARNING
+    ERROR,
+    IMPORT_ERROR,
+    WARNING
 }
diff --git a/bundles/org.simantics.scl.ui/icons/import_error.png b/bundles/org.simantics.scl.ui/icons/import_error.png
new file mode 100644 (file)
index 0000000..caa1838
Binary files /dev/null and b/bundles/org.simantics.scl.ui/icons/import_error.png differ
index a408e7f30ae3b745fd72ad7f3bd476933cb4ba67..768682fa3ef8a056f0b1fc73e7765a1e1390d034 100644 (file)
@@ -33,6 +33,7 @@ public class Activator extends AbstractUIPlugin {
         reg.put("find", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/find.png") );
         reg.put("disk", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/disk.png") );
         reg.put("error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/error.png") );
+        reg.put("import_error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/import_error.png") );
         reg.put("warning", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/warning.png") );
     }
     
index 4c429e7fdda6ced8d40a94b7f77a9467d42f7aa6..11749a4b2b24eef1c717eec74e9129731da58ce6 100644 (file)
@@ -37,8 +37,15 @@ public class SCLCompletionProposal implements ICompletionProposal, ICompletionPr
     private final SCLCompletionType completionType;
     
     public SCLCompletionProposal(SCLValue value, int replacementOffset, String prefix) {
-        this.name = value.getName().name;
-        this.module = value.getName().module;
+        String tempName = value.getName().name;
+        String tempModule = value.getName().module;
+        int p = tempName.lastIndexOf('.');
+        if(p >= 0) {
+            tempModule = tempModule + "." + tempName.substring(0, p);
+            tempName = tempName.substring(p+1);
+        }
+        this.name = tempName;
+        this.module = tempModule;
         this.documentation = value.getDocumentation();
         this.content = name + " :: " + value.getType() + "  (" + module + ")";
         this.replacementOffset = replacementOffset;
index 4b6818ab7b805587bfe6306a9f1154e48ac0e3ad..378840397759e1fbdbdc3714b2c3c930c01fa32b 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PlatformUI;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.module.InvalidModulePathException;
 import org.simantics.scl.compiler.module.ModuleUtils;
 import org.simantics.scl.compiler.source.ModuleSource;
@@ -106,6 +107,7 @@ public class OpenDeclaration extends AbstractHandler {
             SCLTextEditorEnvironment editorEnvironment = moduleEditor.getSCLTextEditorEnvironment();
             editorEnvironment.updateEnvironment(moduleEditor.getDocument());
             SCLValue value = editorEnvironment.getValue(identifierAtCaret);
+            System.out.println("identifierAtCaret = " + identifierAtCaret + " [" + Locations.beginOf(value.definitionLocation) + ", " + Locations.endOf(value.definitionLocation) + "]");
             if(value != null)
                 OpenSCLDefinition.openDefinition(value);
         }
index b4fd1edd8a1c8fdad594ff86e6a6b610f8b5abcb..3e0cc3120bd8c163c62158b4e5f0661ef8e0d74f 100644 (file)
@@ -90,6 +90,8 @@ public class SCLIssuesView extends ViewPart {
                 SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element;
                 return entry.error.severity == ErrorSeverity.ERROR
                         ? imageRegistry.get("error")
+                        : entry.error.severity == ErrorSeverity.IMPORT_ERROR
+                        ? imageRegistry.get("import_error")
                         : imageRegistry.get("warning");
             }
         });