|
From: <caw...@us...> - 2007-04-30 12:27:39
|
Revision: 2394
http://svn.sourceforge.net/rubyeclipse/?rev=2394&view=rev
Author: cawilliams
Date: 2007-04-30 05:27:37 -0700 (Mon, 30 Apr 2007)
Log Message:
-----------
when we're doing method completion: in addition to trying type inferrencing, also suggest any methods that match the prefix on any type (a sort of global fallback)
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-04-30 12:04:54 UTC (rev 2393)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-04-30 12:27:37 UTC (rev 2394)
@@ -92,18 +92,21 @@
if (guesses.isEmpty()) {
guesses.add(new BasicTypeGuess(OBJECT, 100));
}
+ 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!
for (int i = 0; i < types.length; i++) {
- List<CompletionProposal> list = sort(suggestMethods(guess.getConfidence(), types[i]));
- for (CompletionProposal proposal : list) {
- fRequestor.accept(proposal);
- }
+ Map<String, CompletionProposal> map = suggestMethods(guess.getConfidence(), types[i]);
+ list.addAll(map.values());
}
}
-
+ list.addAll(suggestAllMethodsMatchingPrefix(script));
+ Collections.sort(list, new CompletionProposalComparator());
+ for (CompletionProposal proposal : list) {
+ fRequestor.accept(proposal);
+ }
} else {
// FIXME If we're invoked on the class declaration (it's super class) don't do this!
// FIXME Traverse the IRubyElement model, not nodes (and don't reparse)?
@@ -120,6 +123,32 @@
fContext = null;
}
+ private List<CompletionProposal> suggestAllMethodsMatchingPrefix(IRubyScript script) {
+ List< CompletionProposal> list = new ArrayList<CompletionProposal>();
+ IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {script.getRubyProject()});
+ SearchParticipant participant = BasicSearchEngine.getDefaultSearchParticipant();
+ CollectingSearchRequestor searchRequestor = new CollectingSearchRequestor();
+ SearchPattern pattern = SearchPattern.createPattern(IRubyElement.METHOD, fContext.getPartialPrefix(), IRubySearchConstants.DECLARATIONS, SearchPattern.R_PREFIX_MATCH);
+ try {
+ new BasicSearchEngine().search(pattern, new SearchParticipant[] {participant}, scope, searchRequestor, null);
+ } catch (CoreException e) {
+ RubyCore.log(e);
+ }
+ List<SearchMatch> matches = searchRequestor.getResults();
+ for (SearchMatch match : matches) {
+ IMethod element = (IMethod) match.getElement();
+ IType type = element.getDeclaringType();
+ String typeName = "";
+ if (type != null)
+ typeName = type.getElementName();
+ CompletionProposal proposal = suggestMethod(element, typeName, 100); // TODO Base confidence on accuracy in match?
+ if (proposal != null) {
+ list.add(proposal);
+ }
+ }
+ return list;
+ }
+
private void suggestMethodsForEnclosingType(IRubyScript script) throws RubyModelException {
IMember element = (IMember) script.getElementAt(fContext.getOffset());
IType type = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|