forked from VimPlug/jedi
make source_path in script optional, fixes #32
This commit is contained in:
@@ -198,7 +198,7 @@ class Script(object):
|
|||||||
:param col: The column to complete in.
|
:param col: The column to complete in.
|
||||||
:type col: int
|
:type col: int
|
||||||
:param source_path: The path in the os, the current module is in.
|
:param source_path: The path in the os, the current module is in.
|
||||||
:type source_path: string
|
:type source_path: string or None
|
||||||
"""
|
"""
|
||||||
def __init__(self, source, line, column, source_path):
|
def __init__(self, source, line, column, source_path):
|
||||||
self.pos = line, column
|
self.pos = line, column
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ class CachedModule(object):
|
|||||||
self._parser = parsing.PyFuzzyParser(source, self.path or self.name)
|
self._parser = parsing.PyFuzzyParser(source, self.path or self.name)
|
||||||
p_time = None if not self.path else os.path.getmtime(self.path)
|
p_time = None if not self.path else os.path.getmtime(self.path)
|
||||||
|
|
||||||
self.cache[self.path or self.name] = p_time, self._parser
|
if self.path or self.name:
|
||||||
|
self.cache[self.path or self.name] = p_time, self._parser
|
||||||
|
|
||||||
|
|
||||||
class Parser(CachedModule):
|
class Parser(CachedModule):
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class ImportPath(object):
|
|||||||
self.is_like_search = is_like_search
|
self.is_like_search = is_like_search
|
||||||
self.direct_resolve = direct_resolve
|
self.direct_resolve = direct_resolve
|
||||||
self.is_partial_import = bool(kill_count)
|
self.is_partial_import = bool(kill_count)
|
||||||
self.file_path = os.path.dirname(import_stmt.get_parent_until().path)
|
path = import_stmt.get_parent_until().path
|
||||||
|
self.file_path = os.path.dirname(path) if path is not None else None
|
||||||
|
|
||||||
# rest is import_path resolution
|
# rest is import_path resolution
|
||||||
self.import_path = []
|
self.import_path = []
|
||||||
@@ -198,9 +199,13 @@ class ImportPath(object):
|
|||||||
sys.path = temp
|
sys.path = temp
|
||||||
return i
|
return i
|
||||||
|
|
||||||
sys_path_mod = self.sys_path_with_modifications()
|
if self.file_path:
|
||||||
|
sys_path_mod = self.sys_path_with_modifications()
|
||||||
|
sys_path_mod.insert(0, self.file_path)
|
||||||
|
else:
|
||||||
|
sys_path_mod = builtin.module_find_path
|
||||||
|
|
||||||
current_namespace = None
|
current_namespace = None
|
||||||
sys_path_mod.insert(0, self.file_path)
|
|
||||||
# now execute those paths
|
# now execute those paths
|
||||||
rest = []
|
rest = []
|
||||||
for i, s in enumerate(self.import_path):
|
for i, s in enumerate(self.import_path):
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class ModuleWithCursor(Module):
|
|||||||
be there.
|
be there.
|
||||||
|
|
||||||
:param source: The source code of the file.
|
:param source: The source code of the file.
|
||||||
:param path: The module path of the file.
|
:param path: The module path of the file or None.
|
||||||
:param position: The position, the user is currently in. Only important \
|
:param position: The position, the user is currently in. Only important \
|
||||||
for the main file.
|
for the main file.
|
||||||
"""
|
"""
|
||||||
@@ -62,7 +62,8 @@ class ModuleWithCursor(Module):
|
|||||||
# Also, the position is here important (which will not be used by
|
# Also, the position is here important (which will not be used by
|
||||||
# default), therefore fill the cache here.
|
# default), therefore fill the cache here.
|
||||||
self._parser = parsing.PyFuzzyParser(source, path, position)
|
self._parser = parsing.PyFuzzyParser(source, path, position)
|
||||||
builtin.CachedModule.cache[self.path] = time.time(), self._parser
|
if self.path:
|
||||||
|
builtin.CachedModule.cache[self.path] = time.time(), self._parser
|
||||||
|
|
||||||
def get_path_until_cursor(self):
|
def get_path_until_cursor(self):
|
||||||
""" Get the path under the cursor. """
|
""" Get the path under the cursor. """
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ class Module(Scope):
|
|||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
def is_builtin(self):
|
def is_builtin(self):
|
||||||
return not self.path.endswith('.py')
|
return not (self.path is None or self.path.endswith('.py'))
|
||||||
|
|
||||||
|
|
||||||
class Class(Scope):
|
class Class(Scope):
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import api
|
|||||||
|
|
||||||
class TestRegression(unittest.TestCase):
|
class TestRegression(unittest.TestCase):
|
||||||
def get_def(self, src, pos):
|
def get_def(self, src, pos):
|
||||||
script = api.Script(src, pos[0], pos[1], '')
|
script = api.Script(src, pos[0], pos[1], None)
|
||||||
return script.get_definition()
|
return script.get_definition()
|
||||||
|
|
||||||
def complete(self, src, pos=None):
|
def complete(self, src, pos=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user