forked from VimPlug/jedi
Quite a few fixes to be eventually able to use NameParts as Definition inputs.
This commit is contained in:
@@ -143,12 +143,12 @@ class BaseDefinition(object):
|
|||||||
"""
|
"""
|
||||||
# generate the type
|
# generate the type
|
||||||
stripped = self._definition
|
stripped = self._definition
|
||||||
if isinstance(stripped, compiled.CompiledObject):
|
|
||||||
return stripped.type()
|
|
||||||
if isinstance(stripped, er.InstanceElement):
|
if isinstance(stripped, er.InstanceElement):
|
||||||
stripped = stripped.var
|
stripped = stripped.var
|
||||||
if isinstance(stripped, (pr.Name, pr.NamePart)):
|
if isinstance(stripped, (pr.Name, pr.NamePart)):
|
||||||
stripped = stripped.get_definition()
|
stripped = stripped.get_definition()
|
||||||
|
if isinstance(stripped, compiled.CompiledObject):
|
||||||
|
return stripped.type()
|
||||||
if isinstance(stripped, iterable.Array):
|
if isinstance(stripped, iterable.Array):
|
||||||
return 'instance'
|
return 'instance'
|
||||||
string = type(stripped).__name__.lower().replace('wrapper', '')
|
string = type(stripped).__name__.lower().replace('wrapper', '')
|
||||||
@@ -246,10 +246,13 @@ class BaseDefinition(object):
|
|||||||
Document for function f.
|
Document for function f.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
definition = self._definition
|
||||||
|
if isinstance(definition, pr.NamePart):
|
||||||
|
definition = definition.parent.parent
|
||||||
if raw:
|
if raw:
|
||||||
return _Help(self._definition).raw()
|
return _Help(definition).raw()
|
||||||
else:
|
else:
|
||||||
return _Help(self._definition).full()
|
return _Help(definition).full()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def doc(self):
|
def doc(self):
|
||||||
@@ -504,9 +507,8 @@ class Completion(BaseDefinition):
|
|||||||
the ``foo.docstring(fast=False)`` on every object, because it
|
the ``foo.docstring(fast=False)`` on every object, because it
|
||||||
parses all libraries starting with ``a``.
|
parses all libraries starting with ``a``.
|
||||||
"""
|
"""
|
||||||
definition = self._definition
|
if isinstance(definition, pr.Import):
|
||||||
if isinstance(self._definition, pr.Import):
|
i = imports.ImportWrapper(self._evaluator, definition)
|
||||||
i = imports.ImportWrapper(self._evaluator, self._definition)
|
|
||||||
if len(i.import_path) > 1 or not fast:
|
if len(i.import_path) > 1 or not fast:
|
||||||
followed = self._follow_statements_imports()
|
followed = self._follow_statements_imports()
|
||||||
if followed:
|
if followed:
|
||||||
|
|||||||
@@ -326,6 +326,12 @@ class Wrapper(pr.Base):
|
|||||||
def is_class(self):
|
def is_class(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
@underscore_memoization
|
||||||
|
def name(self):
|
||||||
|
name = self.base.name
|
||||||
|
return helpers.FakeName(unicode(name), self, name.start_pos)
|
||||||
|
|
||||||
|
|
||||||
class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
||||||
"""
|
"""
|
||||||
@@ -406,10 +412,6 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
return sub
|
return sub
|
||||||
raise KeyError("Couldn't find subscope.")
|
raise KeyError("Couldn't find subscope.")
|
||||||
|
|
||||||
@common.safe_property
|
|
||||||
def name(self):
|
|
||||||
return self.base.name
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name not in ['start_pos', 'end_pos', 'parent', 'asserts', 'raw_doc',
|
if name not in ['start_pos', 'end_pos', 'parent', 'asserts', 'raw_doc',
|
||||||
'doc', 'get_imports', 'get_parent_until', 'get_code',
|
'doc', 'get_imports', 'get_parent_until', 'get_code',
|
||||||
@@ -428,7 +430,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
def __init__(self, evaluator, func, is_decorated=False):
|
def __init__(self, evaluator, func, is_decorated=False):
|
||||||
""" This should not be called directly """
|
""" This should not be called directly """
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self.base_func = func
|
self.base = self.base_func = func
|
||||||
self.is_decorated = is_decorated
|
self.is_decorated = is_decorated
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
@@ -635,7 +637,7 @@ class FunctionExecution(Executed):
|
|||||||
class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
||||||
def __init__(self, evaluator, module):
|
def __init__(self, evaluator, module):
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self._module = module
|
self.base = self._module = module
|
||||||
|
|
||||||
def scope_names_generator(self, position=None):
|
def scope_names_generator(self, position=None):
|
||||||
yield self, pr.filter_after_position(self._module.get_defined_names(), position)
|
yield self, pr.filter_after_position(self._module.get_defined_names(), position)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from jedi import Script
|
|||||||
|
|
||||||
def get_definition_and_evaluator(source):
|
def get_definition_and_evaluator(source):
|
||||||
d = Script(dedent(source)).goto_definitions()[0]
|
d = Script(dedent(source)).goto_definitions()[0]
|
||||||
return d._definition, d._evaluator
|
return d._definition.parent.parent, d._evaluator
|
||||||
|
|
||||||
|
|
||||||
def test_function_execution():
|
def test_function_execution():
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ asdfasdf""" + "h"
|
|||||||
def test_tokenizer_with_string_literal_backslash():
|
def test_tokenizer_with_string_literal_backslash():
|
||||||
import jedi
|
import jedi
|
||||||
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
|
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
|
||||||
assert c[0]._definition.obj == 'foo'
|
assert c[0]._definition.parent.parent.obj == 'foo'
|
||||||
|
|||||||
Reference in New Issue
Block a user