@@ -50,7 +50,10 @@ def pylsp_completions(config, document, position):
50
50
return None
51
51
52
52
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 )
54
57
55
58
should_include_params = settings .get ('include_params' )
56
59
should_include_class_objects = settings .get ('include_class_objects' , True )
@@ -69,7 +72,8 @@ def pylsp_completions(config, document, position):
69
72
ready_completions = [
70
73
_format_completion (
71
74
c ,
72
- include_params ,
75
+ markup_kind = preferred_markup_kind ,
76
+ include_params = include_params ,
73
77
resolve = resolve_eagerly ,
74
78
resolve_label_or_snippet = (i < max_to_resolve )
75
79
)
@@ -82,7 +86,8 @@ def pylsp_completions(config, document, position):
82
86
if c .type == 'class' :
83
87
completion_dict = _format_completion (
84
88
c ,
85
- False ,
89
+ markup_kind = preferred_markup_kind ,
90
+ include_params = False ,
86
91
resolve = resolve_eagerly ,
87
92
resolve_label_or_snippet = (i < max_to_resolve )
88
93
)
@@ -119,12 +124,18 @@ def pylsp_completions(config, document, position):
119
124
120
125
121
126
@hookimpl
122
- def pylsp_completion_item_resolve (completion_item , document ):
127
+ def pylsp_completion_item_resolve (config , completion_item , document ):
123
128
"""Resolve formatted completion for given non-resolved completion"""
124
129
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
+
125
136
if shared_data :
126
137
completion , data = shared_data
127
- return _resolve_completion (completion , data )
138
+ return _resolve_completion (completion , data , markup_kind = preferred_markup_kind )
128
139
return completion_item
129
140
130
141
@@ -178,18 +189,25 @@ def use_snippets(document, position):
178
189
not (expr_type in _ERRORS and 'import' in code ))
179
190
180
191
181
- def _resolve_completion (completion , d ):
192
+ def _resolve_completion (completion , d , markup_kind : str ):
182
193
# pylint: disable=broad-except
183
194
completion ['detail' ] = _detail (d )
184
195
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
+ )
186
204
except Exception :
187
205
docs = ''
188
206
completion ['documentation' ] = docs
189
207
return completion
190
208
191
209
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 ):
193
211
completion = {
194
212
'label' : _label (d , resolve_label_or_snippet ),
195
213
'kind' : _TYPE_MAP .get (d .type ),
@@ -198,7 +216,7 @@ def _format_completion(d, include_params=True, resolve=False, resolve_label_or_s
198
216
}
199
217
200
218
if resolve :
201
- completion = _resolve_completion (completion , d )
219
+ completion = _resolve_completion (completion , d , markup_kind )
202
220
203
221
if d .type == 'path' :
204
222
path = osp .normpath (d .name )
0 commit comments