From 38cd6e562efe2e5a8752924ebc5213e68b352f09 Mon Sep 17 00:00:00 2001 From: Jussi Koskela Date: Thu, 21 Mar 2019 15:02:02 +0200 Subject: [PATCH] Improved logic to find imports/includes in SCLTextEditorEnvironement gitlab #268 Change-Id: I2030ed897474264b5c7e191b0f14a6cd769cd6e8 --- .../scl/ui/editor/completion/SCLTextEditorEnvironment.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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(); -- 2.47.1