(
self, document: Document, complete_event: CompleteEvent
)
| 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 |
| 259 | except NotImplementedError: |
| 260 | # See: https://github.com/jonathanslenders/ptpython/issues/223 |
| 261 | pass |
| 262 | except Exception: |
| 263 | # Suppress all other Jedi exceptions. |
| 264 | pass |
| 265 | else: |
| 266 | # Move function parameters to the top. |
| 267 | jedi_completions = sorted( |
| 268 | jedi_completions, |
| 269 | key=lambda jc: ( |
| 270 | # Params first. |
| 271 | jc.type != "param", |
| 272 | # Private at the end. |
| 273 | jc.name.startswith("_"), |
no test coverage detected