@@ -25,9 +25,12 @@ def _get_definition_type(self, definition): |
25 | 25 | is_built_in = definition.in_builtin_module |
26 | 26 | # if definition.type not in ['import', 'keyword'] and is_built_in(): |
27 | 27 | # return 'builtin' |
28 | | - if definition.type in ['statement'] and definition.name.isupper(): |
29 | | - return 'constant' |
30 | | - return self.basic_types.get(definition.type, definition.type) |
| 28 | + try: |
| 29 | + if definition.type in ['statement'] and definition.name.isupper(): |
| 30 | + return 'constant' |
| 31 | + return self.basic_types.get(definition.type, definition.type) |
| 32 | + except Exception: |
| 33 | + return 'builtin' |
31 | 34 |
|
32 | 35 | def _additional_info(self, completion): |
33 | 36 | """Provide additional information about the completion object.""" |
@@ -107,8 +110,13 @@ def _get_call_signatures_with_args(self, script): |
107 | 110 | sig = {"name": "", "description": "", "docstring": "", |
108 | 111 | "paramindex": 0, "params": [], "bracketstart": []} |
109 | 112 | sig["description"] = signature.description |
110 | | - sig["docstring"] = signature.docstring() |
111 | | - sig["raw_docstring"] = signature.docstring(raw=True) |
| 113 | + try: |
| 114 | + sig["docstring"] = signature.docstring() |
| 115 | + sig["raw_docstring"] = signature.docstring(raw=True) |
| 116 | + except Exception: |
| 117 | + sig["docstring"] = '' |
| 118 | + sig["raw_docstring"] = '' |
| 119 | + |
112 | 120 | sig["name"] = signature.name |
113 | 121 | sig["paramindex"] = signature.index |
114 | 122 | sig["bracketstart"].append(signature.index) |
@@ -129,8 +137,13 @@ def _get_call_signatures_with_args(self, script): |
129 | 137 | # if name.startswith('*'): |
130 | 138 | # continue |
131 | 139 | #_signatures.append((signature, name, value)) |
132 | | - sig["params"].append({"name": name, "value": value, "docstring": param.docstring( |
133 | | - ), "description": param.description}) |
| 140 | + paramDocstring = '' |
| 141 | + try: |
| 142 | + paramDocstring = param.docstring() |
| 143 | + except Exception: |
| 144 | + paramDocstring = '' |
| 145 | + |
| 146 | + sig["params"].append({"name": name, "value": value, "docstring": paramDocstring, "description": param.description}) |
134 | 147 | return _signatures |
135 | 148 |
|
136 | 149 | def _serialize_completions(self, script, identifier=None, prefix=''): |
@@ -168,8 +181,12 @@ def _serialize_completions(self, script, identifier=None, prefix=''): |
168 | 181 | _completion['text'] = name |
169 | 182 | _completion['displayText'] = name |
170 | 183 | if self.show_doc_strings: |
171 | | - _completion['description'] = signature.docstring() |
172 | | - _completion['raw_docstring'] = signature.docstring(raw=True) |
| 184 | + try: |
| 185 | + _completion['description'] = signature.docstring() |
| 186 | + _completion['raw_docstring'] = signature.docstring(raw=True) |
| 187 | + except Exception: |
| 188 | + _completion['description'] = '' |
| 189 | + _completion['raw_docstring'] = '' |
173 | 190 | else: |
174 | 191 | _completion['description'] = self._generate_signature( |
175 | 192 | signature) |
@@ -181,17 +198,26 @@ def _serialize_completions(self, script, identifier=None, prefix=''): |
181 | 198 | completions = [] |
182 | 199 | for completion in completions: |
183 | 200 | if self.show_doc_strings: |
184 | | - description = completion.docstring() |
| 201 | + try: |
| 202 | + description = completion.docstring() |
| 203 | + except Exception: |
| 204 | + description = '' |
185 | 205 | else: |
186 | 206 | description = self._generate_signature(completion) |
187 | | - _completion = { |
188 | | - 'text': completion.name, |
189 | | - 'type': self._get_definition_type(completion), |
190 | | - 'raw_type': completion.type, |
191 | | - 'description': description, |
192 | | - 'raw_docstring': completion.docstring(raw=True), |
193 | | - 'rightLabel': self._additional_info(completion) |
194 | | - } |
| 207 | + |
| 208 | + try: |
| 209 | + rawDocstring = completion.docstring(raw=True) |
| 210 | + _completion = { |
| 211 | + 'text': completion.name, |
| 212 | + 'type': self._get_definition_type(completion), |
| 213 | + 'raw_type': completion.type, |
| 214 | + 'description': description, |
| 215 | + 'raw_docstring': rawDocstring, |
| 216 | + 'rightLabel': self._additional_info(completion) |
| 217 | + } |
| 218 | + except Exception: |
| 219 | + continue |
| 220 | + |
195 | 221 | for c in _completions: |
196 | 222 | if c['text'] == _completion['text']: |
197 | 223 | c['type'] = _completion['type'] |
@@ -348,6 +374,13 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal |
348 | 374 | container = parent.name if parent.type != 'module' else '' |
349 | 375 | except Exception: |
350 | 376 | container = '' |
| 377 | + |
| 378 | + try: |
| 379 | + docstring = definition.docstring() |
| 380 | + rawdocstring = definition.docstring(raw=True) |
| 381 | + except Exception: |
| 382 | + docstring = '' |
| 383 | + rawdocstring = '' |
351 | 384 | _definition = { |
352 | 385 | 'text': definition.name, |
353 | 386 | 'type': self._get_definition_type(definition), |
@@ -356,8 +389,8 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal |
356 | 389 | 'container': container, |
357 | 390 | 'range': definitionRange, |
358 | 391 | 'description': definition.description, |
359 | | - 'docstring': definition.docstring(), |
360 | | - 'raw_docstring': definition.docstring(raw=True), |
| 392 | + 'docstring': docstring, |
| 393 | + 'raw_docstring': rawdocstring, |
361 | 394 | 'signature': self._generate_signature(definition) |
362 | 395 | } |
363 | 396 | _definitions.append(_definition) |
@@ -388,6 +421,13 @@ def _serialize_definitions(self, definitions, identifier=None): |
388 | 421 | container = parent.name if parent.type != 'module' else '' |
389 | 422 | except Exception: |
390 | 423 | container = '' |
| 424 | + |
| 425 | + try: |
| 426 | + docstring = definition.docstring() |
| 427 | + rawdocstring = definition.docstring(raw=True) |
| 428 | + except Exception: |
| 429 | + docstring = '' |
| 430 | + rawdocstring = '' |
391 | 431 | _definition = { |
392 | 432 | 'text': definition.name, |
393 | 433 | 'type': self._get_definition_type(definition), |
@@ -396,8 +436,8 @@ def _serialize_definitions(self, definitions, identifier=None): |
396 | 436 | 'container': container, |
397 | 437 | 'range': self._extract_range(definition), |
398 | 438 | 'description': definition.description, |
399 | | - 'docstring': definition.docstring(), |
400 | | - 'raw_docstring': definition.docstring(raw=True) |
| 439 | + 'docstring': docstring, |
| 440 | + 'raw_docstring': rawdocstring |
401 | 441 | } |
402 | 442 | _definitions.append(_definition) |
403 | 443 | except Exception as e: |
@@ -411,13 +451,19 @@ def _serialize_tooltip(self, definitions, identifier=None): |
411 | 451 | description = None |
412 | 452 | if definition.type in ['class', 'function']: |
413 | 453 | signature = self._generate_signature(definition) |
414 | | - description = definition.docstring(raw=True).strip() |
| 454 | + try: |
| 455 | + description = definition.docstring(raw=True).strip() |
| 456 | + except Exception: |
| 457 | + description = '' |
415 | 458 | if not description and not hasattr(definition, 'get_line_code'): |
416 | 459 | # jedi returns an empty string for compiled objects |
417 | 460 | description = definition.docstring().strip() |
418 | 461 | if definition.type == 'module': |
419 | 462 | signature = definition.full_name |
420 | | - description = definition.docstring(raw=True).strip() |
| 463 | + try: |
| 464 | + description = definition.docstring(raw=True).strip() |
| 465 | + except Exception: |
| 466 | + description = '' |
421 | 467 | if not description and hasattr(definition, 'get_line_code'): |
422 | 468 | # jedi returns an empty string for compiled objects |
423 | 469 | description = definition.docstring().strip() |
@@ -540,20 +586,31 @@ def watch(self): |
540 | 586 |
|
541 | 587 | if __name__ == '__main__': |
542 | 588 | cachePrefix = 'v' |
| 589 | + modulesToLoad = '' |
543 | 590 | if len(sys.argv) > 0 and sys.argv[1] == 'preview': |
544 | 591 | jediPath = os.path.join(os.path.dirname(__file__), 'preview') |
545 | 592 | jediPreview = True |
| 593 | + if len(sys.argv) > 2: |
| 594 | + modulesToLoad = sys.argv[2] |
546 | 595 | elif len(sys.argv) > 0 and sys.argv[1] == 'custom': |
547 | 596 | jediPath = sys.argv[2] |
548 | 597 | jediPreview = True |
549 | 598 | cachePrefix = 'custom_v' |
| 599 | + if len(sys.argv) > 3: |
| 600 | + modulesToLoad = sys.argv[3] |
550 | 601 | else: |
| 602 | + #std |
551 | 603 | jediPath = os.path.join(os.path.dirname(__file__), 'release') |
| 604 | + if len(sys.argv) > 2: |
| 605 | + modulesToLoad = sys.argv[2] |
| 606 | + |
552 | 607 | sys.path.insert(0, jediPath) |
553 | 608 | import jedi |
554 | 609 | if jediPreview: |
555 | 610 | jedi.settings.cache_directory = os.path.join( |
556 | 611 | jedi.settings.cache_directory, cachePrefix + jedi.__version__.replace('.', '')) |
557 | 612 | # remove jedi from path after we import it so it will not be completed |
558 | 613 | sys.path.pop(0) |
| 614 | + if len(modulesToLoad) > 0: |
| 615 | + jedi.preload_module(modulesToLoad.split(',')) |
559 | 616 | JediCompletion().watch() |