|
From: <caw...@us...> - 2006-07-22 01:49:42
|
Revision: 1540 Author: cawilliams Date: 2006-07-21 18:49:23 -0700 (Fri, 21 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1540&view=rev Log Message: ----------- add some hacks so we handle periods properly for code completion. (we hack off the period and do some offset adjustments) So now we properly find an inferred type in the same project and grab all the methods on it. (Now we just need to handle searching referenced projects and the ruby core) Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2006-07-22 01:49:23 UTC (rev 1540) @@ -0,0 +1,43 @@ +package org.rubypeople.rdt.internal.codeassist; + +import org.rubypeople.rdt.core.IRubyProject; +import org.rubypeople.rdt.core.IRubyScript; +import org.rubypeople.rdt.core.IType; +import org.rubypeople.rdt.core.RubyModelException; + +public class RubyElementRequestor { + + private IRubyProject[] projects; + + public RubyElementRequestor(IRubyProject[] projects) { + this.projects = projects; + } + + public IType findType(String typeName) { + try { + for (int x = 0; x < projects.length; x++) { + IRubyProject project = projects[x]; + IRubyScript[] scripts = project.getRubyScripts(); + System.out.println("Got " + scripts.length + " scripts"); + for (int i = 0; i < scripts.length; i++) { + IRubyScript script = scripts[i]; + System.out.println("Checking for that type inside script: " + + script.getElementName()); + IType[] types = script.getTypes(); + for (int j = 0; j < types.length; j++) { + IType type = types[j]; + if (!type.getElementName().equals(typeName)) + continue; + return type; + + } + } + } + } catch (RubyModelException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + +} Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-07-21 00:57:04 UTC (rev 1539) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-07-22 01:49:23 UTC (rev 1540) @@ -59,6 +59,7 @@ import org.rubypeople.rdt.core.RubyCore; import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.core.WorkingCopyOwner; +import org.rubypeople.rdt.internal.codeassist.RubyElementRequestor; import org.rubypeople.rdt.internal.core.buffer.BufferManager; import org.rubypeople.rdt.internal.core.parser.RubyParser; import org.rubypeople.rdt.internal.core.util.Util; @@ -664,44 +665,38 @@ public void codeComplete(int offset, CompletionRequestor requestor) throws RubyModelException { if (offset < 0) offset = 0; ITypeInferrer inferrer = new DefaultTypeInferrer(); - List<ITypeGuess> guesses = inferrer.infer(new String(getContents()), offset); - // FIXME We're doing some ugly hacky searching for methods and types - // here + StringBuffer source = new StringBuffer(new String(getContents())); + int replaceStart = offset + 1; + char charAtOffset = (char) source.charAt(offset); + if (charAtOffset == '.') { + source.deleteCharAt(offset); + offset--; + } + charAtOffset = (char) source.charAt(offset); + System.out.println(charAtOffset); + List<ITypeGuess> guesses = inferrer.infer(source.toString(), offset); + // TODO Grab the project and all referred projects! + IRubyProject[] projects = new IRubyProject[1]; + projects[0] = getRubyProject(); + RubyElementRequestor completer = new RubyElementRequestor(projects); for (Iterator iter = guesses.iterator(); iter.hasNext();) { ITypeGuess guess = (ITypeGuess) iter.next(); System.out.println("Type Inferrer thinks this is a: " + guess.getType()); - - IRubyProject project = getRubyProject(); - IRubyScript[] scripts = project.getRubyScripts(); - System.out.println("Got " + scripts.length + " scripts"); - for (int i = 0; i < scripts.length; i++) { - IRubyScript script = scripts[i]; - System.out.println("Checking for that type inside script: " - + script.getElementName()); - IType[] types = script.getTypes(); - for (int j = 0; j < types.length; j++) { - - IType type = types[j]; - if (!type.getElementName().equals(guess.getType())) - continue; - System.out.println("Got type with that name: " - + type.getElementName()); - IMethod[] methods = type.getMethods(); - System.out.println("Got " + methods.length + " methods"); - for (int k = 0; k < methods.length; k++) { - String name = methods[k].getElementName(); - System.out.println("Got method name: " + name); - CompletionProposal proposal = new CompletionProposal( - CompletionProposal.METHOD_REF, name, guess - .getConfidence()); - proposal - .setReplaceRange(offset, offset + name.length()); - requestor.accept(proposal); - } - } + IType type = completer.findType(guess.getType()); + IMethod[] methods = type.getMethods(); + System.out.println("Got " + methods.length + " methods"); + for (int k = 0; k < methods.length; k++) { + String name = methods[k].getElementName(); + System.out.println("Got method name: " + name); + CompletionProposal proposal = new CompletionProposal( + CompletionProposal.METHOD_REF, name, guess + .getConfidence()); + // TODO Handle replacement start index correctly + proposal.setReplaceRange(replaceStart, replaceStart + name.length()); + requestor.accept(proposal); } } } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |