MCPcopy Index your code
hub / github.com/prompt-toolkit/ptpython / JediCompleter

Class JediCompleter

src/ptpython/completer.py:201–294  ·  view source on GitHub ↗

Autocompleter that uses the Jedi library.

Source from the content-addressed store, hash-verified

199
200
201class JediCompleter(Completer):
202 """
203 Autocompleter that uses the Jedi library.
204 """
205
206 def __init__(
207 self,
208 get_globals: Callable[[], dict[str, Any]],
209 get_locals: Callable[[], dict[str, Any]],
210 ) -> None:
211 super().__init__()
212
213 self.get_globals = get_globals
214 self.get_locals = get_locals
215
216 def get_completions(
217 self, document: Document, complete_event: CompleteEvent
218 ) -> Iterable[Completion]:
219 script = get_jedi_script_from_document(
220 document, self.get_locals(), self.get_globals()
221 )
222
223 if script:
224 try:
225 jedi_completions = script.complete(
226 column=document.cursor_position_col,
227 line=document.cursor_position_row + 1,
228 )
229 except TypeError:
230 # Issue #9: bad syntax causes completions() to fail in jedi.
231 # https://github.com/jonathanslenders/python-prompt-toolkit/issues/9
232 pass
233 except UnicodeDecodeError:
234 # Issue #43: UnicodeDecodeError on OpenBSD
235 # https://github.com/jonathanslenders/python-prompt-toolkit/issues/43
236 pass
237 except AttributeError:
238 # Jedi issue #513: https://github.com/davidhalter/jedi/issues/513
239 pass
240 except ValueError:
241 # Jedi issue: "ValueError: invalid \x escape"
242 pass
243 except KeyError:
244 # Jedi issue: "KeyError: u'a_lambda'."
245 # https://github.com/jonathanslenders/ptpython/issues/89
246 pass
247 except OSError:
248 # Jedi issue: "IOError: No such file or directory."
249 # https://github.com/jonathanslenders/ptpython/issues/71
250 pass
251 except AssertionError:
252 # In jedi.parser.__init__.py: 227, in remove_last_newline,
253 # the assertion "newline.value.endswith('\n')" can fail.
254 pass
255 except SystemError:
256 # In jedi.api.helpers.py: 144, in get_stack_at_position
257 # raise SystemError("This really shouldn't happen. There's a bug in Jedi.")
258 pass

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected