mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
Remove CachedFastPaser, not needed anymore.
This commit is contained in:
@@ -3,6 +3,7 @@ Parsers for Python
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from jedi import settings
|
||||||
from jedi._compatibility import FileNotFoundError
|
from jedi._compatibility import FileNotFoundError
|
||||||
from jedi.parser.pgen2.pgen import generate_grammar
|
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
|
||||||
@@ -86,7 +87,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
code = source_to_unicode(f.read())
|
code = source_to_unicode(f.read())
|
||||||
|
|
||||||
if diff_cache:
|
if diff_cache and settings.fast_parser:
|
||||||
try:
|
try:
|
||||||
module_cache_item = parser_cache[path]
|
module_cache_item = parser_cache[path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -9,35 +9,14 @@ import re
|
|||||||
import difflib
|
import difflib
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass
|
|
||||||
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.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)
|
||||||
|
|
||||||
|
|
||||||
class CachedFastParser(type):
|
|
||||||
""" This is a metaclass for caching `FastParser`. """
|
|
||||||
def __call__(self, grammar, source, module_path=None):
|
|
||||||
pi = parser_cache.get(module_path, None)
|
|
||||||
if pi is None or not settings.fast_parser:
|
|
||||||
return Parser(grammar, source, module_path)
|
|
||||||
|
|
||||||
parser = pi.parser
|
|
||||||
d = DiffParser(parser)
|
|
||||||
new_lines = splitlines(source, keepends=True)
|
|
||||||
parser.module = parser._parsed = d.update(new_lines)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
|
|
||||||
class FastParser(use_metaclass(CachedFastParser)):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_last_line(node_or_leaf):
|
def _get_last_line(node_or_leaf):
|
||||||
last_leaf = node_or_leaf.get_last_leaf()
|
last_leaf = node_or_leaf.get_last_leaf()
|
||||||
if _ends_with_newline(last_leaf):
|
if _ends_with_newline(last_leaf):
|
||||||
|
|||||||
Reference in New Issue
Block a user