Anonymous avatar Anonymous committed 88d3afa

findit: move codeassist.find_occurrences() to findit module

Comments (0)

Files changed (3)

rope/contrib/codeassist.py

 import keyword
-import re
 import sys
 import warnings
 
 import rope.base.codeanalyze
 import rope.base.evaluate
-from rope.base import pyobjects, pynames, taskhandle, builtins, exceptions
+import rope.contrib.findit
+from rope.base import pyobjects, pynames, builtins, exceptions
 from rope.base.codeanalyze import (ArrayLinesAdapter, LogicalLineFinder,
                                    SourceLinesAdapter, WordRangeFinder)
-from rope.refactor import occurrences, functionutils, importutils
+from rope.refactor import functionutils, importutils
 
 
 def code_assist(project, source_code, offset, resource=None,
     return (None, None)
 
 
-def find_occurrences(project, resource, offset, unsure=False, resources=None,
-                     in_hierarchy=False, task_handle=taskhandle.NullTaskHandle()):
-    """Return a list of `Location`\s
-
-    If `unsure` is `True`, possible matches are returned, too.  You
-    can use `Location.unsure` to see which are unsure occurrences.
-    `resources` can be a list of `rope.base.resource.File`\s that
-    should be searched for occurrences; if `None` all python files
-    in the project are searched.
-
-    """
-    name = rope.base.codeanalyze.get_name_at(resource, offset)
-    this_pymodule = project.pycore.resource_to_pyobject(resource)
-    primary, pyname = rope.base.evaluate.get_primary_and_pyname_at(
-        this_pymodule, offset)
-    def is_match(occurrence):
-        return unsure
-    finder = occurrences.create_finder(
-        project.pycore, name, pyname, unsure=is_match,
-        in_hierarchy=in_hierarchy, instance=primary)
-    if resources is None:
-        resources = project.pycore.get_python_files()
-    job_set = task_handle.create_jobset('Finding Occurrences',
-                                        count=len(resources))
-    result = []
-    for resource in resources:
-        job_set.started_job('Working On <%s>' % resource.path)
-        for occurrence in finder.find_occurrences(resource):
-            location = Location()
-            location.resource = resource
-            location.offset = occurrence.get_word_range()[0]
-            location.unsure = occurrence.is_unsure()
-            result.append(location)
-        job_set.finished_job()
-    return result
-
-
-class Location(object):
-
-    resource = None
-    offset = None
-    unsure = False
+def find_occurrences(*args, **kwds):
+    warnings.warn('Use `rope.contrib.findit.find_occurrences()` instead',
+                  DeprecationWarning, stacklevel=2)
+    return rope.contrib.findit.find_occurrences(*args, **kwds)
 
 
 class CodeAssistProposal(object):

rope/contrib/findit.py

+import rope.base.codeanalyze
+import rope.base.evaluate
+from rope.base import taskhandle
+from rope.refactor import occurrences
+
+
+def find_occurrences(project, resource, offset, unsure=False, resources=None,
+                     in_hierarchy=False, task_handle=taskhandle.NullTaskHandle()):
+    """Return a list of `Location`\s
+
+    If `unsure` is `True`, possible matches are returned, too.  You
+    can use `Location.unsure` to see which are unsure occurrences.
+    `resources` can be a list of `rope.base.resource.File`\s that
+    should be searched for occurrences; if `None` all python files
+    in the project are searched.
+
+    """
+    name = rope.base.codeanalyze.get_name_at(resource, offset)
+    this_pymodule = project.pycore.resource_to_pyobject(resource)
+    primary, pyname = rope.base.evaluate.get_primary_and_pyname_at(
+        this_pymodule, offset)
+    def is_match(occurrence):
+        return unsure
+    finder = occurrences.create_finder(
+        project.pycore, name, pyname, unsure=is_match,
+        in_hierarchy=in_hierarchy, instance=primary)
+    if resources is None:
+        resources = project.pycore.get_python_files()
+    job_set = task_handle.create_jobset('Finding Occurrences',
+                                        count=len(resources))
+    result = []
+    for resource in resources:
+        job_set.started_job('Working On <%s>' % resource.path)
+        for occurrence in finder.find_occurrences(resource):
+            location = Location()
+            location.resource = resource
+            location.offset = occurrence.get_word_range()[0]
+            location.unsure = occurrence.is_unsure()
+            result.append(location)
+        job_set.finished_job()
+    return result
+
+
+class Location(object):
+
+    resource = None
+    offset = None
+    unsure = False

ropetest/contrib/codeassisttest.py

 import unittest
 
 from rope.base import exceptions
-from rope.contrib.codeassist import \
-     (get_definition_location, get_doc, starting_expression,
-      find_occurrences, code_assist, sorted_proposals,
-      starting_offset, get_calltip)
+from rope.contrib.codeassist import (get_definition_location, get_doc,
+                                     starting_expression, code_assist,
+                                     sorted_proposals, starting_offset,
+                                     get_calltip)
 from ropetest import testutils
+from rope.contrib.findit import find_occurrences
 
 
 class CodeAssistTest(unittest.TestCase):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.