]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Improved logic to find imports/includes in SCLTextEditorEnvironement 98/2798/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Thu, 21 Mar 2019 13:02:02 +0000 (15:02 +0200)
committerJussi Koskela <jussi.koskela@semantum.fi>
Thu, 21 Mar 2019 13:02:02 +0000 (15:02 +0200)
gitlab #268

Change-Id: I2030ed897474264b5c7e191b0f14a6cd769cd6e8

bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java

index ffe709f45b768a9ff6c3cd5172b783fd349b5fa9..92133fd5a1b240a5bcc29dca765d6630bb78f7c2 100644 (file)
@@ -45,12 +45,17 @@ public class SCLTextEditorEnvironment {
     
     public void updateEnvironment(IDocument document) {
         String contents = document.get();
+        // Strip triple quoted strings from the contents since they may contain lines that look exactly like normal imports / includes
+        contents = contents.replaceAll("(?s)\"\"\".*?\"\"\"", "\"\"");
+        // Strip multiline comments since they may contain lines that look exactly like normal imports / includes
+        contents = contents.replaceAll("(?s)/\\*.*?\\*/", "");
+
         String[] lines = contents.split("\\R+"); //$NON-NLS-1$
         List<ImportDeclaration> imports = new ArrayList<>();
         imports.add(new ImportDeclaration("StandardLibrary", "")); //$NON-NLS-1$ //$NON-NLS-2$
         for (String line : lines) {
             line = line.trim();
-            if (line.startsWith("import") || line.startsWith("include")) { //$NON-NLS-1$ //$NON-NLS-2$
+            if (line.startsWith("import ") || line.startsWith("include ")) { //$NON-NLS-1$ //$NON-NLS-2$
                 SCLParserImpl parser = new SCLParserImpl(new StringReader(line));
                 try {
                     ImportDeclaration importDecl = (ImportDeclaration)parser.parseImport();