[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion PythonShell.java,1.4,1.5 Pyt
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-15 17:36:18
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25438/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java PythonCompletionProcessor.java Log Message: Making refactoring. Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PythonShell.java 14 Sep 2004 17:42:14 -0000 1.4 --- PythonShell.java 15 Sep 2004 17:36:09 -0000 1.5 *************** *** 40,48 **** } return pytonShell; - } ! public static final int BUFFER_SIZE = 1024 * 4; /** * Python server process. --- 40,47 ---- } return pytonShell; } ! public static final int BUFFER_SIZE = 1024 ; /** * Python server process. *************** *** 134,142 **** process = Runtime.getRuntime().exec("python "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead); ! sleepALittle(); ! ! socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port ! serverSocket = new ServerSocket(pRead); //and read in this port ! socketToRead = serverSocket.accept(); } catch (IOException e) { --- 133,150 ---- process = Runtime.getRuntime().exec("python "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead); ! boolean connected = false; ! int attempts = 0; ! while(!connected && attempts < 20){ ! attempts += 1; ! sleepALittle(); ! try { ! socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port ! serverSocket = new ServerSocket(pRead); //and read in this port ! socketToRead = serverSocket.accept(); ! connected = true; ! } catch (IOException e1) { ! e1.printStackTrace(); ! } ! } } catch (IOException e) { *************** *** 144,147 **** --- 152,156 ---- process.destroy(); } + process = null; e.printStackTrace(); throw e; *************** *** 158,177 **** int j = 0; ! while(str.indexOf("END@@") == -1 && j != 100){ byte[] b = new byte[PythonShell.BUFFER_SIZE]; this.socketToRead.getInputStream().read(b); ! // System.out.println("READ:"+new String(b)); String s = new String(b); ! str += s; ! j++; } //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ ! return str.substring(0, str.lastIndexOf("END@@")); } --- 167,210 ---- int j = 0; ! while(j != 100){ byte[] b = new byte[PythonShell.BUFFER_SIZE]; + // System.out.println("WILL READ"); this.socketToRead.getInputStream().read(b); ! // System.out.println("READ"); String s = new String(b); ! if(s.indexOf("@@PROCESSING_END@@") != -1){ //each time we get a processing message, reset j to 0. ! s = s.replaceAll("@@PROCESSING_END@@", ""); ! j = 0; ! // System.out.println("Processing msg received."); ! } ! s = s.replaceAll((char)0+"",""); //python sends this char as payload. ! System.out.println("RECEIVED:"+s); str += s; ! ! if(str.indexOf("END@@") != -1){ ! // System.out.println("WILL BREAK"); ! break; ! }else{ ! // System.out.println("WILL SLEEP"); ! j++; ! sleepALittle(10); ! } ! } + // System.out.println("OUT"); //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ ! ! try { ! return str.substring(0, str.lastIndexOf("END@@")); ! } catch (RuntimeException e) { ! System.out.println("ERROR WIT STRING:"+str); ! e.printStackTrace(); ! return ""; ! } } *************** *** 182,186 **** */ public void write(String str) throws IOException { - // System.out.println("WRITING:"+str); this.socketToWrite.getOutputStream().write(str.getBytes()); } --- 215,218 ---- *************** *** 213,225 **** * @throws IOException */ ! void endIt() { try { closeConn(); ! } catch (IOException e) { e.printStackTrace(); } if (process!= null){ try { int i = process.getErrorStream().available(); byte b[] = new byte[i]; --- 245,259 ---- * @throws IOException */ ! public void endIt() { try { closeConn(); ! } catch (Exception e) { e.printStackTrace(); } if (process!= null){ try { + + process.getOutputStream().close(); int i = process.getErrorStream().available(); byte b[] = new byte[i]; *************** *** 229,233 **** i = process.getInputStream().available(); b = new byte[i]; ! process.getErrorStream().read(b); System.out.println(new String(b)); } catch (Exception e1) { --- 263,267 ---- i = process.getInputStream().available(); b = new byte[i]; ! process.getInputStream().read(b); System.out.println(new String(b)); } catch (Exception e1) { *************** *** 256,260 **** file = file.getParentFile(); } - System.out.println("changing dir:"+file.getAbsolutePath()); this.write("@@CHANGE_DIR:"+file.getAbsolutePath()+"END@@"); String ok = this.read(); //this should be the ok message... --- 290,293 ---- *************** *** 310,319 **** e.printStackTrace(); ! this.endIt(); ! try { ! this.startIt(); ! } catch (IOException e2) { ! e2.printStackTrace(); ! } return getInvalidCompletion(); } --- 343,347 ---- e.printStackTrace(); ! restartShell(); return getInvalidCompletion(); } *************** *** 321,324 **** --- 349,369 ---- /** + * + */ + public void restartShell() { + try { + this.endIt(); + } catch (Exception e2) { + e2.printStackTrace(); + } + try { + this.startIt(); + } catch (IOException e2) { + e2.printStackTrace(); + } + } + + + /** * @return */ Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonCompletionProcessor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PythonCompletionProcessor.java 14 Sep 2004 17:42:14 -0000 1.5 --- PythonCompletionProcessor.java 15 Sep 2004 17:36:09 -0000 1.6 *************** *** 85,89 **** } }else{ //everything is a part of the qualifier. ! qualifier = activationToken; activationToken = ""; } --- 85,89 ---- } }else{ //everything is a part of the qualifier. ! qualifier = activationToken.trim(); activationToken = ""; } *************** *** 153,157 **** 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, --- 153,157 ---- private List getTemplateProposals(ITextViewer viewer, int documentOffset, String activationToken, java.lang.String qualifier, List allProposals) { List propList = new ArrayList(); ! if(activationToken.trim().equals("") == false || qualifier.trim().equals("") == false){ //templates proposals are added here. this.templatesCompletion.addTemplateProposals(viewer, documentOffset, |