forked from VimPlug/jedi
Rename parser.utils to parser.cache.
This commit is contained in:
@@ -9,7 +9,7 @@ import re
|
|||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.parser import utils as parser_utils
|
from jedi.parser.cache import parser_cache
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import instance
|
from jedi.evaluate import instance
|
||||||
@@ -391,7 +391,7 @@ class BaseDefinition(object):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
path = self._name.get_root_context().py__file__()
|
path = self._name.get_root_context().py__file__()
|
||||||
lines = parser_utils.parser_cache[path].lines
|
lines = parser_cache[path].lines
|
||||||
|
|
||||||
line_nr = self._name.start_pos[0]
|
line_nr = self._name.start_pos[0]
|
||||||
start_line_nr = line_nr - before
|
start_line_nr = line_nr - before
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import time
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.parser.utils import parser_cache
|
from jedi.parser.cache import parser_cache
|
||||||
|
|
||||||
_time_caches = {}
|
_time_caches = {}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from jedi import settings
|
|||||||
from jedi.common import source_to_unicode, unite
|
from jedi.common import source_to_unicode, unite
|
||||||
from jedi.parser.python import parse
|
from jedi.parser.python import parse
|
||||||
from jedi.parser.python import tree
|
from jedi.parser.python import tree
|
||||||
from jedi.parser.utils import parser_cache
|
from jedi.parser.cache import parser_cache
|
||||||
from jedi.evaluate import sys_path
|
from jedi.evaluate import sys_path
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from jedi.parser.pgen2.pgen import generate_grammar
|
|||||||
from jedi.parser.python.parser import Parser, _remove_last_newline
|
from jedi.parser.python.parser import Parser, _remove_last_newline
|
||||||
from jedi.parser.python.diff import DiffParser
|
from jedi.parser.python.diff import DiffParser
|
||||||
from jedi.parser.tokenize import generate_tokens
|
from jedi.parser.tokenize import generate_tokens
|
||||||
from jedi.parser import utils
|
from jedi.parser.cache import parser_cache, load_module, save_module
|
||||||
from jedi.common import splitlines, source_to_unicode
|
from jedi.common import splitlines, source_to_unicode
|
||||||
|
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
use_cache = cache and path is not None and not code
|
use_cache = cache and path is not None and not code
|
||||||
if use_cache:
|
if use_cache:
|
||||||
# In this case we do actual caching. We just try to load it.
|
# In this case we do actual caching. We just try to load it.
|
||||||
module_node = utils.load_module(grammar, path)
|
module_node = load_module(grammar, path)
|
||||||
if module_node is not None:
|
if module_node is not None:
|
||||||
return module_node
|
return module_node
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
|
|
||||||
if diff_cache:
|
if diff_cache:
|
||||||
try:
|
try:
|
||||||
module_cache_item = utils.parser_cache[path]
|
module_cache_item = parser_cache[path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -98,7 +98,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
old_lines=module_cache_item.lines,
|
old_lines=module_cache_item.lines,
|
||||||
new_lines=lines
|
new_lines=lines
|
||||||
)
|
)
|
||||||
utils.save_module(grammar, path, module_node, lines, pickling=False)
|
save_module(grammar, path, module_node, lines, pickling=False)
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
added_newline = not code.endswith('\n')
|
added_newline = not code.endswith('\n')
|
||||||
@@ -117,5 +117,5 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
_remove_last_newline(root_node)
|
_remove_last_newline(root_node)
|
||||||
|
|
||||||
if use_cache or diff_cache:
|
if use_cache or diff_cache:
|
||||||
utils.save_module(grammar, path, root_node, lines)
|
save_module(grammar, path, root_node, lines)
|
||||||
return root_node
|
return root_node
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from jedi import settings
|
|||||||
from jedi.common import splitlines
|
from jedi.common import splitlines
|
||||||
from jedi.parser.python.parser import Parser, _remove_last_newline
|
from jedi.parser.python.parser import Parser, _remove_last_newline
|
||||||
from jedi.parser.python.tree import EndMarker
|
from jedi.parser.python.tree import EndMarker
|
||||||
from jedi.parser.utils import parser_cache
|
from jedi.parser.cache import parser_cache
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser.tokenize import (generate_tokens, NEWLINE, TokenInfo,
|
from jedi.parser.tokenize import (generate_tokens, NEWLINE, TokenInfo,
|
||||||
ENDMARKER, INDENT, DEDENT)
|
ENDMARKER, INDENT, DEDENT)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from textwrap import dedent
|
|||||||
from jedi import api
|
from jedi import api
|
||||||
from jedi._compatibility import is_py3
|
from jedi._compatibility import is_py3
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
from jedi.parser import utils
|
from jedi.parser import cache
|
||||||
|
|
||||||
|
|
||||||
def test_preload_modules():
|
def test_preload_modules():
|
||||||
@@ -17,15 +17,15 @@ def test_preload_modules():
|
|||||||
for i in modules:
|
for i in modules:
|
||||||
assert [i in k for k in parser_cache.keys() if k is not None]
|
assert [i in k for k in parser_cache.keys() if k is not None]
|
||||||
|
|
||||||
temp_cache, utils.parser_cache = utils.parser_cache, {}
|
temp_cache, cache.parser_cache = cache.parser_cache, {}
|
||||||
parser_cache = utils.parser_cache
|
parser_cache = cache.parser_cache
|
||||||
|
|
||||||
api.preload_module('sys')
|
api.preload_module('sys')
|
||||||
check_loaded() # compiled (c_builtin) modules shouldn't be in the cache.
|
check_loaded() # compiled (c_builtin) modules shouldn't be in the cache.
|
||||||
api.preload_module('types', 'token')
|
api.preload_module('types', 'token')
|
||||||
check_loaded('types', 'token')
|
check_loaded('types', 'token')
|
||||||
|
|
||||||
utils.parser_cache = temp_cache
|
cache.parser_cache = temp_cache
|
||||||
|
|
||||||
|
|
||||||
def test_empty_script():
|
def test_empty_script():
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import pytest
|
|||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import settings, cache
|
from jedi import settings, cache
|
||||||
from jedi.parser.utils import _NodeCacheItem
|
from jedi.parser.cache import _NodeCacheItem
|
||||||
from jedi.parser.python import load_grammar
|
from jedi.parser.python import load_grammar
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import jedi
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.common import splitlines
|
from jedi.common import splitlines
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi.parser.utils import parser_cache
|
from jedi.parser.cache import parser_cache
|
||||||
from jedi.parser.python import load_grammar
|
from jedi.parser.python import load_grammar
|
||||||
from jedi.parser.python.diff import DiffParser
|
from jedi.parser.python.diff import DiffParser
|
||||||
from jedi.parser.python import parse
|
from jedi.parser.python import parse
|
||||||
|
|||||||
Reference in New Issue
Block a user