Try to use the new API names everywhere

This commit is contained in:
Dave Halter
2019-12-20 17:29:42 +01:00
parent f03c70e577
commit ebe9921208
2 changed files with 18 additions and 19 deletions
+15 -16
View File
@@ -199,12 +199,12 @@ class Script(object):
return self._complete(line, column, **kwargs) return self._complete(line, column, **kwargs)
def _complete(self, line, column, fuzzy=False): # Python 2... def _complete(self, line, column, fuzzy=False): # Python 2...
with debug.increase_indent_cm('completions'): with debug.increase_indent_cm('complete'):
completion = Completion( completion = Completion(
self._inference_state, self._get_module_context(), self._code_lines, self._inference_state, self._get_module_context(), self._code_lines,
(line, column), self.find_signatures (line, column), self.find_signatures
) )
return completion.completions(fuzzy) return completion.complete(fuzzy)
def completions(self, fuzzy=False): def completions(self, fuzzy=False):
# Deprecated, will be removed. # Deprecated, will be removed.
@@ -215,8 +215,8 @@ class Script(object):
""" """
Return the definitions of a the path under the cursor. goto function! Return the definitions of a the path under the cursor. goto function!
This follows complicated paths and returns the end, not the first This follows complicated paths and returns the end, not the first
definition. The big difference between :meth:`goto_assignments` and definition. The big difference between :meth:`goto` and
:meth:`goto_definitions` is that :meth:`goto_assignments` doesn't :meth:`infer` is that :meth:`goto` doesn't
follow imports and statements. Multiple objects may be returned, follow imports and statements. Multiple objects may be returned,
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.
@@ -226,14 +226,14 @@ class Script(object):
inference call. inference call.
:rtype: list of :class:`classes.Definition` :rtype: list of :class:`classes.Definition`
""" """
with debug.increase_indent_cm('goto_definitions'): with debug.increase_indent_cm('infer'):
return self._goto_definitions(line, column, **kwargs) return self._infer(line, column, **kwargs)
def goto_definitions(self, **kwargs): def goto_definitions(self, **kwargs):
# Deprecated, will be removed. # Deprecated, will be removed.
return self.infer(*self._pos, **kwargs) return self.infer(*self._pos, **kwargs)
def _goto_definitions(self, line, column, only_stubs=False, prefer_stubs=False): def _infer(self, line, column, only_stubs=False, prefer_stubs=False):
pos = line, column pos = line, column
leaf = self._module_node.get_name_of_position(pos) leaf = self._module_node.get_name_of_position(pos)
if leaf is None: if leaf is None:
@@ -280,12 +280,11 @@ class Script(object):
:param prefer_stubs: Prefer stubs to Python objects for this goto call. :param prefer_stubs: Prefer stubs to Python objects for this goto call.
:rtype: list of :class:`classes.Definition` :rtype: list of :class:`classes.Definition`
""" """
with debug.increase_indent_cm('goto_assignments'): with debug.increase_indent_cm('goto'):
return self._goto_assignments(line, column, **kwargs) return self._goto(line, column, **kwargs)
def _goto_assignments(self, line, column, follow_imports=False, def _goto(self, line, column, follow_imports=False, follow_builtin_imports=False,
follow_builtin_imports=False, only_stubs=False, prefer_stubs=False):
only_stubs=False, prefer_stubs=False):
def filter_follow_imports(names): def filter_follow_imports(names):
for name in names: for name in names:
if name.is_import(): if name.is_import():
@@ -308,7 +307,7 @@ class Script(object):
if tree_name is None: if tree_name is None:
# Without a name we really just want to jump to the result e.g. # Without a name we really just want to jump to the result e.g.
# executed by `foo()`, if we the cursor is after `)`. # executed by `foo()`, if we the cursor is after `)`.
return self.goto_definitions(only_stubs=only_stubs, prefer_stubs=prefer_stubs) return self.infer(line, column, only_stubs=only_stubs, prefer_stubs=prefer_stubs)
name = self._get_module_context().create_name(tree_name) name = self._get_module_context().create_name(tree_name)
names = list(name.goto()) names = list(name.goto())
@@ -440,7 +439,7 @@ class Interpreter(Script):
>>> from os.path import join >>> from os.path import join
>>> namespace = locals() >>> namespace = locals()
>>> script = Interpreter('join("").up', [namespace]) >>> script = Interpreter('join("").up', [namespace])
>>> print(script.completions()[0].name) >>> print(script.complete()[0].name)
upper upper
""" """
_allow_descriptor_getattr_default = True _allow_descriptor_getattr_default = True
@@ -494,7 +493,7 @@ def names(source=None, path=None, encoding='utf-8', all_scopes=False,
definitions=True, references=False, environment=None): definitions=True, references=False, environment=None):
""" """
Returns a list of `Definition` objects, containing name parts. Returns a list of `Definition` objects, containing name parts.
This means you can call ``Definition.goto_assignments()`` and get the This means you can call ``Definition.goto()`` and get the
reference of a name. reference of a name.
The parameters are the same as in :py:class:`Script`, except or the The parameters are the same as in :py:class:`Script`, except or the
following ones: following ones:
@@ -531,7 +530,7 @@ def preload_module(*modules):
""" """
for m in modules: for m in modules:
s = "import %s as x; x." % m s = "import %s as x; x." % m
Script(s, 1, len(s), None).completions() Script(s, path=None).complete(1, len(s))
def set_debug_function(func_cb=debug.print_to_stdout, warnings=True, def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
+3 -3
View File
@@ -90,10 +90,10 @@ class Completion:
self._fuzzy = fuzzy self._fuzzy = fuzzy
def completions(self, fuzzy=False, **kwargs): def complete(self, fuzzy=False, **kwargs):
return self._completions(fuzzy, **kwargs) return self._complete(fuzzy, **kwargs)
def _completions(self, fuzzy): def _complete(self, fuzzy):
leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True) leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
string, start_leaf = _extract_string_while_in_string(leaf, self._position) string, start_leaf = _extract_string_while_in_string(leaf, self._position)
if string is not None: if string is not None: