forked from VimPlug/jedi
added magic function names to completion, fixes nothing, but makes jedi more awesome :-D
This commit is contained in:
@@ -108,9 +108,9 @@ class Script(object):
|
|||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible scopes', scopes)
|
debug.dbg('possible scopes', scopes)
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
# TODO is this really the right way? just ignore the funcs? \
|
if s.isinstance(evaluate.Function):
|
||||||
# do the magic functions first? and then recheck here?
|
names = s.get_magic_method_names()
|
||||||
if not s.isinstance(evaluate.Function):
|
else:
|
||||||
if isinstance(s, imports.ImportPath):
|
if isinstance(s, imports.ImportPath):
|
||||||
if like == 'import':
|
if like == 'import':
|
||||||
l = self.module.get_line(self.pos[0])[:self.pos[1]]
|
l = self.module.get_line(self.pos[0])[:self.pos[1]]
|
||||||
@@ -119,6 +119,7 @@ class Script(object):
|
|||||||
names = s.get_defined_names(on_import_stmt=True)
|
names = s.get_defined_names(on_import_stmt=True)
|
||||||
else:
|
else:
|
||||||
names = s.get_defined_names()
|
names = s.get_defined_names()
|
||||||
|
|
||||||
for c in names:
|
for c in names:
|
||||||
completions.append((c, s))
|
completions.append((c, s))
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import sys
|
|||||||
import os
|
import os
|
||||||
if is_py3k:
|
if is_py3k:
|
||||||
import io
|
import io
|
||||||
else:
|
|
||||||
import types
|
import types
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import debug
|
import debug
|
||||||
import parsing
|
import parsing
|
||||||
import imports
|
import imports
|
||||||
|
import evaluate
|
||||||
|
|
||||||
|
|
||||||
def get_sys_path():
|
def get_sys_path():
|
||||||
@@ -157,7 +157,7 @@ class Parser(CachedModule):
|
|||||||
|
|
||||||
def _get_source(self):
|
def _get_source(self):
|
||||||
""" Override this abstract method """
|
""" Override this abstract method """
|
||||||
return self._generate_code(self.module, self._load_mixins())
|
return _generate_code(self.module, self._load_mixins())
|
||||||
|
|
||||||
def _load_mixins(self):
|
def _load_mixins(self):
|
||||||
"""
|
"""
|
||||||
@@ -211,7 +211,8 @@ class Parser(CachedModule):
|
|||||||
mixin_dct['range'] = mixin_dct['xrange']
|
mixin_dct['range'] = mixin_dct['xrange']
|
||||||
return mixin_dct
|
return mixin_dct
|
||||||
|
|
||||||
def _generate_code(self, scope, mixin_funcs, depth=0):
|
|
||||||
|
def _generate_code(scope, mixin_funcs={}, depth=0):
|
||||||
"""
|
"""
|
||||||
Generate a string, which uses python syntax as an input to the
|
Generate a string, which uses python syntax as an input to the
|
||||||
PyFuzzyParser.
|
PyFuzzyParser.
|
||||||
@@ -301,7 +302,7 @@ class Parser(CachedModule):
|
|||||||
mixin = mixin_funcs[name]
|
mixin = mixin_funcs[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
mixin = {}
|
mixin = {}
|
||||||
cl_code = self._generate_code(cl, mixin, depth + 1)
|
cl_code = _generate_code(cl, mixin, depth + 1)
|
||||||
code += parsing.indent_block(cl_code)
|
code += parsing.indent_block(cl_code)
|
||||||
code += '\n'
|
code += '\n'
|
||||||
|
|
||||||
@@ -450,4 +451,23 @@ class Builtin(object):
|
|||||||
def scope(self):
|
def scope(self):
|
||||||
return self.builtin.parser.module
|
return self.builtin.parser.module
|
||||||
|
|
||||||
|
@property
|
||||||
|
def magic_function_names(self):
|
||||||
|
try:
|
||||||
|
return self._magic_function_names
|
||||||
|
except AttributeError:
|
||||||
|
# depth = 1 because this is not a module
|
||||||
|
class Container(object):
|
||||||
|
FunctionType = types.FunctionType
|
||||||
|
source = _generate_code(Container, depth=0)
|
||||||
|
parser = parsing.PyFuzzyParser(source, None)
|
||||||
|
# needed for caching (because of weakref)
|
||||||
|
module = self.magic_func_module = parser.module
|
||||||
|
typ = evaluate.follow_path(iter(['FunctionType']), module, module)
|
||||||
|
|
||||||
|
names = typ.pop().get_defined_names()
|
||||||
|
self._magic_function_names = names
|
||||||
|
return names
|
||||||
|
|
||||||
|
|
||||||
Builtin = Builtin()
|
Builtin = Builtin()
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ class Function(use_metaclass(CachedMetaClass, parsing.Base)):
|
|||||||
return self
|
return self
|
||||||
return self._decorated_func
|
return self._decorated_func
|
||||||
|
|
||||||
|
def get_magic_method_names(self):
|
||||||
|
return builtin.Builtin.magic_function_names
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.base_func, name)
|
return getattr(self.base_func, name)
|
||||||
|
|
||||||
@@ -1561,10 +1564,8 @@ def follow_path(path, scope, call_scope, position=None):
|
|||||||
else:
|
else:
|
||||||
# The function must not be decorated with something else.
|
# The function must not be decorated with something else.
|
||||||
if scope.isinstance(Function):
|
if scope.isinstance(Function):
|
||||||
# TODO Check default function methods and return them.
|
result = scope.get_magic_method_names()
|
||||||
result = []
|
|
||||||
else:
|
else:
|
||||||
# TODO Check magic class methods and return them also.
|
|
||||||
# This is the typical lookup while chaining things.
|
# This is the typical lookup while chaining things.
|
||||||
if filter_private_variable(scope, call_scope, current):
|
if filter_private_variable(scope, call_scope, current):
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -350,3 +350,10 @@ def annot_ret(a:3) -> 3:
|
|||||||
|
|
||||||
#? str()
|
#? str()
|
||||||
annot_ret('')
|
annot_ret('')
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# magic methods
|
||||||
|
# -----------------
|
||||||
|
def a(): pass
|
||||||
|
#? ['__closure__']
|
||||||
|
a.__closure__
|
||||||
|
|||||||
Reference in New Issue
Block a user