summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2009-03-24 16:12:52 (EDT)
committer sefftinge2009-03-24 16:12:52 (EDT)
commit41f52886bb7e489ee92d0967b11bd1cc7ac86501 (patch)
tree260b04b315f8a520ecb49fc8bb7034b512001e2b
parent3c6213482700602c61319e74e07bb32260162caf (diff)
downloadorg.eclipse.xtext-41f52886bb7e489ee92d0967b11bd1cc7ac86501.zip
org.eclipse.xtext-41f52886bb7e489ee92d0967b11bd1cc7ac86501.tar.gz
org.eclipse.xtext-41f52886bb7e489ee92d0967b11bd1cc7ac86501.tar.bz2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=269649
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java24
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java71
2 files changed, 84 insertions, 11 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
index d032b5b..b3aae9f 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessor.java
@@ -7,6 +7,9 @@
*******************************************************************************/
package org.eclipse.xtext.ui.common.editor.contentassist.impl;
+import static java.lang.Math.max;
+import static org.eclipse.xtext.parsetree.ParseTreeUtil.getCurrentOrFollowingNodeByOffset;
+import static org.eclipse.xtext.parsetree.ParseTreeUtil.getLastCompleteNodeByOffset;
import static org.eclipse.xtext.util.CollectionUtils.addAllIfNotNull;
import static org.eclipse.xtext.util.CollectionUtils.addIfNotNull;
@@ -37,7 +40,6 @@ import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
-import org.eclipse.xtext.parsetree.ParseTreeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.common.editor.contentassist.IContentAssistCalculator;
import org.eclipse.xtext.ui.common.editor.contentassist.IContentAssistContext;
@@ -191,22 +193,26 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
IParseResult parseResult = resource.getParseResult();
Assert.isNotNull(parseResult);
CompositeNode rootNode = parseResult.getRootNode();
- AbstractNode referenceNode = ParseTreeUtil.getLastCompleteNodeByOffset(rootNode, offset);
- AbstractNode nodeAtOffset = ParseTreeUtil.getCurrentOrFollowingNodeByOffset(rootNode, offset);
+ AbstractNode referenceNode = getLastCompleteNodeByOffset(rootNode, offset);
+ AbstractNode nodeAtOffset = getCurrentOrFollowingNodeByOffset(rootNode, offset);
if (referenceNode.getOffset()+referenceNode.getLength() == offset) {
- AbstractNode precedingReferenceNode = ParseTreeUtil.getLastCompleteNodeByOffset(rootNode,Math.max(0, referenceNode.getOffset()));
+ AbstractNode precedingReferenceNode = getLastCompleteNodeByOffset(rootNode,max(0, referenceNode.getOffset()));
String matchingString = computeMatchString(referenceNode);
- result.add(newCompletionProposal(matchingString, offset, rootNode, precedingReferenceNode));
+ result.add(newContentAssistContext(matchingString, offset, rootNode, precedingReferenceNode));
if (referenceNode.getGrammarElement() instanceof Keyword ||
referenceNode.getGrammarElement() instanceof CrossReference ||
(referenceNode.getGrammarElement() instanceof RuleCall &&
((RuleCall)referenceNode.getGrammarElement()).getRule() instanceof TerminalRule)) {
- result.add(newCompletionProposal("", offset, rootNode, referenceNode));
+ result.add(newContentAssistContext("", offset, rootNode, referenceNode));
}
+ } else if (referenceNode == nodeAtOffset) {
+ AbstractNode precedingReferenceNode = getLastCompleteNodeByOffset(rootNode,max(0, referenceNode.getOffset()));
+ String matchingString = calculateMatchString(nodeAtOffset,text, offset);
+ result.add(newContentAssistContext(matchingString, offset, rootNode, precedingReferenceNode));
} else {
String matchingString = calculateMatchString(nodeAtOffset,text, offset);
- result.add(newCompletionProposal(matchingString, offset, rootNode, referenceNode));
+ result.add(newContentAssistContext(matchingString, offset, rootNode, referenceNode));
}
return result;
@@ -259,10 +265,10 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
return matchString.toString();
}
- private ContentAssistContext newCompletionProposal(String matchingString, final int offset, CompositeNode rootNode,
+ private ContentAssistContext newContentAssistContext(String matchingString, final int offset, CompositeNode rootNode,
AbstractNode referenceNode) {
EObject model = NodeUtil.getNearestSemanticObject(referenceNode);
- AbstractNode node = ParseTreeUtil.getCurrentOrFollowingNodeByOffset(rootNode, offset);
+ AbstractNode node = getCurrentOrFollowingNodeByOffset(rootNode, offset);
return new ContentAssistContext(model, offset, matchingString, node, referenceNode, rootNode);
}
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
index 867f48b..6110543 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
@@ -248,7 +248,11 @@ public class DefaultContentAssistProcessorTest extends AbstractXtextTests {
.appendNl("")
.appendNl("MyRule : 'foo' name=ID; ")
.assertTextAtCursorPosition("MyRule",
- "ParserRule_Name", "terminal");
+ "ParserRule_Name",
+ "terminal",
+ "as",
+ "generate",
+ "import");
}
public void testCompleteParserRule_03() throws Exception {
@@ -258,7 +262,11 @@ public class DefaultContentAssistProcessorTest extends AbstractXtextTests {
.appendNl("")
.appendNl(" MyRule : 'foo' name=ID; ")
.assertTextAtCursorPosition(" MyRule",
- "ParserRule_Name", "terminal");
+ "ParserRule_Name",
+ "terminal",
+ "as",
+ "generate",
+ "import");
}
public void _testCompleteGenerateKeyword() throws Exception {
@@ -271,6 +279,65 @@ public class DefaultContentAssistProcessorTest extends AbstractXtextTests {
"generate");
}
+ public void testCompleteImportAndGenerateRule() throws Exception {
+ newBuilder(getXtextGrammarSetup())
+ .appendNl("grammar foo")
+ .appendNl("generate foo \"foo\"")
+ .appendNl("")
+ .appendNl("R1 : (attr+=R2)*;")
+ .appendNl("R2 : (attr=INT)? prop=R3;")
+ .assertTextAtCursorPosition("R1",
+ "ParserRule_Name",
+ "as",
+ "generate",
+ "import",
+ "terminal"
+ );
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=269593
+ */
+ public void testCompleteRuleCallWithSpace() throws Exception {
+ newBuilder(getXtextGrammarSetup())
+ .appendNl("grammar foo")
+ .appendNl("generate foo \"foo\"")
+ .appendNl("R1 : (attr+=R2)*;")
+ .appendNl("R2 : (attr=INT)? prop=R3;")
+ .append("R3: attr+= ").assertText(
+ "R1",
+ "R2",
+ "R3",
+ "\"Keyword_Value\"",
+ "(",
+ "["
+ );
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=269593
+ */
+ public void testCompleteAbstractRuleCallWithSpace() throws Exception {
+ newBuilder(getContentAssistGrammarSetup())
+ .appendNl("abstract rules")
+ .appendNl("R1 ();")
+ .append("R2 rule : ").assertText(
+ "R1",
+ "R2"
+ );
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=269649
+ */
+ public void testCompletionOnGenerateKeyword() throws Exception {
+ newBuilder(getXtextGrammarSetup())
+ .appendNl("grammar foo with org.eclipse.xtext.common.Terminals")
+ .appendNl("generate meta \"url\"")
+ .appendNl("Rule: name=ID;")
+ .assertTextAtCursorPosition("generate", 3,"generate");
+ }
+
/**
* regression test for:
*