mirror of
https://github.com/cemu-project/idapython.git
synced 2024-12-02 22:14:18 +01:00
command completion will propose '(' for callables and '[' for iterables
This commit is contained in:
parent
67c94b2f02
commit
40d46c34a9
@ -3,6 +3,7 @@
|
|||||||
#pragma SWIG nowarn=302
|
#pragma SWIG nowarn=302
|
||||||
// and others...
|
// and others...
|
||||||
#pragma SWIG nowarn=312
|
#pragma SWIG nowarn=312
|
||||||
|
#pragma SWIG nowarn=325
|
||||||
#pragma SWIG nowarn=314
|
#pragma SWIG nowarn=314
|
||||||
#pragma SWIG nowarn=362
|
#pragma SWIG nowarn=362
|
||||||
#pragma SWIG nowarn=383
|
#pragma SWIG nowarn=383
|
||||||
@ -1156,6 +1157,7 @@ public:
|
|||||||
Py_DECREF(py_code);
|
Py_DECREF(py_code);
|
||||||
if ( PyW_GetError(&err) || py_result == NULL )
|
if ( PyW_GetError(&err) || py_result == NULL )
|
||||||
{
|
{
|
||||||
|
PyErr_Clear();
|
||||||
warning("notify_when(): Error occured while notifying object.\n%s", err.c_str());
|
warning("notify_when(): Error occured while notifying object.\n%s", err.c_str());
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
@ -1193,9 +1195,11 @@ bool pywraps_nw_init()
|
|||||||
{
|
{
|
||||||
if ( g_nw != NULL )
|
if ( g_nw != NULL )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
g_nw = new pywraps_notify_when_t();
|
g_nw = new pywraps_notify_when_t();
|
||||||
if ( g_nw->init() )
|
if ( g_nw->init() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Things went bad, undo!
|
// Things went bad, undo!
|
||||||
delete g_nw;
|
delete g_nw;
|
||||||
g_nw = NULL;
|
g_nw = NULL;
|
||||||
@ -1207,10 +1211,12 @@ bool pywraps_nw_notify(int slot, ...)
|
|||||||
{
|
{
|
||||||
if ( g_nw == NULL )
|
if ( g_nw == NULL )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, slot);
|
va_start(va, slot);
|
||||||
bool ok = g_nw->notify_va(slot, va);
|
bool ok = g_nw->notify_va(slot, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1220,9 +1226,11 @@ bool pywraps_nw_term()
|
|||||||
{
|
{
|
||||||
if ( g_nw == NULL )
|
if ( g_nw == NULL )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// If could not deinitialize then return w/o stopping nw
|
// If could not deinitialize then return w/o stopping nw
|
||||||
if ( !g_nw->deinit() )
|
if ( !g_nw->deinit() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
delete g_nw;
|
delete g_nw;
|
||||||
g_nw = NULL;
|
g_nw = NULL;
|
||||||
@ -1944,6 +1952,7 @@ class __IDAPython_Completion_Util(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.n = 0
|
self.n = 0
|
||||||
self.completion = None
|
self.completion = None
|
||||||
|
self.lastmodule = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_identifier(line, prefix, prefix_start):
|
def parse_identifier(line, prefix, prefix_start):
|
||||||
@ -1958,33 +1967,54 @@ class __IDAPython_Completion_Util(object):
|
|||||||
|
|
||||||
return line[id_start:prefix_start + len(prefix)]
|
return line[id_start:prefix_start + len(prefix)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def dir_of(m, prefix):
|
||||||
|
return [x for x in dir(m) if x.startswith(prefix)]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_completion(id, prefix):
|
def get_completion(id, prefix):
|
||||||
try:
|
try:
|
||||||
parts = id.split('.')
|
|
||||||
m = sys.modules['__main__']
|
m = sys.modules['__main__']
|
||||||
|
|
||||||
|
parts = id.split('.')
|
||||||
c = len(parts)
|
c = len(parts)
|
||||||
|
|
||||||
for i in xrange(0, c-1):
|
for i in xrange(0, c-1):
|
||||||
m = getattr(m, parts[i])
|
m = getattr(m, parts[i])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return None
|
return (None, None)
|
||||||
else:
|
else:
|
||||||
# search in the module
|
# search in the module
|
||||||
completion = [x for x in dir(m) if x.startswith(prefix)]
|
completion = __IDAPython_Completion_Util.dir_of(m, prefix)
|
||||||
|
|
||||||
# no completion found? looking from the global scope? then try the builtins
|
# no completion found? looking from the global scope? then try the builtins
|
||||||
if not completion and c == 1:
|
if not completion and c == 1:
|
||||||
completion = [x for x in dir(__builtin__) if x.startswith(prefix)]
|
completion = __IDAPython_Completion_Util.dir_of(__builtin__, prefix)
|
||||||
|
|
||||||
return completion if len(completion) else None
|
return (m, completion) if completion else (None, None)
|
||||||
|
|
||||||
def __call__(self, prefix, n, line, prefix_start):
|
def __call__(self, prefix, n, line, prefix_start):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
self.n = n
|
self.n = n
|
||||||
id = self.parse_identifier(line, prefix, prefix_start)
|
id = self.parse_identifier(line, prefix, prefix_start)
|
||||||
self.completion = self.get_completion(id, prefix)
|
self.lastmodule, self.completion = self.get_completion(id, prefix)
|
||||||
return None if self.completion is None or n >= len(self.completion) else self.completion[n]
|
|
||||||
|
|
||||||
|
if self.completion is None or n >= len(self.completion):
|
||||||
|
return None
|
||||||
|
|
||||||
|
s = self.completion[n]
|
||||||
|
try:
|
||||||
|
attr = getattr(self.lastmodule, s)
|
||||||
|
# is it callable?
|
||||||
|
if callable(attr):
|
||||||
|
return s + "("
|
||||||
|
# is it iterable?
|
||||||
|
elif isinstance(attr, basestring) or getattr(attr, '__iter__', False):
|
||||||
|
return s + "["
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return s
|
||||||
|
|
||||||
IDAPython_Completion = __IDAPython_Completion_Util()
|
IDAPython_Completion = __IDAPython_Completion_Util()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user