|
From: <caw...@us...> - 2007-07-10 14:55:50
|
Revision: 2734
http://svn.sourceforge.net/rubyeclipse/?rev=2734&view=rev
Author: cawilliams
Date: 2007-07-10 07:55:48 -0700 (Tue, 10 Jul 2007)
Log Message:
-----------
move all code for getting root node into Completion Context. Make it smater, so it will cache the root node, and also so it will try to auto fix or drop back the the last good AST
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-07-09 21:39:14 UTC (rev 2733)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionContext.java 2007-07-10 14:55:48 UTC (rev 2734)
@@ -7,6 +7,7 @@
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.RubyScript;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.ti.util.ClosestSpanningNodeLocator;
import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
@@ -20,6 +21,7 @@
private String fullPrefix;
private int replaceStart;
private boolean isAfterDoubleSemiColon = false;
+ private Node fRootNode;
public CompletionContext(IRubyScript script, int offset) throws RubyModelException {
this.script = script;
@@ -207,7 +209,26 @@
}
Node getRootNode() {
- return ((RubyScript) getScript()).lastGoodAST;
+ if (fRootNode != null) return fRootNode;
+ RubyParser parser = new RubyParser();
+ if (!isBroken()) {
+ try {
+ fRootNode = parser.parse(getSource());
+ } catch (RuntimeException e) {
+ // ignore
+ }
+ }
+ if (fRootNode == null) {
+ try {
+ fRootNode = parser.parse(getCorrectedSource());
+ } catch (RuntimeException e) {
+ // ignore
+ }
+ }
+ if (fRootNode == null) {
+ fRootNode = ((RubyScript) getScript()).lastGoodAST;
+ }
+ return fRootNode;
}
}
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-07-09 21:39:14 UTC (rev 2733)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-07-10 14:55:48 UTC (rev 2734)
@@ -128,7 +128,7 @@
for (ITypeGuess guess : guesses) {
final String name = guess.getType();
if (fContext.isBroken()) {
- Node rootNode = new RubyParser().parse(fContext.getCorrectedSource());
+ Node rootNode = fContext.getRootNode();
List<Node> typeNodes = ScopedNodeLocator.Instance().findNodesInScope(rootNode, new INodeAcceptor() {
public boolean doesAccept(Node node) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|