@@ -50,7 +50,10 @@ def pylsp_completions(config, document, position):
5050 return None
5151
5252 completion_capabilities = config .capabilities .get ('textDocument' , {}).get ('completion' , {})
53- snippet_support = completion_capabilities .get ('completionItem' , {}).get ('snippetSupport' )
53+ item_capabilities = completion_capabilities .get ('completionItem' , {})
54+ snippet_support = item_capabilities .get ('snippetSupport' )
55+ supported_markup_kinds = item_capabilities .get ('documentationFormat' , ['markdown' ])
56+ preferred_markup_kind = _utils .choose_markup_kind (supported_markup_kinds )
5457
5558 should_include_params = settings .get ('include_params' )
5659 should_include_class_objects = settings .get ('include_class_objects' , True )
@@ -69,7 +72,8 @@ def pylsp_completions(config, document, position):
6972 ready_completions = [
7073 _format_completion (
7174 c ,
72- include_params ,
75+ markup_kind = preferred_markup_kind ,
76+ include_params = include_params ,
7377 resolve = resolve_eagerly ,
7478 resolve_label_or_snippet = (i < max_to_resolve )
7579 )
@@ -82,7 +86,8 @@ def pylsp_completions(config, document, position):
8286 if c .type == 'class' :
8387 completion_dict = _format_completion (
8488 c ,
85- False ,
89+ markup_kind = preferred_markup_kind ,
90+ include_params = False ,
8691 resolve = resolve_eagerly ,
8792 resolve_label_or_snippet = (i < max_to_resolve )
8893 )
@@ -119,12 +124,18 @@ def pylsp_completions(config, document, position):
119124
120125
121126@hookimpl
122- def pylsp_completion_item_resolve (completion_item , document ):
127+ def pylsp_completion_item_resolve (config , completion_item , document ):
123128 """Resolve formatted completion for given non-resolved completion"""
124129 shared_data = document .shared_data ['LAST_JEDI_COMPLETIONS' ].get (completion_item ['label' ])
130+
131+ completion_capabilities = config .capabilities .get ('textDocument' , {}).get ('completion' , {})
132+ item_capabilities = completion_capabilities .get ('completionItem' , {})
133+ supported_markup_kinds = item_capabilities .get ('documentationFormat' , ['markdown' ])
134+ preferred_markup_kind = _utils .choose_markup_kind (supported_markup_kinds )
135+
125136 if shared_data :
126137 completion , data = shared_data
127- return _resolve_completion (completion , data )
138+ return _resolve_completion (completion , data , markup_kind = preferred_markup_kind )
128139 return completion_item
129140
130141
@@ -178,18 +189,25 @@ def use_snippets(document, position):
178189 not (expr_type in _ERRORS and 'import' in code ))
179190
180191
181- def _resolve_completion (completion , d ):
192+ def _resolve_completion (completion , d , markup_kind : str ):
182193 # pylint: disable=broad-except
183194 completion ['detail' ] = _detail (d )
184195 try :
185- docs = _utils .format_docstring (d .docstring ())
196+ docs = _utils .format_docstring (
197+ d .docstring (raw = True ),
198+ signatures = [
199+ signature .to_string ()
200+ for signature in d .get_signatures ()
201+ ],
202+ markup_kind = markup_kind
203+ )
186204 except Exception :
187205 docs = ''
188206 completion ['documentation' ] = docs
189207 return completion
190208
191209
192- def _format_completion (d , include_params = True , resolve = False , resolve_label_or_snippet = False ):
210+ def _format_completion (d , markup_kind : str , include_params = True , resolve = False , resolve_label_or_snippet = False ):
193211 completion = {
194212 'label' : _label (d , resolve_label_or_snippet ),
195213 'kind' : _TYPE_MAP .get (d .type ),
@@ -198,7 +216,7 @@ def _format_completion(d, include_params=True, resolve=False, resolve_label_or_s
198216 }
199217
200218 if resolve :
201- completion = _resolve_completion (completion , d )
219+ completion = _resolve_completion (completion , d , markup_kind )
202220
203221 if d .type == 'path' :
204222 path = osp .normpath (d .name )
0 commit comments