mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Script.complete has been deprecated, therefore changed all usages / documatation to Script.completions
This commit is contained in:
@@ -22,7 +22,7 @@ example for the autocompletion feature:
|
|||||||
>>> script = jedi.Script(source, 3, len('datetime.da'), 'example.py')
|
>>> script = jedi.Script(source, 3, len('datetime.da'), 'example.py')
|
||||||
>>> script
|
>>> script
|
||||||
<Script: 'example.py'>
|
<Script: 'example.py'>
|
||||||
>>> completions = script.complete()
|
>>> completions = script.completions()
|
||||||
>>> completions #doctest: +ELLIPSIS
|
>>> completions #doctest: +ELLIPSIS
|
||||||
[<Completion: date>, <Completion: datetime>, ...]
|
[<Completion: date>, <Completion: datetime>, ...]
|
||||||
>>> print(completions[0].complete)
|
>>> print(completions[0].complete)
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class Script(object):
|
|||||||
: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:`api_classes.Completion`
|
||||||
"""
|
"""
|
||||||
debug.speed('complete start')
|
debug.speed('completions start')
|
||||||
path = self._module.get_path_until_cursor()
|
path = self._module.get_path_until_cursor()
|
||||||
if re.search('^\.|\.\.$', path):
|
if re.search('^\.|\.\.$', path):
|
||||||
return []
|
return []
|
||||||
@@ -161,14 +161,14 @@ class Script(object):
|
|||||||
comp_dct[k] = new
|
comp_dct[k] = new
|
||||||
comps.append(new)
|
comps.append(new)
|
||||||
|
|
||||||
debug.speed('complete end')
|
debug.speed('completions end')
|
||||||
|
|
||||||
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
||||||
x.word.startswith('_'),
|
x.word.startswith('_'),
|
||||||
x.word.lower()))
|
x.word.lower()))
|
||||||
|
|
||||||
def _prepare_goto(self, goto_path, is_like_search=False):
|
def _prepare_goto(self, goto_path, is_like_search=False):
|
||||||
""" Base for complete, goto and definition. Basically it returns
|
""" Base for completions, goto and definition. Basically it returns
|
||||||
the resolved scopes under cursor. """
|
the resolved scopes under cursor. """
|
||||||
debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope))
|
debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope))
|
||||||
|
|
||||||
@@ -551,4 +551,4 @@ def _quick_complete(source):
|
|||||||
lines = re.sub(r'[\n\r\s]*$', '', source).splitlines()
|
lines = re.sub(r'[\n\r\s]*$', '', source).splitlines()
|
||||||
pos = len(lines), len(lines[-1])
|
pos = len(lines), len(lines[-1])
|
||||||
script = Script(source, pos[0], pos[1], '')
|
script = Script(source, pos[0], pos[1], '')
|
||||||
return script.complete()
|
return script.completions()
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
class Completion(BaseDefinition):
|
class Completion(BaseDefinition):
|
||||||
"""
|
"""
|
||||||
`Completion` objects are returned from :meth:`api.Script.complete`. They
|
`Completion` objects are returned from :meth:`api.Script.completions`. They
|
||||||
provide additional information about a completion.
|
provide additional information about a completion.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name, needs_dot, like_name_length, base):
|
def __init__(self, name, needs_dot, like_name_length, base):
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ class TestBase(unittest.TestCase):
|
|||||||
script = self.get_script(src, pos)
|
script = self.get_script(src, pos)
|
||||||
return script.definition()
|
return script.definition()
|
||||||
|
|
||||||
def complete(self, src, pos=None, path=None):
|
def completions(self, src, pos=None, path=None):
|
||||||
script = self.get_script(src, pos, path)
|
script = self.get_script(src, pos, path)
|
||||||
return script.complete()
|
return script.completions()
|
||||||
|
|
||||||
def goto(self, src, pos=None):
|
def goto(self, src, pos=None):
|
||||||
script = self.get_script(src, pos)
|
script = self.get_script(src, pos)
|
||||||
|
|||||||
2
test/completion/thirdparty/jedi_.py
vendored
2
test/completion/thirdparty/jedi_.py
vendored
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
from jedi import functions, evaluate, parsing
|
from jedi import functions, evaluate, parsing
|
||||||
|
|
||||||
el = functions.complete()[0]
|
el = functions.completions()[0]
|
||||||
#? ['description']
|
#? ['description']
|
||||||
el.description
|
el.description
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ tests.
|
|||||||
|
|
||||||
There are different kind of tests:
|
There are different kind of tests:
|
||||||
|
|
||||||
- complete / definitions ``#?``
|
- completions / definitions ``#?``
|
||||||
- goto: ``#!``
|
- goto: ``#!``
|
||||||
- related names: ``#<``
|
- related names: ``#<``
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ multiple Python versions.
|
|||||||
.. _tox: http://testrun.org/tox
|
.. _tox: http://testrun.org/tox
|
||||||
|
|
||||||
Integration test cases are located in ``test/completion`` directory
|
Integration test cases are located in ``test/completion`` directory
|
||||||
and each test cases are indicated by the comment ``#?`` (complete /
|
and each test cases are indicated by the comment ``#?`` (completions /
|
||||||
definitions), ``#!`` (assignments) and ``#<`` (usages). There is also
|
definitions), ``#!`` (assignments) and ``#<`` (usages). There is also
|
||||||
support for third party libraries. In a normal test run they are not
|
support for third party libraries. In a normal test run they are not
|
||||||
being executed, you have to provide a ``--thirdparty`` option.
|
being executed, you have to provide a ``--thirdparty`` option.
|
||||||
@@ -148,8 +148,8 @@ class IntegrationTestCase(object):
|
|||||||
return testers[self.test_type](compare_cb)
|
return testers[self.test_type](compare_cb)
|
||||||
|
|
||||||
def run_completion(self, compare_cb):
|
def run_completion(self, compare_cb):
|
||||||
completions = self.script().complete()
|
completions = self.script().completions()
|
||||||
#import cProfile; cProfile.run('script.complete()')
|
#import cProfile; cProfile.run('script.completions()')
|
||||||
|
|
||||||
comp_str = set([c.word for c in completions])
|
comp_str = set([c.word for c in completions])
|
||||||
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ class TestRegression(TestBase):
|
|||||||
cache = api.cache
|
cache = api.cache
|
||||||
cache.star_import_cache = {} # first empty...
|
cache.star_import_cache = {} # first empty...
|
||||||
# path needs to be not-None (otherwise caching effects are not visible)
|
# path needs to be not-None (otherwise caching effects are not visible)
|
||||||
jedi.Script('', 1, 0, '').complete()
|
jedi.Script('', 1, 0, '').completions()
|
||||||
time.sleep(2 * new)
|
time.sleep(2 * new)
|
||||||
jedi.Script('', 1, 0, '').complete()
|
jedi.Script('', 1, 0, '').completions()
|
||||||
|
|
||||||
# reset values
|
# reset values
|
||||||
jedi.settings.star_import_cache_validity = old
|
jedi.settings.star_import_cache_validity = old
|
||||||
@@ -121,11 +121,11 @@ class TestRegression(TestBase):
|
|||||||
assert self.definition("", (1, 0)) == []
|
assert self.definition("", (1, 0)) == []
|
||||||
|
|
||||||
def test_complete_at_zero(self):
|
def test_complete_at_zero(self):
|
||||||
s = self.complete("str", (1, 3))
|
s = self.completions("str", (1, 3))
|
||||||
assert len(s) == 1
|
assert len(s) == 1
|
||||||
assert list(s)[0].word == 'str'
|
assert list(s)[0].word == 'str'
|
||||||
|
|
||||||
s = self.complete("", (1, 0))
|
s = self.completions("", (1, 0))
|
||||||
assert len(s) > 0
|
assert len(s) > 0
|
||||||
|
|
||||||
def test_definition_on_import(self):
|
def test_definition_on_import(self):
|
||||||
@@ -135,16 +135,16 @@ class TestRegression(TestBase):
|
|||||||
@cwd_at('jedi')
|
@cwd_at('jedi')
|
||||||
def test_complete_on_empty_import(self):
|
def test_complete_on_empty_import(self):
|
||||||
# should just list the files in the directory
|
# should just list the files in the directory
|
||||||
assert 10 < len(self.complete("from .", path='')) < 30
|
assert 10 < len(self.completions("from .", path='')) < 30
|
||||||
assert 10 < len(self.complete("from . import", (1, 5), '')) < 30
|
assert 10 < len(self.completions("from . import", (1, 5), '')) < 30
|
||||||
assert 10 < len(self.complete("from . import classes",
|
assert 10 < len(self.completions("from . import classes",
|
||||||
(1, 5), '')) < 30
|
(1, 5), '')) < 30
|
||||||
assert len(self.complete("import")) == 0
|
assert len(self.completions("import")) == 0
|
||||||
assert len(self.complete("import import", path='')) > 0
|
assert len(self.completions("import import", path='')) > 0
|
||||||
|
|
||||||
# 111
|
# 111
|
||||||
assert self.complete("from datetime import")[0].word == 'import'
|
assert self.completions("from datetime import")[0].word == 'import'
|
||||||
assert self.complete("from datetime import ")
|
assert self.completions("from datetime import ")
|
||||||
|
|
||||||
def assert_call_def(self, call_def, name, index):
|
def assert_call_def(self, call_def, name, index):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -276,18 +276,18 @@ class TestRegression(TestBase):
|
|||||||
def test_unicode_script(self):
|
def test_unicode_script(self):
|
||||||
""" normally no unicode objects are being used. (<=2.7) """
|
""" normally no unicode objects are being used. (<=2.7) """
|
||||||
s = unicode("import datetime; datetime.timedelta")
|
s = unicode("import datetime; datetime.timedelta")
|
||||||
completions = self.complete(s)
|
completions = self.completions(s)
|
||||||
assert len(completions)
|
assert len(completions)
|
||||||
assert type(completions[0].description) is unicode
|
assert type(completions[0].description) is unicode
|
||||||
|
|
||||||
s = utf8("author='öä'; author")
|
s = utf8("author='öä'; author")
|
||||||
completions = self.complete(s)
|
completions = self.completions(s)
|
||||||
x = completions[0].description
|
x = completions[0].description
|
||||||
assert type(x) is unicode
|
assert type(x) is unicode
|
||||||
|
|
||||||
s = utf8("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author")
|
s = utf8("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author")
|
||||||
s = s.encode('latin-1')
|
s = s.encode('latin-1')
|
||||||
completions = self.complete(s)
|
completions = self.completions(s)
|
||||||
assert type(completions[0].description) is unicode
|
assert type(completions[0].description) is unicode
|
||||||
|
|
||||||
def test_multibyte_script(self):
|
def test_multibyte_script(self):
|
||||||
@@ -299,27 +299,27 @@ class TestRegression(TestBase):
|
|||||||
except NameError:
|
except NameError:
|
||||||
pass # python 3 has no unicode method
|
pass # python 3 has no unicode method
|
||||||
else:
|
else:
|
||||||
assert len(self.complete(s, (1, len(code))))
|
assert len(self.completions(s, (1, len(code))))
|
||||||
|
|
||||||
def test_unicode_attribute(self):
|
def test_unicode_attribute(self):
|
||||||
""" github jedi-vim issue #94 """
|
""" github jedi-vim issue #94 """
|
||||||
s1 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
s1 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
||||||
' name = "e"\n\nPerson().name.')
|
' name = "e"\n\nPerson().name.')
|
||||||
completions1 = self.complete(s1)
|
completions1 = self.completions(s1)
|
||||||
assert 'strip' in [c.word for c in completions1]
|
assert 'strip' in [c.word for c in completions1]
|
||||||
s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
||||||
' name = "é"\n\nPerson().name.')
|
' name = "é"\n\nPerson().name.')
|
||||||
completions2 = self.complete(s2)
|
completions2 = self.completions(s2)
|
||||||
assert 'strip' in [c.word for c in completions2]
|
assert 'strip' in [c.word for c in completions2]
|
||||||
|
|
||||||
def test_os_nowait(self):
|
def test_os_nowait(self):
|
||||||
""" github issue #45 """
|
""" github issue #45 """
|
||||||
s = self.complete("import os; os.P_")
|
s = self.completions("import os; os.P_")
|
||||||
assert 'P_NOWAIT' in [i.word for i in s]
|
assert 'P_NOWAIT' in [i.word for i in s]
|
||||||
|
|
||||||
def test_follow_definition(self):
|
def test_follow_definition(self):
|
||||||
""" github issue #45 """
|
""" github issue #45 """
|
||||||
c = self.complete("from datetime import timedelta; timedelta")
|
c = self.completions("from datetime import timedelta; timedelta")
|
||||||
# type can also point to import, but there will be additional
|
# type can also point to import, but there will be additional
|
||||||
# attributes
|
# attributes
|
||||||
objs = itertools.chain.from_iterable(r.follow_definition() for r in c)
|
objs = itertools.chain.from_iterable(r.follow_definition() for r in c)
|
||||||
@@ -344,7 +344,7 @@ class TestRegression(TestBase):
|
|||||||
"""At some point, points were inserted into the completions, this
|
"""At some point, points were inserted into the completions, this
|
||||||
caused problems, sometimes.
|
caused problems, sometimes.
|
||||||
"""
|
"""
|
||||||
c = self.complete("if IndentationErr")
|
c = self.completions("if IndentationErr")
|
||||||
assert c[0].word == 'IndentationError'
|
assert c[0].word == 'IndentationError'
|
||||||
self.assertEqual(c[0].complete, 'or')
|
self.assertEqual(c[0].complete, 'or')
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ class TestRegression(TestBase):
|
|||||||
'''
|
'''
|
||||||
arg."""
|
arg."""
|
||||||
|
|
||||||
words = [c.word for c in self.complete(s)]
|
words = [c.word for c in self.completions(s)]
|
||||||
assert 'join' in words
|
assert 'join' in words
|
||||||
|
|
||||||
def test_docstrings_type_dotted_import(self):
|
def test_docstrings_type_dotted_import(self):
|
||||||
@@ -366,7 +366,7 @@ class TestRegression(TestBase):
|
|||||||
:type arg: threading.Thread
|
:type arg: threading.Thread
|
||||||
'''
|
'''
|
||||||
arg."""
|
arg."""
|
||||||
words = [c.word for c in self.complete(s)]
|
words = [c.word for c in self.completions(s)]
|
||||||
assert 'start' in words
|
assert 'start' in words
|
||||||
|
|
||||||
def test_no_statement_parent(self):
|
def test_no_statement_parent(self):
|
||||||
@@ -415,7 +415,7 @@ class TestDocstring(TestBase):
|
|||||||
class TestFeature(TestBase):
|
class TestFeature(TestBase):
|
||||||
def test_full_name(self):
|
def test_full_name(self):
|
||||||
""" feature request #61"""
|
""" feature request #61"""
|
||||||
assert self.complete('import os; os.path.join')[0].full_name \
|
assert self.completions('import os; os.path.join')[0].full_name \
|
||||||
== 'os.path.join'
|
== 'os.path.join'
|
||||||
|
|
||||||
def test_keyword_full_name_should_be_none(self):
|
def test_keyword_full_name_should_be_none(self):
|
||||||
@@ -427,7 +427,7 @@ class TestFeature(TestBase):
|
|||||||
assert d.full_name is None
|
assert d.full_name is None
|
||||||
|
|
||||||
def test_full_name_builtin(self):
|
def test_full_name_builtin(self):
|
||||||
self.assertEqual(self.complete('type')[0].full_name, 'type')
|
self.assertEqual(self.completions('type')[0].full_name, 'type')
|
||||||
|
|
||||||
def test_full_name_tuple_mapping(self):
|
def test_full_name_tuple_mapping(self):
|
||||||
s = """
|
s = """
|
||||||
@@ -451,7 +451,7 @@ class TestFeature(TestBase):
|
|||||||
quick_completions = api._quick_complete(source)
|
quick_completions = api._quick_complete(source)
|
||||||
# Run real completion
|
# Run real completion
|
||||||
script = jedi.Script(source, pos[0], pos[1], '')
|
script = jedi.Script(source, pos[0], pos[1], '')
|
||||||
real_completions = script.complete()
|
real_completions = script.completions()
|
||||||
# Compare results
|
# Compare results
|
||||||
quick_values = [(c.full_name, c.line, c.column) for c in quick_completions]
|
quick_values = [(c.full_name, c.line, c.column) for c in quick_completions]
|
||||||
real_values = [(c.full_name, c.line, c.column) for c in real_completions]
|
real_values = [(c.full_name, c.line, c.column) for c in real_completions]
|
||||||
@@ -535,7 +535,7 @@ class TestSpeed(TestBase):
|
|||||||
@_check_speed(0.2)
|
@_check_speed(0.2)
|
||||||
def test_os_path_join(self):
|
def test_os_path_join(self):
|
||||||
s = "from posixpath import join; join('', '')."
|
s = "from posixpath import join; join('', '')."
|
||||||
assert len(self.complete(s)) > 10 # is a str completion
|
assert len(self.completions(s)) > 10 # is a str completion
|
||||||
|
|
||||||
@_check_speed(0.1)
|
@_check_speed(0.1)
|
||||||
def test_scipy_speed(self):
|
def test_scipy_speed(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user