aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-04-28 05:49:07 (EDT)
committersefftinge2009-04-28 05:49:07 (EDT)
commitc25ec25ad773992fe78b08b00edab3058b333bbe (patch)
tree324dc495d9aa15504673ce212ae3d5357a1231ce
parent4b984c5a3975818cf0d04c188fbdffd1865ec240 (diff)
downloadorg.eclipse.xtext-c25ec25ad773992fe78b08b00edab3058b333bbe.zip
org.eclipse.xtext-c25ec25ad773992fe78b08b00edab3058b333bbe.tar.gz
org.eclipse.xtext-c25ec25ad773992fe78b08b00edab3058b333bbe.tar.bz2
Fix: CA for cases, where prefix matches a keyword
-rwxr-xr-xplugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/DefaultContentAssistContextFactory.java7
-rwxr-xr-xtests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractContentAssistProcessorTest.java33
2 files changed, 31 insertions, 9 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/DefaultContentAssistContextFactory.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/DefaultContentAssistContextFactory.java
index b554d4a..7593172 100755
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/DefaultContentAssistContextFactory.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/DefaultContentAssistContextFactory.java
@@ -73,10 +73,11 @@ public class DefaultContentAssistContextFactory implements ContentAssistContext.
String prefix = getPrefix(lastCompleteNode, fixedOffset);
result.add(createContext(viewer, fixedOffset, parseResult, rootNode, precedingLastCompleteNode, currentModel, lastCompleteNode, prefix));
- if (lastCompleteNode.getGrammarElement() instanceof Keyword ||
- lastCompleteNode.getGrammarElement() instanceof CrossReference ||
+ if (lastCompleteNode.getGrammarElement() != null &&
+ (lastCompleteNode.getGrammarElement() instanceof Keyword ||
+ lastCompleteNode.getGrammarElement() instanceof CrossReference ||
(lastCompleteNode.getGrammarElement() instanceof RuleCall &&
- ((RuleCall)lastCompleteNode.getGrammarElement()).getRule() instanceof TerminalRule)) {
+ ((RuleCall)lastCompleteNode.getGrammarElement()).getRule() instanceof TerminalRule))) {
result.add(createContext(viewer, fixedOffset, parseResult, rootNode, lastCompleteNode, currentModel, currentNode, ""));
}
} else if (lastCompleteNode == currentNode) {
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractContentAssistProcessorTest.java
index 47dbd20..1aede24 100755
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractContentAssistProcessorTest.java
@@ -1,10 +1,4 @@
/*******************************************************************************
- * __ ___ _
- * \ \/ / |_ _____ __ |_
- * \ /| __/ _ \ \/ / __|
- * / \| |_ __/> <| |_
- * /_/\_\\__\___/_/\_\\__|
- *
* Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -313,6 +307,33 @@ public abstract class AbstractContentAssistProcessorTest extends AbstractXtextTe
.appendNl("Rule: name=ID;")
.assertTextAtCursorPosition("org.eclipse.xtext", 5, "org.eclipse.xtext.common.Terminals");
}
+
+ public void testCompletionOnSyntaxError_01() throws Exception {
+ newBuilder(setup.getXtextSetup())
+ .appendNl("grammar foo with org.eclipse.xtext.common.Terminals")
+ .appendNl("generate foo 'bar'")
+ .appendNl("grammarA: child=Rule;")
+ .appendNl("Rule: call=grammar")
+ .assertTextAtCursorPosition("=grammar", "=grammar".length(), "grammarA");
+ }
+
+ public void testCompletionOnSyntaxError_02() throws Exception {
+ newBuilder(setup.getXtextSetup())
+ .appendNl("grammar foo with org.eclipse.xtext.common.Terminals")
+ .appendNl("generate foo 'bar'")
+ .appendNl("grammarA: child=Rule;")
+ .append("Rule: call=grammar")
+ .assertText("grammarA");
+ }
+
+ public void testCompletionOnSyntaxError_03() throws Exception {
+ newBuilder(setup.getXtextSetup())
+ .appendNl("grammar foo with org.eclipse.xtext.common.Terminals")
+ .appendNl("generate foo 'bar'")
+ .appendNl("grammarA: child=Rule;")
+ .appendNl("Rule: call=grammar;")
+ .assertTextAtCursorPosition("grammar;", "grammar".length(), "grammarA");
+ }
/**
* regression test for: