[Pydev-cvs] org.python.pydev/PySrc importsTipper.py,NONE,1.1 refactoring.py,NONE,1.1 pycompletionser
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-14 17:42:48
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9579/PySrc Modified Files: pycompletionserver.py simpleTipper.py test_pyserver.py test_simpleTipper.py Added Files: importsTipper.py refactoring.py Log Message: Code completion improvements. Starting refactoring integration with bicycle repair man. Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pycompletionserver.py 13 Sep 2004 19:47:54 -0000 1.5 --- pycompletionserver.py 14 Sep 2004 17:42:07 -0000 1.6 *************** *** 8,12 **** HOST = '127.0.0.1' # Symbolic name meaning the local host - MSG_KILL_SERVER = '@@KILL_SERVER_END@@' MSG_COMPLETIONS = '@@COMPLETIONS' --- 8,11 ---- *************** *** 16,21 **** MSG_CLASS_GLOBALS = '@@CLASS_GLOBALS(' MSG_INVALID_REQUEST = '@@INVALID_REQUEST' ! BUFFER_SIZE = 1024 class T(threading.Thread): --- 15,23 ---- MSG_CLASS_GLOBALS = '@@CLASS_GLOBALS(' MSG_INVALID_REQUEST = '@@INVALID_REQUEST' + MSG_RELOAD_MODULES = '@@RELOAD_MODULES_END@@' + MSG_CHANGE_DIR = '@@CHANGE_DIR:' + MSG_OK = '@@MSG_OK_END@@' ! BUFFER_SIZE = 1024 * 4 class T(threading.Thread): *************** *** 62,65 **** --- 64,70 ---- self.socket.send(MSG_INVALID_REQUEST) + def sendOkMsg(self): + self.socket.send(MSG_OK) + def getTokenAndData(self, data): ''' *************** *** 99,132 **** data = '' while not data.endswith(MSG_END): ! data += conn.recv(BUFFER_SIZE) if MSG_KILL_SERVER in data: #break if we received kill message. break; - else: - data = data.rstrip(MSG_END) - - if MSG_GLOBALS in data: - data = data.replace(MSG_GLOBALS, '') - comps = simpleTipper.GenerateTip(data, None, False) - self.sendCompletionsMessage(comps) - - elif MSG_TOKEN_GLOBALS in data: - data = data.replace(MSG_TOKEN_GLOBALS, '') - token, data = self.getTokenAndData(data) - comps = simpleTipper.GenerateTip(data, token, False) - self.sendCompletionsMessage(comps) ! elif MSG_CLASS_GLOBALS in data: ! data = data.replace(MSG_CLASS_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) ! self.sendCompletionsMessage(comps) else: ! self.sendReceivedInvalidMessage() - conn.send(data) conn.close() --- 104,145 ---- data = '' while not data.endswith(MSG_END): ! data+=conn.recv(BUFFER_SIZE) if MSG_KILL_SERVER in data: #break if we received kill message. break; ! elif MSG_RELOAD_MODULES in data: ! simpleTipper.ReloadModules() ! self.sendOkMsg() else: ! data = data[:data.find(MSG_END)] + if MSG_GLOBALS in data: + data = data.replace(MSG_GLOBALS, '') + comps = simpleTipper.GenerateTip(data, None, False) + self.sendCompletionsMessage(comps) + + elif MSG_TOKEN_GLOBALS in data: + data = data.replace(MSG_TOKEN_GLOBALS, '') + token, data = self.getTokenAndData(data) + comps = simpleTipper.GenerateTip(data, token, False) + self.sendCompletionsMessage(comps) + + elif MSG_CLASS_GLOBALS in data: + data = data.replace(MSG_CLASS_GLOBALS, '') + token, data = self.getTokenAndData(data) + comps = simpleTipper.GenerateTip(data, token, True) + self.sendCompletionsMessage(comps) + + elif MSG_CHANGE_DIR in data: + data = data.replace(MSG_CHANGE_DIR, '') + simpleTipper.CompleteFromDir(data) + self.sendOkMsg() + + else: + self.sendReceivedInvalidMessage() conn.close() Index: simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleTipper.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** simpleTipper.py 13 Sep 2004 19:47:54 -0000 1.3 --- simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.4 *************** *** 3,7 **** --- 3,35 ---- ''' import compiler + import sys + + __eraseThisCurrDirModule = None + def CompleteFromDir(dir): + ''' + This is necessary so that we get the imports from the same dir where the file + we are completing is located. + ''' + global __eraseThisCurrDirModule + if __eraseThisCurrDirModule is not None: + del sys.path[__eraseThisCurrDirModule] + + sys.path.insert(0, dir) + + def GenerateImportsTip(theDoc): + pass + + def ReloadModules(): + ''' + Reload all the modules in sys.modules + ''' + import sys + for m,n in sys.modules.items(): + try: + reload(n) + except: #some errors may arise because some modules may not be reloaded... + pass + def GenerateTip (theDoc, token, checkForSelf): ''' *************** *** 37,47 **** for d in dir(%s): __eraseThisTips.append([d,inspect.getdoc(getattr(%s, d))]) ! ''' % (token,token) import simpleinspect try: __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') simpleinspect.__eraseThisTips = [] --- 65,78 ---- for d in dir(%s): __eraseThisTips.append([d,inspect.getdoc(getattr(%s, d))]) ! ''' % (token.replace(' ','.'),token.replace(' ','.')) import simpleinspect + __eraseThisMsg = '' try: + __eraseThisMsg += 'Compiling \n%s\n'%theDoc __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') + __eraseThisMsg += 'Compiled' simpleinspect.__eraseThisTips = [] *************** *** 50,53 **** --- 81,85 ---- simpleinspect.__eraseThisTips = [] + __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc if checkForSelf: toReturn += GetSelfVariables(originalDoc, token) *************** *** 57,62 **** import sys s = str(sys.exc_info()[1]) ! print s ! return [('ERROR_COMPLETING',s)] class Visitor(compiler.visitor.ASTVisitor): --- 89,93 ---- import sys s = str(sys.exc_info()[1]) ! return [('ERROR_COMPLETING','%s\nerror tracing:\n%s'%(s,__eraseThisMsg))] class Visitor(compiler.visitor.ASTVisitor): Index: test_pyserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_pyserver.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_pyserver.py 13 Sep 2004 19:47:54 -0000 1.3 --- test_pyserver.py 14 Sep 2004 17:42:07 -0000 1.4 *************** *** 6,9 **** --- 6,10 ---- import pycompletionserver import socket + import os class Test(unittest.TestCase): *************** *** 88,91 **** --- 89,117 ---- self.assert_(len(completions) != len(completions2)) + + #reload modules test + # sToWrite.send('@@RELOAD_MODULES_END@@') + # ok = connToRead.recv(4086) + # self.assertEquals('@@MSG_OK_END@@' , ok) + # this test is not executed because it breaks our current enviroment. + + + + #change dir test + curr = os.getcwd( ) + newDir = None + + if curr.find('/') != -1: + newDir = curr[0:curr.rindex('/')] + elif curr.find('\\') != -1: + newDir = curr[0:curr.rindex('\\')] + + self.assert_(newDir != None) + sToWrite.send('@@CHANGE_DIR:%sEND@@'%newDir) + ok = connToRead.recv(4086) + self.assertEquals('@@MSG_OK_END@@' , ok) + sToWrite.send('@@TOKEN_GLOBALS(math acos):import math\nEND@@') + completions = connToRead.recv(4086) + self.sendKillMsg(sToWrite) *************** *** 104,105 **** --- 130,132 ---- if __name__ == '__main__': unittest.main() + --- NEW FILE: refactoring.py --- import sys import os sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), "ThirdParty", "brm")) import ThirdParty.brm.bike as bike class Refactoring(object): def __init__(self): self.init() def init(self): """ Private slot to handle the Reset action. """ self.brmctx = bike.init() self.logging = Preferences.getRefactoring("Logging") if self.logging: self.brmctx.setProgressLogger(self.ui.stdout) else: self.brmctx.setProgressLogger(SilentLogger()) self.brmctx.setWarningLogger(self.ui.stderr) def handleReset(self): """ Private slot to handle the Reset action. """ self.init() Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_simpleTipper.py 13 Sep 2004 19:47:54 -0000 1.2 --- test_simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.3 *************** *** 5,9 **** import unittest import simpleTipper ! class Test(unittest.TestCase): --- 5,10 ---- import unittest import simpleTipper ! import importsTipper ! class Test(unittest.TestCase): *************** *** 95,99 **** --- 96,111 ---- + def getDoc3(self): + pass + + def testImports(self): + raise RuntimeError('not implemented') + importsTipper.GenerateImportsTip(0) + + + + + if __name__ == '__main__': unittest.main() --- NEW FILE: importsTipper.py --- def GenerateImportsTip(theDoc): pass |