33
44import logging
55import os
6+ from typing import Callable , List , Optional
67
78import parso
89
3637
3738
3839@hookimpl
39- def pylsp_completions (config , document , position ):
40+ def pylsp_completions (config , document , position , signatures_to_markdown = None ):
4041 """Get formatted completions for current code position"""
4142 settings = config .plugin_settings ("jedi_completion" , document_path = document .path )
4243 resolve_eagerly = settings .get ("eager" , False )
@@ -88,6 +89,7 @@ def pylsp_completions(config, document, position):
8889 resolve = resolve_eagerly ,
8990 resolve_label_or_snippet = (i < max_to_resolve ),
9091 snippet_support = snippet_support ,
92+ signatures_to_markdown = signatures_to_markdown ,
9193 )
9294 for i , c in enumerate (completions )
9395 ]
@@ -103,6 +105,7 @@ def pylsp_completions(config, document, position):
103105 resolve = resolve_eagerly ,
104106 resolve_label_or_snippet = (i < max_to_resolve ),
105107 snippet_support = snippet_support ,
108+ signatures_to_markdown = signatures_to_markdown ,
106109 )
107110 completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
108111 completion_dict ["label" ] += " object"
@@ -118,6 +121,7 @@ def pylsp_completions(config, document, position):
118121 resolve = resolve_eagerly ,
119122 resolve_label_or_snippet = (i < max_to_resolve ),
120123 snippet_support = snippet_support ,
124+ signatures_to_markdown = signatures_to_markdown ,
121125 )
122126 completion_dict ["kind" ] = lsp .CompletionItemKind .TypeParameter
123127 completion_dict ["label" ] += " object"
@@ -137,7 +141,9 @@ def pylsp_completions(config, document, position):
137141
138142
139143@hookimpl
140- def pylsp_completion_item_resolve (config , completion_item , document ):
144+ def pylsp_completion_item_resolve (
145+ config , completion_item , document , signatures_to_markdown = None
146+ ):
141147 """Resolve formatted completion for given non-resolved completion"""
142148 shared_data = document .shared_data ["LAST_JEDI_COMPLETIONS" ].get (
143149 completion_item ["label" ]
@@ -152,7 +158,12 @@ def pylsp_completion_item_resolve(config, completion_item, document):
152158
153159 if shared_data :
154160 completion , data = shared_data
155- return _resolve_completion (completion , data , markup_kind = preferred_markup_kind )
161+ return _resolve_completion (
162+ completion ,
163+ data ,
164+ markup_kind = preferred_markup_kind ,
165+ signatures_to_markdown = signatures_to_markdown ,
166+ )
156167 return completion_item
157168
158169
@@ -207,13 +218,19 @@ def use_snippets(document, position):
207218 return expr_type not in _IMPORTS and not (expr_type in _ERRORS and "import" in code )
208219
209220
210- def _resolve_completion (completion , d , markup_kind : str ):
221+ def _resolve_completion (
222+ completion ,
223+ d ,
224+ markup_kind : str ,
225+ signatures_to_markdown : Optional [Callable [[List [str ]], str ]] = None ,
226+ ):
211227 completion ["detail" ] = _detail (d )
212228 try :
213229 docs = _utils .format_docstring (
214230 d .docstring (raw = True ),
215231 signatures = [signature .to_string () for signature in d .get_signatures ()],
216232 markup_kind = markup_kind ,
233+ signatures_to_markdown = signatures_to_markdown ,
217234 )
218235 except Exception :
219236 docs = ""
@@ -228,6 +245,7 @@ def _format_completion(
228245 resolve = False ,
229246 resolve_label_or_snippet = False ,
230247 snippet_support = False ,
248+ signatures_to_markdown = None ,
231249):
232250 completion = {
233251 "label" : _label (d , resolve_label_or_snippet ),
@@ -237,7 +255,9 @@ def _format_completion(
237255 }
238256
239257 if resolve :
240- completion = _resolve_completion (completion , d , markup_kind )
258+ completion = _resolve_completion (
259+ completion , d , markup_kind , signatures_to_markdown
260+ )
241261
242262 # Adjustments for file completions
243263 if d .type == "path" :
0 commit comments