|
From: <caw...@us...> - 2006-10-18 00:54:17
|
Revision: 1622
http://svn.sourceforge.net/rubyeclipse/?rev=1622&view=rev
Author: cawilliams
Date: 2006-10-17 17:54:14 -0700 (Tue, 17 Oct 2006)
Log Message:
-----------
don't suggest types or variables when we're sure it's a method we're trying to complete, don't suggest methods that don't begin with the prefix user has typed.
Modified Paths:
--------------
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/CompletionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2006-10-13 07:16:27 UTC (rev 1621)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2006-10-18 00:54:14 UTC (rev 1622)
@@ -48,12 +48,14 @@
public class CompletionEngine {
private CompletionRequestor requestor;
+ private String prefix;
public CompletionEngine(CompletionRequestor requestor) {
this.requestor = requestor;
}
public void complete(IRubyScript script, int offset) throws RubyModelException {
+ this.prefix = null;
this.requestor.beginReporting();
if (offset < 0)
offset = 0;
@@ -66,9 +68,12 @@
// inferrer
// if we hit a space, use character after space?
// TODO We need to handle other bad syntax like invoking compeltion right after an @
+ StringBuffer prefix = new StringBuffer();
+ boolean isMethod = false;
for (int i = offset; i >= 0; i--) {
char curChar = (char) source.charAt(i);
if (curChar == '.') {
+ isMethod = true;
if (offset == i) { // if it's the first character we looked at,
// fix syntax
source.deleteCharAt(i);
@@ -76,7 +81,7 @@
break;
}
// TODO Grab the prefix we just ate up and use it to filter
- // responses?
+ // responses?
offset = i - 1;
break;
}
@@ -84,8 +89,10 @@
offset = i + 1;
break;
}
- }
-
+ prefix.insert(0, curChar);
+ }
+ this.prefix = prefix.toString();
+
List<ITypeGuess> guesses = inferrer.infer(source.toString(), offset);
// TODO Grab the project and all referred projects!
IRubyProject[] projects = new IRubyProject[1];
@@ -97,7 +104,7 @@
suggestMethods(replaceStart, completer, guess, type);
}
// FIXME Do we need to call this at all if we know it's a method call we're trying to complete?
- getDocumentsRubyElementsInScope(script, source.toString(), offset, replaceStart);
+ if (!isMethod) getDocumentsRubyElementsInScope(script, source.toString(), offset, replaceStart);
this.requestor.endReporting();
}
@@ -131,6 +138,11 @@
for (int k = 0; k < methods.length; k++) {
IMethod method = methods[k];
String name = method.getElementName();
+
+ if (prefix != null && prefix.length() != 0) {
+ // If we have a prefix, then don't suggest non-matches
+ if (!name.startsWith(prefix)) continue;
+ }
CompletionProposal proposal = new CompletionProposal(
CompletionProposal.METHOD_REF, name, confidence);
// TODO Handle replacement start index correctly
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|