Anonymous avatar Anonymous committed 1813358

codeassist: better context sensitive pyname finding

Comments (0)

Files changed (2)


     pymodule = _get_pymodule(project.pycore, source_code,
                              resource, maxfixes=maxfixes)
     scope = pymodule.get_scope().get_inner_scope_for_line(lineno)
-    return rope.base.evaluate.get_string_result(scope, expression)
+    result = rope.base.evaluate.get_string_result(scope, expression)
+    new_code = pymodule.source_code
+    if result is None or new_code.startswith(source_code[:offset]):
+        if offset < len(new_code):
+            return rope.base.evaluate.get_pyname_at(pymodule, offset)
+    return result
 def _get_pymodule(pycore, code, resource, maxfixes=1):


         result = get_doc(self.project, code, len(code) - 2, mod2)
+    def test_get_doc_on_from_import_module(self):
+        mod1 = testutils.create_module(self.project, 'mod1')
+        mod1.write('"""mod1 docs"""\nvar = 1\n')
+        code = 'from mod1 import var\n'
+        result = get_doc(self.project, code, code.index('mod1'))
+        result.index('mod1 docs')
     def test_finding_occurrences(self):
         mod = testutils.create_module(self.project, 'mod')
         mod.write('a_var = 1\n')
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
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.