[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion PythonShell.java,1.8,1.9 Pyt
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-24 16:41:31
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15928/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java PythonCompletionProcessor.java PyCodeCompletion.java CompletionCache.java Log Message: Decoration support / Making correction assistant on Ctrl+1 Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PythonShell.java 20 Sep 2004 13:18:05 -0000 1.8 --- PythonShell.java 24 Sep 2004 16:41:21 -0000 1.9 *************** *** 17,21 **** --- 17,23 ---- import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.IStatus; import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; + import org.python.pydev.plugin.PydevPlugin; import org.python.pydev.plugin.PydevPrefs; import org.python.pydev.plugin.SocketUtil; *************** *** 127,132 **** * @param milisSleep: time to wait after creating the process. * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt(int milisSleep) throws IOException{ try { --- 129,135 ---- * @param milisSleep: time to wait after creating the process. * @throws IOException is some error happens creating the sockets - the process is terminated. + * @throws CoreException */ ! public void startIt(int milisSleep) throws IOException, CoreException{ try { *************** *** 136,143 **** if(process != null) endIt(); ! process = Runtime.getRuntime().exec(PydevPrefs.getDefaultInterpreter()+" "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead); boolean connected = false; int attempts = 0; while(!connected && attempts < 20){ attempts += 1; --- 139,149 ---- if(process != null) endIt(); ! String interpreter = getDefaultInterpreter(); ! String execMsg = interpreter+" "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead; ! process = Runtime.getRuntime().exec(execMsg); boolean connected = false; int attempts = 0; + while(!connected && attempts < 20){ attempts += 1; *************** *** 149,155 **** connected = true; } catch (IOException e1) { ! //e1.printStackTrace(); } } } catch (IOException e) { --- 155,168 ---- connected = true; } catch (IOException e1) { ! PydevPlugin.log(IStatus.ERROR, "Error starting server", e1); } } + + if(!connected){ + //what, after all this trouble we are still not connected????!?!?!?! + //let's communicate this to the user... + throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error creating python process ("+execMsg+")", new Exception("Error creating python process."))); + } + } catch (IOException e) { *************** *** 158,162 **** } process = null; - //e.printStackTrace(); throw e; } --- 171,174 ---- *************** *** 164,173 **** /** * 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{ this.startIt(25); } --- 176,197 ---- /** + * @return + */ + protected String getDefaultInterpreter() { + try { + return PydevPrefs.getDefaultInterpreter(); + } catch (RuntimeException e) { + return "python"; + } + } + + + /** * This method creates the python server process and starts the sockets, so that we * can talk with the server. ! * @throws IOException ! * @throws CoreException */ ! public void startIt() throws IOException, CoreException{ this.startIt(25); } *************** *** 237,242 **** return str; } catch (RuntimeException e) { ! System.out.println("ERROR WITH STRING:"+str); ! e.printStackTrace(); return ""; } --- 261,265 ---- return str; } catch (RuntimeException e) { ! PydevPlugin.log(IStatus.ERROR, "ERROR WITH STRING:"+str, e); return ""; } *************** *** 343,347 **** } catch (IOException e) { ! e.printStackTrace(); } } --- 366,370 ---- } catch (IOException e) { ! PydevPlugin.log(IStatus.ERROR, "ERROR sending go to dir msg.", e); } } *************** *** 353,357 **** } catch (IOException e) { ! e.printStackTrace(); } } --- 376,380 ---- } catch (IOException e) { ! PydevPlugin.log(IStatus.ERROR, "ERROR sending reload modules msg.", e); } } *************** *** 359,365 **** /** * @param str * @throws IOException */ ! public List getGlobalCompletions(String str) { str = URLEncoder.encode(str); return this.getTheCompletions("@@GLOBALS:"+str+"\nEND@@"); --- 382,389 ---- /** * @param str + * @throws CoreException * @throws IOException */ ! public List getGlobalCompletions(String str) throws CoreException { str = URLEncoder.encode(str); return this.getTheCompletions("@@GLOBALS:"+str+"\nEND@@"); *************** *** 368,374 **** /** * @param str * @throws IOException */ ! public List getTokenCompletions(String token, String str) { token = URLEncoder.encode(token); str = URLEncoder.encode(str); --- 392,399 ---- /** * @param str + * @throws CoreException * @throws IOException */ ! public List getTokenCompletions(String token, String str) throws CoreException { token = URLEncoder.encode(token); str = URLEncoder.encode(str); *************** *** 381,386 **** * @param docToParse * @return */ ! public List getClassCompletions(String token, String str) { token = URLEncoder.encode(token); str = URLEncoder.encode(str); --- 406,412 ---- * @param docToParse * @return + * @throws CoreException */ ! public List getClassCompletions(String token, String str) throws CoreException { token = URLEncoder.encode(token); str = URLEncoder.encode(str); *************** *** 392,402 **** * @param importsTipper * @return */ ! public List getImportCompletions(String str) { str = URLEncoder.encode(str); return this.getTheCompletions("@@IMPORTS:"+str+"\nEND@@"); } ! private List getTheCompletions(String str){ try { this.write(str); --- 418,429 ---- * @param importsTipper * @return + * @throws CoreException */ ! public List getImportCompletions(String str) throws CoreException { str = URLEncoder.encode(str); return this.getTheCompletions("@@IMPORTS:"+str+"\nEND@@"); } ! private List getTheCompletions(String str) throws CoreException{ try { this.write(str); *************** *** 404,408 **** return getCompletions(); } catch (Exception e) { ! e.printStackTrace(); restartShell(); --- 431,435 ---- return getCompletions(); } catch (Exception e) { ! PydevPlugin.log(IStatus.ERROR, "ERROR getting completions.", e); restartShell(); *************** *** 412,427 **** /** * */ ! public void restartShell() { try { this.endIt(); ! } catch (Exception e2) { ! e2.printStackTrace(); } try { this.startIt(); ! } catch (IOException e2) { ! e2.printStackTrace(); } } --- 439,454 ---- /** + * @throws CoreException * */ ! public void restartShell() throws CoreException { try { this.endIt(); ! } catch (Exception e) { } try { this.startIt(); ! } catch (IOException e) { ! PydevPlugin.log(IStatus.ERROR, "ERROR restarting shell.", e); } } Index: PyCodeCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletion.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PyCodeCompletion.java 22 Sep 2004 16:32:41 -0000 1.10 --- PyCodeCompletion.java 24 Sep 2004 16:41:21 -0000 1.11 *************** *** 65,71 **** * @param theActivationToken * @return */ public List autoComplete(PyEdit edit, IDocument doc, int documentOffset, ! java.lang.String theActivationToken) { List theList = new ArrayList(); PythonShell serverShell = null; --- 65,72 ---- * @param theActivationToken * @return + * @throws CoreException */ public List autoComplete(PyEdit edit, IDocument doc, int documentOffset, ! java.lang.String theActivationToken) throws CoreException { List theList = new ArrayList(); PythonShell serverShell = null; Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonCompletionProcessor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PythonCompletionProcessor.java 23 Sep 2004 18:00:01 -0000 1.8 --- PythonCompletionProcessor.java 24 Sep 2004 16:41:21 -0000 1.9 *************** *** 10,13 **** --- 10,15 ---- import java.util.List; + import org.eclipse.core.runtime.CoreException; + import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; *************** *** 56,123 **** public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { ! IDocument doc = viewer.getDocument(); ! Point selectedRange = viewer.getSelectedRange(); ! // there may not be a selected range ! java.lang.String completeDoc = doc.get(); ! codeCompletion.calcDocBoundary(completeDoc, documentOffset); ! String activationToken = codeCompletion.getActivationToken(completeDoc, documentOffset); ! java.lang.String qualifier = ""; ! //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(new char[] { '.' }, activationToken) == false ! && activationToken.length() > 0) { ! qualifier = activationToken.charAt(activationToken.length() - 1) + qualifier; ! activationToken = activationToken.substring(0, activationToken.length() - 1); } - } else { //everything is a part of the qualifier. - qualifier = activationToken.trim(); - activationToken = ""; - } ! int qlen = qualifier.length(); ! try { ! PythonShell.getServerShell().sendGoToDirMsg(edit.getEditorFile()); ! } catch (Exception e) { ! //if we don't suceed, we don't have to fail... just go on and try ! // to complete... ! e.printStackTrace(); ! } ! List pythonProposals = getPythonProposals(documentOffset, doc, 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); ! Arrays.sort(proposals, proposalsComparator); ! // Return the proposals ! return proposals; } --- 58,130 ---- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { ! try { ! IDocument doc = viewer.getDocument(); ! Point selectedRange = viewer.getSelectedRange(); ! // there may not be a selected range ! java.lang.String completeDoc = doc.get(); ! codeCompletion.calcDocBoundary(completeDoc, documentOffset); ! String activationToken = codeCompletion.getActivationToken(completeDoc, documentOffset); ! java.lang.String qualifier = ""; ! //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(new char[] { '.' }, activationToken) == false ! && activationToken.length() > 0) { ! qualifier = activationToken.charAt(activationToken.length() - 1) + qualifier; ! activationToken = activationToken.substring(0, activationToken.length() - 1); ! } ! } else { //everything is a part of the qualifier. ! qualifier = activationToken.trim(); ! activationToken = ""; } ! int qlen = qualifier.length(); ! try { ! PythonShell.getServerShell().sendGoToDirMsg(edit.getEditorFile()); ! } catch (Exception e) { ! //if we don't suceed, we don't have to fail... just go on and try ! // to complete... ! e.printStackTrace(); ! } ! List pythonProposals = getPythonProposals(documentOffset, doc, 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); + Arrays.sort(proposals, proposalsComparator); + // Return the proposals + return proposals; + } catch (CoreException e) { + + ErrorDialog.openError(null,"Error", "Error", e.getStatus()); + } + return new ICompletionProposal[0]; } *************** *** 129,134 **** * @param qlen * @return */ ! private List getPythonProposals(int documentOffset, IDocument doc, String activationToken, int qlen) { List allProposals = this.completionCache.getAllProposals(edit, doc, activationToken, documentOffset, qlen, codeCompletion); --- 136,142 ---- * @param qlen * @return + * @throws CoreException */ ! private List getPythonProposals(int documentOffset, IDocument doc, String activationToken, int qlen) throws CoreException { List allProposals = this.completionCache.getAllProposals(edit, doc, activationToken, documentOffset, qlen, codeCompletion); Index: CompletionCache.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/CompletionCache.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CompletionCache.java 22 Sep 2004 16:32:41 -0000 1.5 --- CompletionCache.java 24 Sep 2004 16:41:21 -0000 1.6 *************** *** 12,15 **** --- 12,16 ---- import java.util.Map; + import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.CompletionProposal; *************** *** 36,43 **** * @param codeCompletion * @return */ public List getAllProposals(PyEdit edit, IDocument doc, String activationToken, int documentOffset, int qlen, ! PyCodeCompletion codeCompletion) { String importsTipperStr = codeCompletion.getImportsTipperStr(activationToken, edit, doc, documentOffset); --- 37,45 ---- * @param codeCompletion * @return + * @throws CoreException */ public List getAllProposals(PyEdit edit, IDocument doc, String activationToken, int documentOffset, int qlen, ! PyCodeCompletion codeCompletion) throws CoreException { String importsTipperStr = codeCompletion.getImportsTipperStr(activationToken, edit, doc, documentOffset); |