From 84b211a0aa05c956d33e038a1106bb0464ce373a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 26 Jul 2017 14:10:42 +0300 Subject: [PATCH] (refs #7386) Minor SCL tools improvements * 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 --- .../modeling/ComponentTypeScriptRequest.java | 3 ++- .../scl/compiler/compilation/Elaboration.java | 5 ++++- .../scl/compiler/environment/Environments.java | 2 ++ .../simantics/scl/compiler/errors/ErrorLog.java | 2 +- .../scl/compiler/errors/ErrorSeverity.java | 5 +++-- .../org.simantics.scl.ui/icons/import_error.png | Bin 0 -> 734 bytes .../src/org/simantics/scl/ui/Activator.java | 1 + .../editor/completion/SCLCompletionProposal.java | 11 +++++++++-- .../simantics/scl/ui/editor2/OpenDeclaration.java | 2 ++ .../simantics/scl/ui/issues/SCLIssuesView.java | 2 ++ 10 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 bundles/org.simantics.scl.ui/icons/import_error.png diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java index 53b601fa2..e5ae63935 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ComponentTypeScriptRequest.java @@ -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 errors = new ArrayList(); 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); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index fccf26815..ff5ee3b29 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -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, diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java index 3be214d2d..2ce0ced5b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java @@ -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); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java index 62d5d8c3d..0e61a1644 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java @@ -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; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java index 9f65cb3e8..101e0f9e5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java @@ -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 index 0000000000000000000000000000000000000000..caa1838d7f1deb211954f417f44196d131762a33 GIT binary patch literal 734 zcmV<40wMj0P)B81U&hml7ftTkzJn#82Ff)=N+_m4tia#>Z zED;~bI?|((@r+mjthjMa_A%$0tfL-QbPg*LnU_WAg~uA`bk8XfVKMue{f|q-zK6T5 z$+$@!kfN4#c5k}DXoQw#g?X#j%8Ke&msn`eT!P~gh zHx954K@vhr&4ZG+`hMNW>{NV8fvu^oY$D5Q1iV26C?>7a-M}^ zf+7V1!ylPMVQx91B8Cg`?xBTxqe=5WDy=kaC@M|QuY#QKhWa@G0EkNg#f0(jFm#fT zq(fIa<`(Bsvbh3LeZkN_`bKD^)UAxX(*OX?;)Z5%EeUj&Ln?`^^>#>7P)wMLOu%Z% z#{0>)_#PZZQ_%FyFws`rLW<6?B9I~^a*dRT3jsj_aVg-iIZ@^~jCT_~7#@6%x*tZE zq`GHV=^FpWu6ko=kNu#n>&wdlL2&yUSp1p7YT&3fgcO-= 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; diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java index 4b6818ab7..378840397 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java @@ -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); } diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java index b4fd1edd8..3e0cc3120 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java @@ -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"); } }); -- 2.47.1