|
From: <caw...@us...> - 2007-07-12 16:51:33
|
Revision: 2753
http://svn.sourceforge.net/rubyeclipse/?rev=2753&view=rev
Author: cawilliams
Date: 2007-07-12 08:26:00 -0700 (Thu, 12 Jul 2007)
Log Message:
-----------
filter out duplicate global completions, suggest globals on empty prefix completions, limit global search by forcing $ at front (for some reason it's picking up all fields otherwise).
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 2007-07-12 15:17:58 UTC (rev 2752)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-07-12 15:26:00 UTC (rev 2753)
@@ -90,6 +90,7 @@
if (fContext.emptyPrefix()) { // no prefix, so we could suggest anything
suggestMethodsForEnclosingType(script);
getDocumentsRubyElementsInScope();
+ suggestGlobals();
} else {
if (fContext.isDoubleSemiColon()) {
String prefix = fContext.getFullPrefix();
@@ -117,6 +118,10 @@
suggestConstantNames();
return;
}
+ if (fContext.isGlobal()) { // looks like a global
+ suggestGlobals();
+ return;
+ }
if (fContext.isExplicitMethodInvokation()) {
ITypeInferrer inferrer = new DefaultTypeInferrer();
List<ITypeGuess> guesses = inferrer.infer(fContext.getCorrectedSource(), fContext.getOffset());
@@ -162,9 +167,6 @@
}
getDocumentsRubyElementsInScope();
}
- if (fContext.isGlobal()) { // looks like a global
- suggestGlobals();
- }
}
this.fRequestor.endReporting();
fContext = null;
@@ -315,14 +317,15 @@
}
private void suggestGlobals() {
- SearchPattern pattern = SearchPattern.createPattern(IRubyElement.GLOBAL, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
+ SearchPattern pattern = SearchPattern.createPattern(IRubyElement.GLOBAL, "$*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {fContext.getScript().getRubyProject()});
List<SearchMatch> results = search(pattern, scope);
+ Set<String> names = new HashSet<String>();
for (SearchMatch match: results) {
IRubyElement element = (IRubyElement) match.getElement();
String name = element.getElementName();
- if (!fContext.prefixStartsWith(name))
- continue;
+ if (names.contains(name)) continue;
+ names.add(name);
CompletionProposal proposal = createProposal(fContext.getReplaceStart(), CompletionProposal.CONSTANT_REF, name, element);
proposal.setType(name);
fRequestor.accept(proposal);
@@ -372,14 +375,12 @@
}
private void suggestConstantNames() {
- SearchPattern pattern = SearchPattern.createPattern(IRubyElement.CONSTANT, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
+ SearchPattern pattern = SearchPattern.createPattern(IRubyElement.CONSTANT, fContext.getPartialPrefix()+ "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {fContext.getScript()});
List<SearchMatch> results = search(pattern, scope);
for (SearchMatch match: results) {
IRubyElement element = (IRubyElement) match.getElement();
String name = element.getElementName();
- if (!fContext.prefixStartsWith(name))
- continue;
CompletionProposal proposal = createProposal(fContext.getReplaceStart(), CompletionProposal.CONSTANT_REF, name, element);
proposal.setType(name);
fRequestor.accept(proposal);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|