[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion PyCodeCompletion.java,1.2,1.
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-08-16 20:55:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31791/src/org/python/pydev/editor/codecompletion Modified Files: PyCodeCompletion.java Log Message: Now we don't write/ read the file anymore. Index: PyCodeCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletion.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyCodeCompletion.java 11 Aug 2004 17:44:16 -0000 1.2 --- PyCodeCompletion.java 16 Aug 2004 20:55:31 -0000 1.3 *************** *** 7,16 **** import java.io.BufferedReader; - import java.io.BufferedWriter; import java.io.File; - import java.io.FileWriter; import java.io.IOException; - import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; --- 7,14 ---- import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; + import java.io.OutputStreamWriter; import java.net.URL; import java.util.ArrayList; *************** *** 64,73 **** java.lang.String theActivationToken) { List theList = new ArrayList(); ! String s = new String(); ! File tmp = null; ! // System.out.println("DBG:autoComplete:theActivationToken: "+theActivationToken); try { ! // get the inspect.py file from the package: ! s = getAutoCompleteScript(); } catch (CoreException e) { --- 62,69 ---- java.lang.String theActivationToken) { List theList = new ArrayList(); ! File tipperFile=null; ! try { ! tipperFile = getAutoCompleteScript(); } catch (CoreException e) { *************** *** 77,99 **** try { ! //We actually write a file with all of our code to a temporary location, ! //so that we can get its code completion from the typper.py script. ! // ! //TODO: there must be a faster strategy... ! // ! tmp = bufferContent(theCode); ! ! if (tmp == null) { ! System.out.println("DBG:bufferContent() null. No tip for you!!"); ! return theList; ! } ! String ss = new String("python " + s + " " + tmp.getAbsolutePath()); ! ! Process p = Runtime.getRuntime().exec(ss); BufferedReader in = new BufferedReader(new InputStreamReader(p .getInputStream())); String str; ! while ((str = in.readLine()) != null) { if (!str.startsWith("tip: ")){ continue; --- 73,107 ---- try { ! Process p = Runtime.getRuntime().exec(new String[]{"python"}); ! //we have the process... ! OutputStreamWriter writer = new OutputStreamWriter(p.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(p .getInputStream())); + BufferedReader eIn = new BufferedReader(new InputStreamReader( + p.getErrorStream())); + + //we have to put the tipper in sys.path + writer.write("import sys\n"); + 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"); + + theCode = theCode.replaceAll("\r",""); + theCode = theCode.replaceAll("\n","\\\\n"); + + theCode = theCode.replaceAll("'","@l@l@*"); //TODO: that's a really bad way to do it... + + writer.write("s = '"+theCode+"'\n"); + writer.write("s = s.replace('@l@l@*', '\\'')\n"); + + writer.write("GenerateTip(s)\n\n\n"); + + writer.flush(); + writer.close(); + String str; ! while ((str = in.readLine()) != null) { if (!str.startsWith("tip: ")){ continue; *************** *** 105,115 **** } in.close(); - InputStream eInput = p.getErrorStream(); - BufferedReader eIn = new BufferedReader(new InputStreamReader( - eInput)); while ((str = eIn.readLine()) != null) { ! //System.out.println("error output: " + str); } p.waitFor(); } catch (IOException e) { --- 113,121 ---- } in.close(); while ((str = eIn.readLine()) != null) { ! // System.out.println("error output: " + str); } + eIn.close(); p.waitFor(); } catch (IOException e) { *************** *** 123,150 **** } - /** - * We actually write a file with all of our code to a temporary location, - * so that we can get its code completion from the typper.py script. - * - * @param theCode code to be written to file. - */ - private File bufferContent(java.lang.String theCode) { - // - try { - // Create temp file. - File temp = File.createTempFile("PyDev", ".tmp"); - - // Delete temp file when program exits. - temp.deleteOnExit(); - - // Write to temp file - BufferedWriter out = new BufferedWriter(new FileWriter(temp)); - out.write(theCode); - out.close(); - return temp; - } catch (IOException e) { - return null; - } - } /** --- 129,132 ---- *************** *** 154,158 **** * @throws CoreException */ ! public static String getAutoCompleteScript() throws CoreException { String targetExec = "tipper.py"; --- 136,140 ---- * @throws CoreException */ ! public static File getAutoCompleteScript() throws CoreException { String targetExec = "tipper.py"; *************** *** 166,172 **** try { fileURL = Platform.asLocalURL(bundleURL); ! String filePath = new File(fileURL.getPath()).getAbsolutePath(); ! return filePath; } catch (IOException e) { throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, --- 148,154 ---- try { fileURL = Platform.asLocalURL(bundleURL); ! File f = new File(fileURL.getPath()); ! return f; } catch (IOException e) { throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, |