mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
api is now a separate package, to structure the whole thing better.
This commit is contained in:
@@ -26,7 +26,7 @@ from jedi import common
|
|||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi import interpret
|
from jedi import interpret
|
||||||
from jedi import keywords
|
from jedi import keywords
|
||||||
from jedi import api_classes
|
from jedi.api import classes
|
||||||
from jedi.evaluate import Evaluator, filter_private_variable
|
from jedi.evaluate import Evaluator, filter_private_variable
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import builtin
|
from jedi.evaluate import builtin
|
||||||
@@ -84,7 +84,7 @@ class Script(object):
|
|||||||
raise ValueError('`column` parameter is not in a valid range.')
|
raise ValueError('`column` parameter is not in a valid range.')
|
||||||
self._pos = line, column
|
self._pos = line, column
|
||||||
|
|
||||||
api_classes.clear_caches()
|
classes.clear_caches()
|
||||||
debug.reset_time()
|
debug.reset_time()
|
||||||
self.source = common.source_to_unicode(source, encoding)
|
self.source = common.source_to_unicode(source, encoding)
|
||||||
self._user_context = UserContext(self.source, self._pos)
|
self._user_context = UserContext(self.source, self._pos)
|
||||||
@@ -117,11 +117,11 @@ class Script(object):
|
|||||||
|
|
||||||
def completions(self):
|
def completions(self):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Completion` objects. Those objects contain
|
Return :class:`classes.Completion` objects. Those objects contain
|
||||||
information about the completions, more than just names.
|
information about the completions, more than just names.
|
||||||
|
|
||||||
:return: Completion objects, sorted by name and __ comes last.
|
:return: Completion objects, sorted by name and __ comes last.
|
||||||
:rtype: list of :class:`api_classes.Completion`
|
:rtype: list of :class:`classes.Completion`
|
||||||
"""
|
"""
|
||||||
def get_completions(user_stmt, bs):
|
def get_completions(user_stmt, bs):
|
||||||
if isinstance(user_stmt, pr.Import):
|
if isinstance(user_stmt, pr.Import):
|
||||||
@@ -165,7 +165,7 @@ class Script(object):
|
|||||||
or n.startswith(like):
|
or n.startswith(like):
|
||||||
if not filter_private_variable(s,
|
if not filter_private_variable(s,
|
||||||
user_stmt or self._parser.user_scope, n):
|
user_stmt or self._parser.user_scope, n):
|
||||||
new = api_classes.Completion(self._evaluator, c, needs_dot, len(like), s)
|
new = classes.Completion(self._evaluator, c, needs_dot, len(like), s)
|
||||||
k = (new.name, new.complete) # key
|
k = (new.name, new.complete) # key
|
||||||
if k in comp_dct and settings.no_completion_duplicates:
|
if k in comp_dct and settings.no_completion_duplicates:
|
||||||
comp_dct[k]._same_name_completions.append(new)
|
comp_dct[k]._same_name_completions.append(new)
|
||||||
@@ -332,7 +332,7 @@ class Script(object):
|
|||||||
because Python itself is a dynamic language, which means depending on
|
because Python itself is a dynamic language, which means depending on
|
||||||
an option you can have two different versions of a function.
|
an option you can have two different versions of a function.
|
||||||
|
|
||||||
:rtype: list of :class:`api_classes.Definition`
|
:rtype: list of :class:`classes.Definition`
|
||||||
"""
|
"""
|
||||||
def resolve_import_paths(scopes):
|
def resolve_import_paths(scopes):
|
||||||
for s in scopes.copy():
|
for s in scopes.copy():
|
||||||
@@ -378,7 +378,7 @@ class Script(object):
|
|||||||
# add keywords
|
# add keywords
|
||||||
scopes |= keywords.keywords(string=goto_path, pos=self._pos)
|
scopes |= keywords.keywords(string=goto_path, pos=self._pos)
|
||||||
|
|
||||||
d = set([api_classes.Definition(self._evaluator, s) for s in scopes
|
d = set([classes.Definition(self._evaluator, s) for s in scopes
|
||||||
if s is not imports.ImportPath.GlobalNamespace])
|
if s is not imports.ImportPath.GlobalNamespace])
|
||||||
return self._sorted_defs(d)
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
@@ -389,10 +389,10 @@ class Script(object):
|
|||||||
dynamic language, which means depending on an option you can have two
|
dynamic language, which means depending on an option you can have two
|
||||||
different versions of a function.
|
different versions of a function.
|
||||||
|
|
||||||
:rtype: list of :class:`api_classes.Definition`
|
:rtype: list of :class:`classes.Definition`
|
||||||
"""
|
"""
|
||||||
results, _ = self._goto()
|
results, _ = self._goto()
|
||||||
d = [api_classes.Definition(self._evaluator, d) for d in set(results)
|
d = [classes.Definition(self._evaluator, d) for d in set(results)
|
||||||
if d is not imports.ImportPath.GlobalNamespace]
|
if d is not imports.ImportPath.GlobalNamespace]
|
||||||
return self._sorted_defs(d)
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
@@ -453,14 +453,14 @@ class Script(object):
|
|||||||
|
|
||||||
def usages(self, additional_module_paths=()):
|
def usages(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Usage` objects, which contain all
|
Return :class:`classes.Usage` objects, which contain all
|
||||||
names that point to the definition of the name under the cursor. This
|
names that point to the definition of the name under the cursor. This
|
||||||
is very useful for refactoring (renaming), or to show all usages of a
|
is very useful for refactoring (renaming), or to show all usages of a
|
||||||
variable.
|
variable.
|
||||||
|
|
||||||
.. todo:: Implement additional_module_paths
|
.. todo:: Implement additional_module_paths
|
||||||
|
|
||||||
:rtype: list of :class:`api_classes.Usage`
|
:rtype: list of :class:`classes.Usage`
|
||||||
"""
|
"""
|
||||||
temp, settings.dynamic_flow_information = \
|
temp, settings.dynamic_flow_information = \
|
||||||
settings.dynamic_flow_information, False
|
settings.dynamic_flow_information, False
|
||||||
@@ -482,13 +482,13 @@ class Script(object):
|
|||||||
|
|
||||||
for d in set(definitions):
|
for d in set(definitions):
|
||||||
if isinstance(d, pr.Module):
|
if isinstance(d, pr.Module):
|
||||||
names.append(api_classes.Usage(self._evaluator, d, d))
|
names.append(classes.Usage(self._evaluator, d, d))
|
||||||
elif isinstance(d, er.Instance):
|
elif isinstance(d, er.Instance):
|
||||||
# Instances can be ignored, because they are being created by
|
# Instances can be ignored, because they are being created by
|
||||||
# ``__getattr__``.
|
# ``__getattr__``.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
names.append(api_classes.Usage(self._evaluator, d.names[-1], d))
|
names.append(classes.Usage(self._evaluator, d.names[-1], d))
|
||||||
|
|
||||||
settings.dynamic_flow_information = temp
|
settings.dynamic_flow_information = temp
|
||||||
return self._sorted_defs(set(names))
|
return self._sorted_defs(set(names))
|
||||||
@@ -507,7 +507,7 @@ class Script(object):
|
|||||||
|
|
||||||
This would return ``None``.
|
This would return ``None``.
|
||||||
|
|
||||||
:rtype: list of :class:`api_classes.CallDef`
|
:rtype: list of :class:`classes.CallDef`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
call, index = self._func_call_and_param_index()
|
call, index = self._func_call_and_param_index()
|
||||||
@@ -520,7 +520,7 @@ class Script(object):
|
|||||||
origins = cache.cache_call_signatures(_callable, user_stmt)
|
origins = cache.cache_call_signatures(_callable, user_stmt)
|
||||||
debug.speed('func_call followed')
|
debug.speed('func_call followed')
|
||||||
|
|
||||||
return [api_classes.CallDef(o, index, call) for o in origins
|
return [classes.CallDef(o, index, call) for o in origins
|
||||||
if o.isinstance(er.Function, er.Instance, er.Class)]
|
if o.isinstance(er.Function, er.Instance, er.Class)]
|
||||||
|
|
||||||
def _func_call_and_param_index(self):
|
def _func_call_and_param_index(self):
|
||||||
@@ -663,13 +663,13 @@ def defined_names(source, path=None, encoding='utf-8'):
|
|||||||
`defined_names` method which can be used to get sub-definitions
|
`defined_names` method which can be used to get sub-definitions
|
||||||
(e.g., methods in class).
|
(e.g., methods in class).
|
||||||
|
|
||||||
:rtype: list of api_classes.Definition
|
:rtype: list of classes.Definition
|
||||||
"""
|
"""
|
||||||
parser = Parser(
|
parser = Parser(
|
||||||
common.source_to_unicode(source, encoding),
|
common.source_to_unicode(source, encoding),
|
||||||
module_path=path,
|
module_path=path,
|
||||||
)
|
)
|
||||||
return api_classes._defined_names(Evaluator(), parser.module)
|
return classes._defined_names(Evaluator(), parser.module)
|
||||||
|
|
||||||
|
|
||||||
def preload_module(*modules):
|
def preload_module(*modules):
|
||||||
@@ -734,7 +734,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
# compare to see if they match
|
# compare to see if they match
|
||||||
if any(r in compare_definitions for r in compare_follow_res):
|
if any(r in compare_definitions for r in compare_follow_res):
|
||||||
scope = call.parent
|
scope = call.parent
|
||||||
result.append(api_classes.Usage(evaluator, search, scope))
|
result.append(classes.Usage(evaluator, search, scope))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -764,7 +764,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
direct_resolve=True)
|
direct_resolve=True)
|
||||||
f = i.follow(is_goto=True)
|
f = i.follow(is_goto=True)
|
||||||
if set(f) & set(definitions):
|
if set(f) & set(definitions):
|
||||||
names.append(api_classes.Usage(evaluator, name_part, stmt))
|
names.append(classes.Usage(evaluator, name_part, stmt))
|
||||||
else:
|
else:
|
||||||
for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True):
|
for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True):
|
||||||
names += check_call(call)
|
names += check_call(call)
|
||||||
2
setup.py
2
setup.py
@@ -26,7 +26,7 @@ setup(name='jedi',
|
|||||||
license='MIT',
|
license='MIT',
|
||||||
keywords='python completion refactoring vim',
|
keywords='python completion refactoring vim',
|
||||||
long_description=readme,
|
long_description=readme,
|
||||||
packages=['jedi', 'jedi.parser', 'jedi.evaluate'],
|
packages=['jedi', 'jedi.parser', 'jedi.evaluate', 'jedi.api'],
|
||||||
package_data={'jedi': ['evlaluate/evaluate/mixin/*.pym']},
|
package_data={'jedi': ['evlaluate/evaluate/mixin/*.pym']},
|
||||||
platforms=['any'],
|
platforms=['any'],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ There are three kinds of test:
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import api_classes
|
from jedi.api import classes
|
||||||
from jedi.evaluate import Evaluator
|
from jedi.evaluate import Evaluator
|
||||||
from .helpers import TestCase
|
from .helpers import TestCase
|
||||||
|
|
||||||
@@ -82,6 +82,6 @@ def test_keyword_full_name_should_be_none():
|
|||||||
"""issue #94"""
|
"""issue #94"""
|
||||||
# Using `from jedi.keywords import Keyword` here does NOT work
|
# Using `from jedi.keywords import Keyword` here does NOT work
|
||||||
# in Python 3. This is due to the import hack jedi using.
|
# in Python 3. This is due to the import hack jedi using.
|
||||||
Keyword = api_classes.keywords.Keyword
|
Keyword = classes.keywords.Keyword
|
||||||
d = api_classes.Definition(Evaluator(), Keyword('(', (0, 0)))
|
d = classes.Definition(Evaluator(), Keyword('(', (0, 0)))
|
||||||
assert d.full_name is None
|
assert d.full_name is None
|
||||||
|
|||||||
Reference in New Issue
Block a user