[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion PyTemplateCompletion.java,1.
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-13 17:12:34
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1125/src/org/python/pydev/editor/codecompletion Modified Files: PyTemplateCompletion.java PythonShell.java PyCodeCompletionPreferencesPage.java PythonCompletionProcessor.java CompletionCache.java PyCodeCompletion.java Log Message: New code completion. Index: PyCodeCompletionPreferencesPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletionPreferencesPage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyCodeCompletionPreferencesPage.java 25 Aug 2004 17:25:23 -0000 1.1 --- PyCodeCompletionPreferencesPage.java 13 Sep 2004 17:11:49 -0000 1.2 *************** *** 36,39 **** --- 36,42 ---- public static final boolean DEFAULT_AUTOCOMPLETE_ON_PAR = false; + public static final String USE_SERVER_TIP = "USE_SERVER_TIP"; + public static final boolean DEFAULT_USE_SERVER_TIP = false; + /** */ *************** *** 62,65 **** --- 65,71 ---- addField(new BooleanFieldEditor( AUTOCOMPLETE_ON_PAR, "Autocomplete on '('?", p)); + + addField(new BooleanFieldEditor( + USE_SERVER_TIP, "Use server tipper enviroment (otherwise console is used)?", p)); } *************** *** 81,84 **** --- 87,91 ---- prefs.setDefault(AUTOCOMPLETE_DELAY, DEFAULT_AUTOCOMPLETE_DELAY); prefs.setDefault(AUTOCOMPLETE_ON_PAR, DEFAULT_AUTOCOMPLETE_ON_PAR); + prefs.setDefault(USE_SERVER_TIP, DEFAULT_USE_SERVER_TIP); } *************** *** 99,102 **** --- 106,113 ---- } + public static boolean useServerTipEnviroment() { + return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.USE_SERVER_TIP); + } + /* (non-Javadoc) * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) Index: PyTemplateCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyTemplateCompletion.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyTemplateCompletion.java 11 Aug 2004 13:04:13 -0000 1.1 --- PyTemplateCompletion.java 13 Sep 2004 17:11:49 -0000 1.2 *************** *** 6,11 **** --- 6,13 ---- package org.python.pydev.editor.codecompletion; + import java.io.File; import java.util.List; + import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IRegion; *************** *** 51,55 **** */ protected Image getImage(Template template) { ! // TODO Auto-generated method stub return null; } --- 53,62 ---- */ protected Image getImage(Template template) { ! try { ! File file = PyCodeCompletion.getImageWithinIcons("template.gif"); ! return new Image(null, file.getAbsolutePath()); ! } catch (CoreException e) { ! e.printStackTrace(); ! } return null; } Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonCompletionProcessor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PythonCompletionProcessor.java 25 Aug 2004 17:25:41 -0000 1.3 --- PythonCompletionProcessor.java 13 Sep 2004 17:11:50 -0000 1.4 *************** *** 16,19 **** --- 16,20 ---- import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.swt.graphics.Point; + import org.python.pydev.editor.PyEdit; /** *************** *** 31,34 **** --- 32,44 ---- private CompletionCache completionCache = new CompletionCache(); + private PyEdit edit; + + /** + * @param edit + */ + public PythonCompletionProcessor(PyEdit edit) { + this.edit = edit; + } + private boolean endsWithSomeChar(char cs[], String activationToken) { for (int i = 0; i < cs.length; i++) { *************** *** 43,48 **** public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { ! List propList = new ArrayList(); IDocument doc = viewer.getDocument(); Point selectedRange = viewer.getSelectedRange(); --- 53,59 ---- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { ! IDocument doc = viewer.getDocument(); + Point selectedRange = viewer.getSelectedRange(); *************** *** 55,67 **** java.lang.String qualifier = ""; ! char[] cs = getCompletionProposalAutoActivationCharacters(); ! ! while (endsWithSomeChar(cs, activationToken) == false ! && activationToken.length() > 0) { ! qualifier = activationToken.charAt(activationToken.length() - 1) ! + qualifier; ! activationToken = activationToken.substring(0, activationToken ! .length() - 1); } --- 66,85 ---- java.lang.String qualifier = ""; ! char[] cs = new char[]{'.', '(', ' '}; ! ! //we complete on '.' and '('. ! //' ' gets globals ! //and any other char gets globals on token and templates. ! //we have to get the qualifier. e.g. bla.foo = foo is the qualifier. ! if(activationToken.indexOf('.')!= -1){ ! while (endsWithSomeChar(cs, activationToken) == false ! && activationToken.length() > 0) { ! ! qualifier = activationToken.charAt(activationToken.length() - 1) ! + qualifier; ! activationToken = activationToken.substring(0, activationToken ! .length() - 1); ! } } *************** *** 71,92 **** theDoc += "\n" + activationToken; ! List allProposals = this.completionCache.getAllProposals(theDoc, ! activationToken, documentOffset, qlen, codeCompletion); ! //templates proposals are added here. ! this.templatesCompletion.addTemplateProposals(viewer, documentOffset, ! propList); ! for (Iterator iter = allProposals.iterator(); iter.hasNext();) { ICompletionProposal proposal = (ICompletionProposal) iter.next(); if (proposal.getDisplayString().startsWith(qualifier)) { ! propList.add(proposal); } } ! ICompletionProposal[] proposals = new ICompletionProposal[propList ! .size()]; // and fill with list elements ! propList.toArray(proposals); // Return the proposals return proposals; --- 89,113 ---- theDoc += "\n" + activationToken; ! List pythonProposals = getPythonProposals(documentOffset, doc, theDoc, activationToken, qlen); ! List templateProposals = getTemplateProposals(viewer, documentOffset, activationToken, qualifier, pythonProposals); ! ArrayList pythonAndTemplateProposals = new ArrayList(); ! pythonAndTemplateProposals.addAll(pythonProposals); ! pythonAndTemplateProposals.addAll(templateProposals); ! ! ArrayList returnProposals = new ArrayList(); ! ! for (Iterator iter = pythonAndTemplateProposals.iterator(); iter.hasNext();) { ICompletionProposal proposal = (ICompletionProposal) iter.next(); if (proposal.getDisplayString().startsWith(qualifier)) { ! returnProposals.add(proposal); } } ! ICompletionProposal[] proposals = new ICompletionProposal[returnProposals.size()]; ! // and fill with list elements ! returnProposals.toArray(proposals); // Return the proposals return proposals; *************** *** 94,97 **** --- 115,150 ---- } + /** + * @param documentOffset + * @param doc + * @param theDoc + * @param activationToken + * @param qlen + * @return + */ + private List getPythonProposals(int documentOffset, IDocument doc, java.lang.String theDoc, String activationToken, int qlen) { + List allProposals = this.completionCache.getAllProposals(edit, doc, theDoc, + activationToken, documentOffset, qlen, codeCompletion); + return allProposals; + } + + /** + * @param viewer + * @param documentOffset + * @param activationToken + * @param qualifier + * @param allProposals + */ + private List getTemplateProposals(ITextViewer viewer, int documentOffset, String activationToken, java.lang.String qualifier, List allProposals) { + List propList = new ArrayList(); + if(activationToken.trim().equals("") == false){ + //templates proposals are added here. + this.templatesCompletion.addTemplateProposals(viewer, documentOffset, + propList); + + } + return propList; + } + /* * (non-Javadoc) Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PythonShell.java 27 Aug 2004 17:12:00 -0000 1.1 --- PythonShell.java 13 Sep 2004 17:11:49 -0000 1.2 *************** *** 6,60 **** package org.python.pydev.editor.codecompletion; - import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.net.Socket; import org.eclipse.core.runtime.CoreException; /** ! * ! * TODO: THIS IS STILL ONLY A TEST!! ! * * @author Fabio Zadrozny */ public class PythonShell { ! public Process p; ! private Socket socket; ! public static final String END_MSG = "@END@"; - public PythonShell() throws IOException, CoreException { - startIt(); - } /** * @throws CoreException */ ! public void startIt() throws IOException, CoreException { ! ! File serverFile = new File("D:\\dev_programs\\eclipse_3\\eclipse\\workspace\\org.python.pydev\\PySrc\\pycompletionserver.py"); ! //PyCodeCompletion.getScriptWithinPySrc("pycompletionserver.py"); ! ! p = Runtime.getRuntime().exec("python "+serverFile.getAbsolutePath()); ! ! sleepALittle(); ! ! socket = new Socket("127.0.0.1",50007); ! ! write("TESTE"+END_MSG); ! String b = read(); ! System.out.println(b); } ! /** * */ private void sleepALittle() { try { synchronized(this){ ! wait(100); } } catch (InterruptedException e) { --- 6,94 ---- package org.python.pydev.editor.codecompletion; import java.io.File; import java.io.IOException; + import java.net.ServerSocket; import java.net.Socket; + import java.util.ArrayList; + import java.util.List; + import java.util.StringTokenizer; import org.eclipse.core.runtime.CoreException; /** ! * TODO: Still only a test!! * @author Fabio Zadrozny */ public class PythonShell { ! ! public static final int BUFFER_SIZE = 1024; ! /** ! * Python server process. ! */ ! public Process process; ! ! /** ! * We should write in this socket. ! */ ! private Socket socketToWrite; ! ! /** ! * We should read this socket. ! */ ! private Socket socketToRead; ! ! /** ! * Python file that works as the server. ! */ ! private File serverFile; + /** + * Server socket (accept connections). + */ + private ServerSocket serverSocket; /** + * Initialize given the file that points to the python server (execute it + * with python). + * + * @param f file pointing to the python server + * + * @throws IOException * @throws CoreException */ ! public PythonShell(File f) throws IOException, CoreException { ! serverFile = f; ! if(!serverFile.exists()){ ! throw new RuntimeException("Can't find python server file"); ! } } ! /** + * Initialize with the default python server file. * + * @throws IOException + * @throws CoreException + */ + public PythonShell() throws IOException, CoreException { + this(PyCodeCompletion.getScriptWithinPySrc("pycompletionserver.py")); + } + + /** + * Just wait a little... */ private void sleepALittle() { + sleepALittle(25); //25 millis + } + + /** + * Just wait a little... + */ + private void sleepALittle(int t) { try { synchronized(this){ ! wait(t); //millis } } catch (InterruptedException e) { *************** *** 64,92 **** /** ! * @throws IOException */ ! private void closeConn() throws IOException { ! if(socket != null){ ! socket.getOutputStream().write("".getBytes()); ! socket.close(); } - socket = null; } /** ! * @return * @throws IOException */ public String read() throws IOException { String str = ""; ! while(str.endsWith(END_MSG)){ ! BufferedInputStream inputStream = new BufferedInputStream(socket.getInputStream(), 3); ! int size = inputStream.available(); ! byte b[] = new byte[size]; ! inputStream.read(b); ! str += new String(b); } ! return str; } /** --- 98,148 ---- /** ! * This method creates the python server process and starts the sockets, so that we ! * can talk with the server. ! * ! * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt() throws IOException{ ! try { ! process = Runtime.getRuntime().exec("python "+serverFile.getAbsolutePath()+" 50007 50008"); ! ! sleepALittle(); ! ! socketToWrite = new Socket("127.0.0.1",50007); //we should write in port 50007 ! serverSocket = new ServerSocket(50008); //and read in port 50008 ! socketToRead = serverSocket.accept(); ! } catch (IOException e) { ! ! if(process!=null){ ! process.destroy(); ! } ! e.printStackTrace(); ! throw e; } } + /** ! * @return s string with the contents read. * @throws IOException */ public String read() throws IOException { String str = ""; ! ! while(str.indexOf("END@@") == -1 ){ ! byte[] b = new byte[PythonShell.BUFFER_SIZE]; ! ! this.socketToRead.getInputStream().read(b); ! String s = new String(b); ! ! str += s; } ! ! //remove @@COMPLETIONS ! str = str.replaceFirst("@@COMPLETIONS",""); ! //remove END@@ ! return str.substring(0, str.indexOf("END@@")); } + /** *************** *** 95,105 **** */ public void write(String str) throws IOException { ! socket.getOutputStream().write(str.getBytes()); } /** * Kill our sub-process. */ ! private void endIt() { try { closeConn(); --- 151,186 ---- */ public void write(String str) throws IOException { ! this.socketToWrite.getOutputStream().write(str.getBytes()); ! } ! ! ! /** ! * @throws IOException ! */ ! private void closeConn() throws IOException { ! write("@@KILL_SERVER_END@@"); ! if(socketToWrite != null){ ! socketToWrite.close(); ! } ! socketToWrite = null; ! ! if(socketToRead != null){ ! socketToRead.close(); ! } ! socketToRead = null; ! ! if(serverSocket != null){ ! serverSocket.close(); ! } ! serverSocket = null; } + /** * Kill our sub-process. + * @throws IOException */ ! void endIt() throws IOException { ! try { closeConn(); *************** *** 107,120 **** e.printStackTrace(); } ! if (p!= null){ ! p.destroy(); ! p = null; } } ! ! public static void main(String[] args) throws IOException, CoreException{ ! PythonShell shell = new PythonShell(); ! shell.endIt(); } --- 188,295 ---- e.printStackTrace(); } ! if (process!= null){ ! int i = process.getErrorStream().available(); ! byte b[] = new byte[i]; ! process.getErrorStream().read(b); ! System.out.println(new String(b)); ! ! i = process.getInputStream().available(); ! b = new byte[i]; ! process.getErrorStream().read(b); ! System.out.println(new String(b)); ! ! process.destroy(); ! try { ! process.waitFor(); ! } catch (InterruptedException e1) { ! e1.printStackTrace(); ! } ! process = null; } } ! ! ! ! /** ! * @param str ! * @throws IOException ! */ ! public List getGlobalCompletions(String str) { ! try { ! this.write("@@GLOBALS:"+str+"\nEND@@"); ! ! return getCompletions(); ! } catch (IOException e) { ! e.printStackTrace(); ! try { ! this.endIt(); ! } catch (IOException e1) { ! // TODO Auto-generated catch block ! e1.printStackTrace(); ! } ! try { ! this.startIt(); ! } catch (IOException e2) { ! // TODO Auto-generated catch block ! e2.printStackTrace(); ! } ! return getInvalidCompletion(); ! } ! ! } ! ! /** ! * @param str ! * @throws IOException ! */ ! public List getTokenCompletions(String token, String str) { ! String s = "@@TOKEN_GLOBALS("+token+"):"+str+"\nEND@@"; ! try { ! this.write(s); ! ! return getCompletions(); ! } catch (IOException e) { ! e.printStackTrace(); ! try { ! this.endIt(); ! } catch (IOException e1) { ! // TODO Auto-generated catch block ! e1.printStackTrace(); ! } ! try { ! this.startIt(); ! } catch (IOException e2) { ! // TODO Auto-generated catch block ! e2.printStackTrace(); ! } ! return getInvalidCompletion(); ! } ! } ! ! /** ! * @return ! */ ! private List getInvalidCompletion() { ! List l = new ArrayList(); ! l.add(new String[]{"SERVER_ERROR","please try again."}); ! return l; ! } ! ! ! /** ! * @throws IOException ! */ ! private List getCompletions() throws IOException { ! ArrayList list = new ArrayList(); ! String string = this.read().replaceAll("\\(","").replaceAll("\\)",""); ! StringTokenizer tokenizer = new StringTokenizer(string, ","); ! ! while(tokenizer.hasMoreTokens()){ ! String token = tokenizer.nextToken(); ! String description = tokenizer.nextToken(); ! list.add(new String[]{token, description}); ! } ! return list; } Index: PyCodeCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletion.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyCodeCompletion.java 16 Aug 2004 20:55:31 -0000 1.3 --- PyCodeCompletion.java 13 Sep 2004 17:11:50 -0000 1.4 *************** *** 13,16 **** --- 13,17 ---- import java.net.URL; import java.util.ArrayList; + import java.util.Iterator; import java.util.List; *************** *** 20,24 **** --- 21,33 ---- import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; + import org.eclipse.jface.text.BadLocationException; + import org.eclipse.jface.text.IDocument; + import org.eclipse.jface.text.IRegion; import org.osgi.framework.Bundle; + import org.python.pydev.editor.PyEdit; + import org.python.pydev.editor.model.AbstractNode; + import org.python.pydev.editor.model.Location; + import org.python.pydev.editor.model.ModelUtils; + import org.python.pydev.editor.model.Scope; import org.python.pydev.plugin.PydevPlugin; *************** *** 28,38 **** */ public class PyCodeCompletion { ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, ! * int) ! */ int docBoundary = -1; // the document prior to the activation token /** --- 37,44 ---- */ public class PyCodeCompletion { ! ! int docBoundary = -1; // the document prior to the activation token + private PythonShell pytonShell; /** *************** *** 54,57 **** --- 60,66 ---- /** * Returns a list with the tokens to use for autocompletion. + * @param edit + * @param doc + * @param documentOffset * * @param theCode *************** *** 59,69 **** * @return */ ! public List autoComplete(java.lang.String theCode, java.lang.String theActivationToken) { List theList = new ArrayList(); ! File tipperFile=null; try { ! tipperFile = getAutoCompleteScript(); } catch (CoreException e) { --- 68,182 ---- * @return */ ! public List autoComplete(PyEdit edit, IDocument doc, int documentOffset, java.lang.String theCode, java.lang.String theActivationToken) { + if(PyCodeCompletionPreferencesPage.useServerTipEnviroment()){ + return serverCompletion(theActivationToken, edit, doc, documentOffset, theCode); + }else{ + return consoleCompletion(theCode); + } + } + + + /** + * @param edit + * @param doc + * @param documentOffset + * @param theCode + * @param theCode + */ + private List serverCompletion(String theActivationToken, PyEdit edit, IDocument doc, int documentOffset, String theCode) { List theList = new ArrayList(); ! PythonShell serverShell = null; ! try { ! serverShell = getServerShell(); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! ! ! String docToParse = getDocToParse(doc, documentOffset); ! ! if (theActivationToken.replace('.',' ').trim().equals("self")){ ! // System.out.println("serverCompletion - self."); ! ! Location loc = Location.offsetToLocation(doc, documentOffset); ! AbstractNode closest = ModelUtils.getLessOrEqualNode(edit.getPythonModel(),loc); + Scope scope = closest.getScope().findContainingClass(); + String token = scope.getStartNode().getName(); + + List completions = serverShell.getTokenCompletions(token, docToParse); + theList.addAll(completions); + + } + else{ //go to globals + // System.out.println("simpleCompletion - ''"); + List completions = serverShell.getGlobalCompletions(docToParse); + theList.addAll(completions); + + } + return theList; + + } + + /** + * @param doc + * @param documentOffset + * @return + */ + private String getDocToParse(IDocument doc, int documentOffset) { + String wholeDoc = doc.get(); + String newDoc = ""; try { ! int lineOfOffset = doc.getLineOfOffset(documentOffset); ! IRegion lineInformation = doc.getLineInformation(lineOfOffset); ! ! int docLength = doc.getLength(); ! String src = doc.get(lineInformation.getOffset(), documentOffset-lineInformation.getOffset()); ! ! String spaces=""; ! for (int i = 0; i < src.length(); i++) { ! if(src.charAt(i) != ' '){ ! break; ! } ! spaces += ' '; ! } ! ! newDoc = wholeDoc.substring(0, lineInformation.getOffset()); ! newDoc += spaces+"pass\n"; ! newDoc += wholeDoc.substring(lineInformation.getOffset() + lineInformation.getLength(), docLength); ! ! System.out.println("DOC:"+newDoc); ! ! } catch (BadLocationException e1) { ! e1.printStackTrace(); ! } ! return newDoc; ! } ! ! /** ! * @return ! * @throws CoreException ! * @throws IOException ! * ! */ ! private PythonShell getServerShell() throws IOException, CoreException { ! if(pytonShell == null){ ! pytonShell = new PythonShell(); ! pytonShell.startIt(); ! } ! return pytonShell; ! ! } ! ! /** ! * @param theCode ! */ ! private List consoleCompletion(java.lang.String theCode) { ! List theList = new ArrayList(); ! File tipperFile=null; ! try { ! ! tipperFile = getAutoCompleteScript(false); } catch (CoreException e) { *************** *** 86,90 **** writer.write("sys.path.insert(0,r'"+tipperFile.getParent()+"')\n"); - //now we have it in the modules... import and call tipper with the code... writer.write("from tipper import GenerateTip\n"); --- 199,202 ---- *************** *** 98,102 **** writer.write("GenerateTip(s)\n\n\n"); - writer.flush(); writer.close(); --- 210,213 ---- *************** *** 105,108 **** --- 216,220 ---- while ((str = in.readLine()) != null) { if (!str.startsWith("tip: ")){ + // System.out.println("std output: " + str); continue; } *************** *** 110,114 **** str = str.substring(5); ! theList.add(str); } in.close(); --- 222,226 ---- str = str.substring(5); ! theList.add(new String[]{str,""}); } in.close(); *************** *** 129,132 **** --- 241,258 ---- } + /** + * + * @param useSimpleTipper + * @return the script to get the variables. + * + * @throws CoreException + */ + public static File getAutoCompleteScript(boolean useSimpleTipper) throws CoreException { + if(useSimpleTipper){ + return getScriptWithinPySrc("simpleTipper.py"); + }else{ + return getScriptWithinPySrc("tipper.py"); + } + } /** *************** *** 136,141 **** * @throws CoreException */ ! public static File getAutoCompleteScript() throws CoreException { ! String targetExec = "tipper.py"; IPath relative = new Path("PySrc").addTrailingSeparator().append( --- 262,266 ---- * @throws CoreException */ ! public static File getScriptWithinPySrc(String targetExec) throws CoreException { IPath relative = new Path("PySrc").addTrailingSeparator().append( *************** *** 157,160 **** --- 282,305 ---- } + public static File getImageWithinIcons(String icon) throws CoreException { + + IPath relative = new Path("icons").addTrailingSeparator().append( + icon); + + Bundle bundle = PydevPlugin.getDefault().getBundle(); + + URL bundleURL = Platform.find(bundle, relative); + URL fileURL; + try { + fileURL = Platform.asLocalURL(bundleURL); + File f = new File(fileURL.getPath()); + + return f; + } catch (IOException e) { + throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, + "Can't find image", null)); + } + } + /** * The docBoundary should get until the last line before the one *************** *** 181,185 **** calcDocBoundary(theDoc, documentOffset); } ! return theDoc.substring(this.docBoundary + 1, documentOffset); } --- 326,334 ---- calcDocBoundary(theDoc, documentOffset); } ! String str = theDoc.substring(this.docBoundary + 1, documentOffset); ! if (str.endsWith(" ")){ ! str = " "; ! } ! return str; } Index: CompletionCache.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/CompletionCache.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CompletionCache.java 11 Aug 2004 13:04:13 -0000 1.1 --- CompletionCache.java 13 Sep 2004 17:11:50 -0000 1.2 *************** *** 12,16 **** --- 12,18 ---- import java.util.Map; + import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.CompletionProposal; + import org.python.pydev.editor.PyEdit; /** *************** *** 18,67 **** */ public class CompletionCache { ! private Map cache = new HashMap(); private List cacheEntries = new ArrayList(); - ! public List getAllProposals(String theDoc, String activationToken, ! int documentOffset, int qlen, PyCodeCompletion codeCompletion) { - - List allProposals = null; ! if (cache.containsKey(theDoc)) { ! //if it is in the cache, we can just get the proposals, ! //the only thing here, is that we have to change its size depending ! //on the new qlen. ! ! ! allProposals = new ArrayList(); ! List proposals = (List) cache.get(theDoc); ! ! for (Iterator iter = proposals.iterator(); iter.hasNext();) { ! CompletionProposal prop = (CompletionProposal) iter.next(); ! String displayString = prop.getDisplayString(); ! allProposals.add(new CompletionProposal(displayString, ! documentOffset - qlen, qlen, displayString.length())); ! } ! ! ! ! } else { ! List theList = codeCompletion.autoComplete(theDoc, ! activationToken); allProposals = new ArrayList(); for (Iterator iter = theList.iterator(); iter.hasNext();) { ! String element = (String) iter.next(); ! CompletionProposal proposal = new CompletionProposal(element, ! documentOffset - qlen, qlen, element.length()); allProposals.add(proposal); } ! cacheEntries.add(theDoc); ! cache.put(theDoc, allProposals); ! //we don't want this the get huge... ! if (cacheEntries.size() > 20) { Object entry = cacheEntries.remove(0); cache.remove(entry); --- 20,63 ---- */ public class CompletionCache { ! private Map cache = new HashMap(); private List cacheEntries = new ArrayList(); ! /** ! * Returns all the completions ! * ! * @param edit ! * @param doc ! * @param partialDoc ! * @param activationToken ! * @param documentOffset ! * @param qlen ! * @param codeCompletion ! * @return ! */ ! public List getAllProposals(PyEdit edit, IDocument doc, String partialDoc, ! String activationToken, int documentOffset, int qlen, PyCodeCompletion codeCompletion) { ! List allProposals = getCacheProposals(partialDoc, documentOffset, qlen); ! ! if(allProposals == null){ //no cache proposals ! List theList = codeCompletion.autoComplete(edit, doc, ! documentOffset, partialDoc, activationToken); allProposals = new ArrayList(); for (Iterator iter = theList.iterator(); iter.hasNext();) { ! String element[] = (String[]) iter.next(); ! ! CompletionProposal proposal = new CompletionProposal(element[0], ! documentOffset - qlen, qlen, element[0].length(),null, null, null, element[1]); allProposals.add(proposal); } ! cacheEntries.add(partialDoc); ! cache.put(partialDoc, allProposals); ! //we don't want this to get huge... ! if (cacheEntries.size() > 2) { Object entry = cacheEntries.remove(0); cache.remove(entry); *************** *** 71,73 **** --- 67,102 ---- } + + /** + * @param partialDoc + * @param documentOffset + * @param qlen + * @return + */ + private List getCacheProposals(String partialDoc, int documentOffset, int qlen) { + List allProposals = null; + if (cache.containsKey(partialDoc)) { + //if it is in the cache, we can just get the proposals, + //the only thing here, is that we have to change its size depending + //on the new qlen. + + allProposals = new ArrayList(); + List proposals = (List) cache.get(partialDoc); + + for (Iterator iter = proposals.iterator(); iter.hasNext();) { + CompletionProposal prop = (CompletionProposal) iter.next(); + String displayString = prop.getDisplayString(); + allProposals.add(new CompletionProposal( + displayString, // + documentOffset - qlen, // + qlen, // + displayString.length(), // + prop.getImage(), // + prop.getDisplayString(), // + prop.getContextInformation(), // + prop.getAdditionalProposalInfo()));// + } + } + return allProposals; + } } \ No newline at end of file |