diff --git a/README.rst b/README.rst index 252cd48c..ef0d804e 100644 --- a/README.rst +++ b/README.rst @@ -32,7 +32,7 @@ Jedi has a focus on autocompletion and goto functionality. Jedi is fast and is very well tested. It understands Python and stubs on a deep level. Jedi has support for different goto functions. It's possible to search for -usages and list names in a Python file to get information about them. +references and list names in a Python file to get information about them. Jedi uses a very simple API to connect with IDE's. There's a reference implementation as a `VIM-Plugin `_, diff --git a/jedi/__init__.py b/jedi/__init__.py index 71504c3d..efec776d 100644 --- a/jedi/__init__.py +++ b/jedi/__init__.py @@ -4,7 +4,7 @@ Jedi has a focus on autocompletion and goto functionality. Jedi is fast and is very well tested. It understands Python and stubs on a deep level. Jedi has support for different goto functions. It's possible to search for -usages and list names in a Python file to get information about them. +references and list names in a Python file to get information about them. Jedi uses a very simple API to connect with IDE's. There's a reference implementation as a `VIM-Plugin `_, diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index d1b1ff4d..b03c6ef8 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -333,27 +333,27 @@ class Script(object): """ Return :class:`classes.Definition` objects, which contain all 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 - variable. + is very useful for refactoring (renaming), or to show all references of + a variable. - :param include_builtins: Default True, checks if a usage is a builtin - (e.g. ``sys``) and in that case does not return it. + :param include_builtins: Default True, checks if a reference is a + builtin (e.g. ``sys``) and in that case does not return it. :rtype: list of :class:`classes.Definition` """ - def _usages(include_builtins=True): + def _references(include_builtins=True): tree_name = self._module_node.get_name_of_position((line, column)) if tree_name is None: # Must be syntax return [] - names = usages.usages(self._get_module_context(), tree_name) + names = usages.find_references(self._get_module_context(), tree_name) definitions = [classes.Definition(self._inference_state, n) for n in names] if not include_builtins: definitions = [d for d in definitions if not d.in_builtin_module()] return helpers.sorted_definitions(definitions) - return _usages(**kwargs) + return _references(**kwargs) def call_signatures(self): # Deprecated, will be removed. diff --git a/jedi/inference/dynamic_params.py b/jedi/inference/dynamic_params.py index 5f457cd1..e37c442e 100644 --- a/jedi/inference/dynamic_params.py +++ b/jedi/inference/dynamic_params.py @@ -74,7 +74,7 @@ def dynamic_param_lookup(function_value, param_index): path = function_value.get_root_context().py__file__() if path is not None and is_stdlib_path(path): - # We don't want to search for usages in the stdlib. Usually people + # We don't want to search for references in the stdlib. Usually people # don't work with it (except if you are a core maintainer, sorry). # This makes everything slower. Just disable it and run the tests, # you will see the slowdown, especially in 3.6. diff --git a/jedi/inference/usages.py b/jedi/inference/usages.py index 95888ed2..4cd00cc9 100644 --- a/jedi/inference/usages.py +++ b/jedi/inference/usages.py @@ -32,7 +32,7 @@ def _find_names(module_context, tree_name): return _dictionarize(_resolve_names(found_names)) -def usages(module_context, tree_name): +def find_references(module_context, tree_name): search_name = tree_name.value found_names = _find_names(module_context, tree_name) module_contexts = set(d.get_root_context() for d in found_names.values()) diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 4cd18660..4a25ed66 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -57,7 +57,7 @@ def rename(script, new_name): :param script: The source Script object. :return: list of changed lines/changed files """ - return Refactoring(_rename(script.usages(), new_name)) + return Refactoring(_rename(script.find_references(), new_name)) def _rename(names, replace_str): @@ -169,8 +169,8 @@ def inline(script): definitions = script.goto() assert len(definitions) == 1 stmt = definitions[0]._definition - usages = script.usages() - inlines = [r for r in usages + references = script.find_references() + inlines = [r for r in references if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos] inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column), reverse=True) diff --git a/test/completion/usages.py b/test/completion/usages.py index 0976798c..2f8d1802 100644 --- a/test/completion/usages.py +++ b/test/completion/usages.py @@ -1,5 +1,5 @@ """ -Renaming tests. This means search for usages. +Renaming tests. This means search for references. I always leave a little bit of space to add room for additions, because the results always contain position informations. """ diff --git a/test/refactor/rename.py b/test/refactor/rename.py index e98c5897..8faab24f 100644 --- a/test/refactor/rename.py +++ b/test/refactor/rename.py @@ -1,6 +1,6 @@ """ Test coverage for renaming is mostly being done by testing -`Script.usages`. +`Script.find_references`. """ # --- simple diff --git a/test/test_api/import_tree_for_usages/__init__.py b/test/test_api/import_tree_for_usages/__init__.py index d2ae403e..70352869 100644 --- a/test/test_api/import_tree_for_usages/__init__.py +++ b/test/test_api/import_tree_for_usages/__init__.py @@ -1,4 +1,4 @@ """ -An import tree, for testing usages. +An import tree, for testing references. """ diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index eb67e23e..f33b5cef 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -162,8 +162,8 @@ def test_goto_definition_not_multiple(Script): assert len(Script(s).infer()) == 1 -def test_usage_description(Script): - descs = [u.description for u in Script("foo = ''; foo").usages()] +def test_reference_description(Script): + descs = [u.description for u in Script("foo = ''; foo").find_references()] assert set(descs) == {"foo = ''", 'foo'} diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index bc3055ac..89643038 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -51,8 +51,8 @@ def test_basedefinition_type(Script, names): script = Script(source, path=None) definitions += script.infer(len(lines), len('variable')) - script2 = Script(source, 4, len('class C'), None) - definitions += script2.usages() + script2 = Script(source, path=None) + definitions += script2.find_references(4, len('class C')) source_param = "def f(a): return a" script_param = Script(source_param, path=None) diff --git a/test/test_api/test_usages.py b/test/test_api/test_usages.py index 245951b7..30a6581a 100644 --- a/test/test_api/test_usages.py +++ b/test/test_api/test_usages.py @@ -1,11 +1,12 @@ -def test_import_usage(Script): - s = Script("from .. import foo", line=1, column=18, path="foo.py") - assert [usage.line for usage in s.usages()] == [1] +def test_import_references(Script): + s = Script("from .. import foo", path="foo.py") + assert [usage.line for usage in s.find_references(line=1, column=18)] == [1] def test_exclude_builtin_modules(Script): def get(include): - return [(d.line, d.column) for d in Script(source, column=8).usages(include_builtins=include)] + references = Script(source).find_references(column=8, include_builtins=include) + return [(d.line, d.column) for d in references] source = '''import sys\nprint(sys.path)''' places = get(include=True) assert len(places) > 2 # Includes stubs