From: Jussi Koskela Date: Thu, 21 Mar 2019 13:02:02 +0000 (+0200) Subject: Improved logic to find imports/includes in SCLTextEditorEnvironement X-Git-Tag: v1.43.0~136^2~168^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F98%2F2798%2F1;p=simantics%2Fplatform.git Improved logic to find imports/includes in SCLTextEditorEnvironement gitlab #268 Change-Id: I2030ed897474264b5c7e191b0f14a6cd769cd6e8 --- diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java index ffe709f45..92133fd5a 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java @@ -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 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();