mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
moved parts of module to builtin
This commit is contained in:
35
builtin.py
35
builtin.py
@@ -8,19 +8,10 @@ import parsing
|
|||||||
class CachedModule(object):
|
class CachedModule(object):
|
||||||
cache = {}
|
cache = {}
|
||||||
|
|
||||||
def __init__(self, name=None, path=None, sys_path=sys.path):
|
def __init__(self, path=None, name=None):
|
||||||
self.path = path
|
self.path = path
|
||||||
if name:
|
self.name = name
|
||||||
self.name = name
|
|
||||||
else:
|
|
||||||
name = os.path.basename(self.path)
|
|
||||||
self.name = name.rpartition('.')[0] # cut file type (normally .so)
|
|
||||||
self.path = os.path.dirname(self.path)
|
|
||||||
#print self.name, self.path
|
|
||||||
self._content = {}
|
|
||||||
self._parser = None
|
self._parser = None
|
||||||
self._module = None
|
|
||||||
self.sys_path = sys_path
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parser(self):
|
def parser(self):
|
||||||
@@ -79,21 +70,17 @@ class Parser(CachedModule):
|
|||||||
}
|
}
|
||||||
module_cache = {}
|
module_cache = {}
|
||||||
|
|
||||||
def __init__(self, name=None, path=None, sys_path=sys.path):
|
def __init__(self, path=None, name=None, sys_path=sys.path):
|
||||||
super(Parser, self).__init__(name, path)
|
if not name:
|
||||||
|
name = os.path.basename(path)
|
||||||
self.path = path
|
name = name.rpartition('.')[0] # cut file type (normally .so)
|
||||||
if name:
|
path = os.path.dirname(path)
|
||||||
self.name = name
|
|
||||||
else:
|
|
||||||
name = os.path.basename(self.path)
|
|
||||||
self.name = name.rpartition('.')[0] # cut file type (normally .so)
|
|
||||||
self.path = os.path.dirname(self.path)
|
|
||||||
#print self.name, self.path
|
#print self.name, self.path
|
||||||
self._content = {}
|
super(Parser, self).__init__(path=path, name=name)
|
||||||
self._parser = None
|
|
||||||
self._module = None
|
|
||||||
self.sys_path = sys_path
|
self.sys_path = sys_path
|
||||||
|
self._content = {}
|
||||||
|
self._module = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module(self):
|
def module(self):
|
||||||
|
|||||||
10
functions.py
10
functions.py
@@ -12,23 +12,23 @@ __all__ = ['complete', 'get_completion_parts', 'set_debug_function']
|
|||||||
class FileWithCursor(modules.Module):
|
class FileWithCursor(modules.Module):
|
||||||
"""
|
"""
|
||||||
Manages all files, that are parsed and caches them.
|
Manages all files, that are parsed and caches them.
|
||||||
Important are the params source and module_path, one of them has to
|
Important are the params source and path, one of them has to
|
||||||
be there.
|
be there.
|
||||||
|
|
||||||
:param source: The source code of the file.
|
:param source: The source code of the file.
|
||||||
:param module_path: The module name of the file.
|
:param path: The module path of the file.
|
||||||
:param row: The row, the user is currently in. Only important for the \
|
:param row: The row, the user is currently in. Only important for the \
|
||||||
main file.
|
main file.
|
||||||
"""
|
"""
|
||||||
def __init__(self, module_path, source, row):
|
def __init__(self, path, source, row):
|
||||||
super(FileWithCursor, self).__init__(module_path, source)
|
super(FileWithCursor, self).__init__(path, source)
|
||||||
self.row = row
|
self.row = row
|
||||||
|
|
||||||
# this two are only used, because there is no nonlocal in Python 2
|
# this two are only used, because there is no nonlocal in Python 2
|
||||||
self._row_temp = None
|
self._row_temp = None
|
||||||
self._relevant_temp = None
|
self._relevant_temp = None
|
||||||
|
|
||||||
self._parser = parsing.PyFuzzyParser(source, module_path, row)
|
self._parser = parsing.PyFuzzyParser(source, path, row)
|
||||||
|
|
||||||
def get_row_path(self, column):
|
def get_row_path(self, column):
|
||||||
""" Get the path under the cursor. """
|
""" Get the path under the cursor. """
|
||||||
|
|||||||
30
modules.py
30
modules.py
@@ -20,39 +20,25 @@ class Module(builtin.CachedModule):
|
|||||||
Manages all files, that are parsed and caches them.
|
Manages all files, that are parsed and caches them.
|
||||||
|
|
||||||
:param source: The source code of the file.
|
:param source: The source code of the file.
|
||||||
:param module_path: The module path of the file.
|
:param path: The module path of the file.
|
||||||
"""
|
"""
|
||||||
module_cache = {}
|
module_cache = {}
|
||||||
|
|
||||||
def __init__(self, module_path, source):
|
def __init__(self, path, source):
|
||||||
|
super(Module, self).__init__(path=path)
|
||||||
self.source = source
|
self.source = source
|
||||||
self.module_path = module_path
|
|
||||||
self._line_cache = None
|
self._line_cache = None
|
||||||
self._parser = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def parser(self):
|
|
||||||
if not self._parser:
|
|
||||||
# check the cache
|
|
||||||
try:
|
|
||||||
timestamp, _parser = Module.module_cache[self.module_path]
|
|
||||||
if timestamp == os.path.getmtime(self.module_path):
|
|
||||||
debug.dbg('hit module cache')
|
|
||||||
return _parser
|
|
||||||
except KeyError:
|
|
||||||
self._load_module()
|
|
||||||
return self._parser
|
|
||||||
|
|
||||||
def _get_source(self):
|
def _get_source(self):
|
||||||
return self.source
|
return self.source
|
||||||
|
|
||||||
def _load_module(self):
|
def _load_module(self):
|
||||||
self._parser = parsing.PyFuzzyParser(self.source, self.module_path)
|
self._parser = parsing.PyFuzzyParser(self.source, self.path)
|
||||||
del self.source # efficiency
|
del self.source # efficiency
|
||||||
|
|
||||||
# insert into cache
|
# insert into cache
|
||||||
to_cache = (os.path.getmtime(self.module_path), self._parser)
|
to_cache = (os.path.getmtime(self.path), self._parser)
|
||||||
Module.module_cache[self.module_path] = to_cache
|
Module.module_cache[self.path] = to_cache
|
||||||
|
|
||||||
|
|
||||||
def find_module(current_module, point_path):
|
def find_module(current_module, point_path):
|
||||||
@@ -73,7 +59,7 @@ def find_module(current_module, point_path):
|
|||||||
else:
|
else:
|
||||||
path = None
|
path = None
|
||||||
debug.dbg('search_module', string, path,
|
debug.dbg('search_module', string, path,
|
||||||
current_module.module_path)
|
current_module.path)
|
||||||
try:
|
try:
|
||||||
i = imp.find_module(string, path)
|
i = imp.find_module(string, path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -83,7 +69,7 @@ def find_module(current_module, point_path):
|
|||||||
|
|
||||||
# TODO handle relative paths - they are included in the import object
|
# TODO handle relative paths - they are included in the import object
|
||||||
current_namespace = None
|
current_namespace = None
|
||||||
module_find_path.insert(0, os.path.dirname(current_module.module_path))
|
module_find_path.insert(0, os.path.dirname(current_module.path))
|
||||||
# now execute those paths
|
# now execute those paths
|
||||||
rest = []
|
rest = []
|
||||||
for i, s in enumerate(point_path):
|
for i, s in enumerate(point_path):
|
||||||
|
|||||||
10
parsing.py
10
parsing.py
@@ -218,7 +218,7 @@ class Scope(Simple):
|
|||||||
try:
|
try:
|
||||||
name = self.command
|
name = self.command
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = self.module_path
|
name = self.path
|
||||||
|
|
||||||
return "<%s: %s@%s-%s>" % \
|
return "<%s: %s@%s-%s>" % \
|
||||||
(self.__class__.__name__, name, self.line_nr, self.line_end)
|
(self.__class__.__name__, name, self.line_nr, self.line_end)
|
||||||
@@ -226,12 +226,12 @@ class Scope(Simple):
|
|||||||
|
|
||||||
class GlobalScope(Scope):
|
class GlobalScope(Scope):
|
||||||
"""
|
"""
|
||||||
The top scope, which is a module.
|
The top scope, which is always a module.
|
||||||
I don't know why I didn't name it Module :-)
|
I don't know why I didn't name it Module :-)
|
||||||
"""
|
"""
|
||||||
def __init__(self, module_path, docstr=''):
|
def __init__(self, path, docstr=''):
|
||||||
super(GlobalScope, self).__init__(module_path, docstr)
|
super(GlobalScope, self).__init__(path, docstr)
|
||||||
self.module_path = module_path
|
self.path = path
|
||||||
self.global_vars = []
|
self.global_vars = []
|
||||||
|
|
||||||
def add_global(self, name):
|
def add_global(self, name):
|
||||||
|
|||||||
Reference in New Issue
Block a user