[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor PythonCompletionProcessor.java,1.14,1.15
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-08-10 16:04:38
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4917/src/org/python/pydev/editor Modified Files: PythonCompletionProcessor.java Log Message: Cached results from code completion and removed completion for ( and [. Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PythonCompletionProcessor.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PythonCompletionProcessor.java 10 Aug 2004 14:09:38 -0000 1.14 --- PythonCompletionProcessor.java 10 Aug 2004 16:04:18 -0000 1.15 *************** *** 14,20 **** import java.net.URL; import java.util.ArrayList; ! import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Vector; --- 14,21 ---- import java.net.URL; import java.util.ArrayList; ! import java.util.HashMap; import java.util.Iterator; import java.util.List; + import java.util.Map; import java.util.Vector; *************** *** 50,53 **** --- 51,58 ---- public class PythonCompletionProcessor extends TemplateCompletionProcessor implements IContentAssistProcessor { + + private Map cache = new HashMap(); + private List cacheEntries = new ArrayList(); + /* * (non-Javadoc) *************** *** 95,126 **** List propList = new ArrayList(); IDocument doc = viewer.getDocument(); ! //System.out.println("The document:"+doc.get()); Point selectedRange = viewer.getSelectedRange(); // there may not be a selected range java.lang.String theDoc = doc.get(); calcDocBoundary(theDoc, documentOffset); String activationToken = this .getActivationToken(theDoc, documentOffset); ! //System.out.println("DBG:theActivationToken: " + activationToken); theDoc = partialDocument(theDoc, documentOffset); ! java.lang.String qualifier = getQualifier(doc, documentOffset); int qlen = qualifier.length(); theDoc += "\n" + activationToken; - //System.out.println("Interpreted doc: " + theDoc); - //System.out.println("activationToken: " + activationToken); - Vector theList = autoComplete(theDoc, activationToken); - //System.out.println("DBG:vector:" + theList); ! for (Iterator iter = theList.iterator(); iter.hasNext();) { ! String element = (String) iter.next(); ! ! CompletionProposal proposal = new CompletionProposal(element, ! documentOffset - qlen, qlen, element.length()); ! propList.add(proposal); } //templates proposals are added here. addTemplateProposals(viewer, documentOffset, propList); ICompletionProposal[] proposals = new ICompletionProposal[propList .size()]; --- 100,163 ---- List propList = new ArrayList(); IDocument doc = viewer.getDocument(); ! Point selectedRange = viewer.getSelectedRange(); // there may not be a selected range java.lang.String theDoc = doc.get(); calcDocBoundary(theDoc, documentOffset); + String activationToken = this .getActivationToken(theDoc, documentOffset); ! ! java.lang.String qualifier = ""; ! ! while(activationToken.endsWith(".") == false && activationToken.length() > 0){ ! qualifier += activationToken.charAt(activationToken.length()-1); ! activationToken = activationToken.substring(0, activationToken.length()-1); ! } ! ! theDoc = partialDocument(theDoc, documentOffset); ! ! int qlen = qualifier.length(); theDoc += "\n" + activationToken; ! //simple cache mechanism. ! List allProposals; ! if(cache.containsKey(theDoc)){ ! allProposals = (List) cache.get(theDoc); ! } ! else{ ! Vector theList = 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); ! } } + //end cache mechanism. + //templates proposals are added here. 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()]; *************** *** 311,323 **** } - /** - * @param doc - * @param documentOffset - */ - private java.lang.String getQualifier(IDocument doc, int documentOffset) { - // this routine should return any partial entry after the activation - // character - return ""; - } /* --- 348,351 ---- *************** *** 339,343 **** */ public char[] getCompletionProposalAutoActivationCharacters() { ! return new char[] { '.', '(', '[' }; } --- 367,371 ---- */ public char[] getCompletionProposalAutoActivationCharacters() { ! return new char[] { '.'/*, '(', '['*/ }; } |