Completions fail with KeyError in parser_cache if fast_parser is False #1888
Open
Description
The autocompletion jedi.Script#complete
fails with because the parso.cache.parser_cache
is empty when setting jedi.settings.fast_parser = False
.
Try this script to reproduce the issue:
import jedi
jedi.settings.fast_parser = False
script = jedi.Script(
code="im", # Just starting a new file. Trying to get 'import' completed
path="", # Using "" for unsaved files as described in the docstring
)
# Complete at the end of the code
completions = script.complete()
print(completions)
Traceback:
Traceback (most recent call last):
File "/home/benjamin/misc/jedi/./jedi-18-1-bug.py", line 12, in <module>
completions = script.complete()
File "/home/benjamin/misc/jedi/jedi/api/helpers.py", line 487, in wrapper
return func(self, line, column, *args, **kwargs)
File "/home/benjamin/misc/jedi/jedi/api/__init__.py", line 214, in complete
return completion.complete()
File "/home/benjamin/misc/jedi/jedi/api/completion.py", line 170, in complete
cached_name, completion_names = self._complete_python(leaf)
File "/home/benjamin/misc/jedi/jedi/api/completion.py", line 314, in _complete_python
completion_names += self._complete_global_scope()
File "/home/benjamin/misc/jedi/jedi/api/completion.py", line 379, in _complete_global_scope
for filter in filters:
File "/home/benjamin/misc/jedi/jedi/inference/context.py", line 486, in get_global_filters
yield from context.get_filters(
File "/home/benjamin/misc/jedi/jedi/inference/context.py", line 318, in get_filters
next(filters, None)
File "/home/benjamin/misc/jedi/jedi/inference/value/module.py", line 63, in get_filters
ParserTreeFilter(
File "/home/benjamin/misc/jedi/jedi/inference/filters.py", line 138, in __init__
super().__init__(parent_context, node_context)
File "/home/benjamin/misc/jedi/jedi/inference/filters.py", line 100, in __init__
self._parso_cache_node = get_parso_cache_node(
File "/home/benjamin/misc/jedi/jedi/parser_utils.py", line 287, in get_parso_cache_node
return parser_cache[grammar._hashed][path]
KeyError: '715ad56c5f4f8395092c58b6b6f2deb4f906f81380929a836bd86ab253634875'
Using git bisect
I found that the first commit with this bug is b9067cc.