|
From: <caw...@us...> - 2007-06-12 18:56:47
|
Revision: 2609
http://svn.sourceforge.net/rubyeclipse/?rev=2609&view=rev
Author: cawilliams
Date: 2007-06-12 11:56:45 -0700 (Tue, 12 Jun 2007)
Log Message:
-----------
when syntax is broken and we're trying to complete a method call, we fall back to parsing corrected source and traversing nodes for method suggestions if there's a matching type in the file (in addition to asking the RubyElementRequestor to find the type).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionContext.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionContext.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionContext.java 2007-06-12 16:32:02 UTC (rev 2608)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionContext.java 2007-06-12 18:56:45 UTC (rev 2609)
@@ -112,6 +112,14 @@
return correctedSource;
}
+ public boolean isBroken() {
+ try {
+ return !getCorrectedSource().equals(script.getSource());
+ } catch (RubyModelException e) {
+ return true;
+ }
+ }
+
public boolean hasReceiver() {
return getFullPrefix().indexOf('.') > 1;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-06-12 16:32:02 UTC (rev 2608)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-06-12 18:56:45 UTC (rev 2609)
@@ -93,7 +93,7 @@
for (int i = 0; i < types.length; i++) {
IType type = types[i];
suggestTypesConstants(type);
-// Suggest nested types
+ // Suggest nested types
suggestNestedTypes(type);
// Suggest class level methods
Map<String, CompletionProposal> map = suggestMethods(100, type, false);
@@ -120,8 +120,35 @@
List<CompletionProposal> list = new ArrayList<CompletionProposal>();
RubyElementRequestor requestor = new RubyElementRequestor(script);
for (ITypeGuess guess : guesses) {
- String name = guess.getType();
- IType[] types = requestor.findType(name); // FIXME When syntax is broken, grabbing type that is defined in same script like this just doesn't work!
+ final String name = guess.getType();
+ if (fContext.isBroken()) {
+ Node rootNode = new RubyParser().parse(fContext.getCorrectedSource());
+ List<Node> typeNodes = ScopedNodeLocator.Instance().findNodesInScope(rootNode, new INodeAcceptor() {
+
+ public boolean doesAccept(Node node) {
+ if ((node instanceof ClassNode) || (node instanceof ModuleNode)) {
+ return ASTUtil.getNameReflectively(node).equals(name);
+ }
+ return false;
+ }
+
+ });
+ for (Node typeNode : typeNodes) {
+ List<Node> methods = ScopedNodeLocator.Instance().findNodesInScope(typeNode, new INodeAcceptor() {
+
+ public boolean doesAccept(Node node) {
+ return (node instanceof DefnNode) || (node instanceof DefsNode);
+ }
+
+ });
+ for (Node methodNode : methods) {
+ MethodDefNode methodDef = (MethodDefNode) methodNode;
+ NodeMethod method = new NodeMethod(methodDef);
+ list.add(suggestMethod(method, name, 100));
+ }
+ }
+ }
+ IType[] types = requestor.findType(name);
for (int i = 0; i < types.length; i++) {
Map<String, CompletionProposal> map = suggestMethods(guess.getConfidence(), types[i], true);
list.addAll(map.values());
@@ -178,6 +205,7 @@
private List<CompletionProposal> suggestAllMethodsMatchingPrefix(IRubyScript script) {
List< CompletionProposal> list = new ArrayList<CompletionProposal>();
+ if (fContext.getPartialPrefix() == null || fContext.getPartialPrefix().trim().length() == 0) return list;
IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {script.getRubyProject()});
SearchParticipant participant = BasicSearchEngine.getDefaultSearchParticipant();
CollectingSearchRequestor searchRequestor = new CollectingSearchRequestor();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|