@@ -25,9 +25,12 @@ def _get_definition_type(self, definition):
2525 is_built_in = definition .in_builtin_module
2626 # if definition.type not in ['import', 'keyword'] and is_built_in():
2727 # 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'
3134
3235 def _additional_info (self , completion ):
3336 """Provide additional information about the completion object."""
@@ -107,8 +110,13 @@ def _get_call_signatures_with_args(self, script):
107110 sig = {"name" : "" , "description" : "" , "docstring" : "" ,
108111 "paramindex" : 0 , "params" : [], "bracketstart" : []}
109112 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+
112120 sig ["name" ] = signature .name
113121 sig ["paramindex" ] = signature .index
114122 sig ["bracketstart" ].append (signature .index )
@@ -129,8 +137,13 @@ def _get_call_signatures_with_args(self, script):
129137 # if name.startswith('*'):
130138 # continue
131139 #_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 })
134147 return _signatures
135148
136149 def _serialize_completions (self , script , identifier = None , prefix = '' ):
@@ -168,8 +181,12 @@ def _serialize_completions(self, script, identifier=None, prefix=''):
168181 _completion ['text' ] = name
169182 _completion ['displayText' ] = name
170183 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' ] = ''
173190 else :
174191 _completion ['description' ] = self ._generate_signature (
175192 signature )
@@ -181,17 +198,26 @@ def _serialize_completions(self, script, identifier=None, prefix=''):
181198 completions = []
182199 for completion in completions :
183200 if self .show_doc_strings :
184- description = completion .docstring ()
201+ try :
202+ description = completion .docstring ()
203+ except Exception :
204+ description = ''
185205 else :
186206 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+
195221 for c in _completions :
196222 if c ['text' ] == _completion ['text' ]:
197223 c ['type' ] = _completion ['type' ]
@@ -348,6 +374,13 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal
348374 container = parent .name if parent .type != 'module' else ''
349375 except Exception :
350376 container = ''
377+
378+ try :
379+ docstring = definition .docstring ()
380+ rawdocstring = definition .docstring (raw = True )
381+ except Exception :
382+ docstring = ''
383+ rawdocstring = ''
351384 _definition = {
352385 'text' : definition .name ,
353386 'type' : self ._get_definition_type (definition ),
@@ -356,8 +389,8 @@ def _get_definitionsx(self, definitions, identifier=None, ignoreNoModulePath=Fal
356389 'container' : container ,
357390 'range' : definitionRange ,
358391 'description' : definition .description ,
359- 'docstring' : definition . docstring () ,
360- 'raw_docstring' : definition . docstring ( raw = True ) ,
392+ 'docstring' : docstring ,
393+ 'raw_docstring' : rawdocstring ,
361394 'signature' : self ._generate_signature (definition )
362395 }
363396 _definitions .append (_definition )
@@ -388,6 +421,13 @@ def _serialize_definitions(self, definitions, identifier=None):
388421 container = parent .name if parent .type != 'module' else ''
389422 except Exception :
390423 container = ''
424+
425+ try :
426+ docstring = definition .docstring ()
427+ rawdocstring = definition .docstring (raw = True )
428+ except Exception :
429+ docstring = ''
430+ rawdocstring = ''
391431 _definition = {
392432 'text' : definition .name ,
393433 'type' : self ._get_definition_type (definition ),
@@ -396,8 +436,8 @@ def _serialize_definitions(self, definitions, identifier=None):
396436 'container' : container ,
397437 'range' : self ._extract_range (definition ),
398438 'description' : definition .description ,
399- 'docstring' : definition . docstring () ,
400- 'raw_docstring' : definition . docstring ( raw = True )
439+ 'docstring' : docstring ,
440+ 'raw_docstring' : rawdocstring
401441 }
402442 _definitions .append (_definition )
403443 except Exception as e :
@@ -411,13 +451,19 @@ def _serialize_tooltip(self, definitions, identifier=None):
411451 description = None
412452 if definition .type in ['class' , 'function' ]:
413453 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 = ''
415458 if not description and not hasattr (definition , 'get_line_code' ):
416459 # jedi returns an empty string for compiled objects
417460 description = definition .docstring ().strip ()
418461 if definition .type == 'module' :
419462 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 = ''
421467 if not description and hasattr (definition , 'get_line_code' ):
422468 # jedi returns an empty string for compiled objects
423469 description = definition .docstring ().strip ()
@@ -540,20 +586,31 @@ def watch(self):
540586
541587if __name__ == '__main__' :
542588 cachePrefix = 'v'
589+ modulesToLoad = ''
543590 if len (sys .argv ) > 0 and sys .argv [1 ] == 'preview' :
544591 jediPath = os .path .join (os .path .dirname (__file__ ), 'preview' )
545592 jediPreview = True
593+ if len (sys .argv ) > 2 :
594+ modulesToLoad = sys .argv [2 ]
546595 elif len (sys .argv ) > 0 and sys .argv [1 ] == 'custom' :
547596 jediPath = sys .argv [2 ]
548597 jediPreview = True
549598 cachePrefix = 'custom_v'
599+ if len (sys .argv ) > 3 :
600+ modulesToLoad = sys .argv [3 ]
550601 else :
602+ #std
551603 jediPath = os .path .join (os .path .dirname (__file__ ), 'release' )
604+ if len (sys .argv ) > 2 :
605+ modulesToLoad = sys .argv [2 ]
606+
552607 sys .path .insert (0 , jediPath )
553608 import jedi
554609 if jediPreview :
555610 jedi .settings .cache_directory = os .path .join (
556611 jedi .settings .cache_directory , cachePrefix + jedi .__version__ .replace ('.' , '' ))
557612 # remove jedi from path after we import it so it will not be completed
558613 sys .path .pop (0 )
614+ if len (modulesToLoad ) > 0 :
615+ jedi .preload_module (modulesToLoad .split (',' ))
559616 JediCompletion ().watch ()
0 commit comments