def lsp_completion_item( completion: Completion, char_before_cursor: str, enable_snippets: bool, resolve_eagerly: bool, markup_kind: MarkupKind, ) -> CompletionItem: """Using a Jedi completion, obtain a jedi completion item.""" completion_name = completion.name name_clean = clean_completion_name(completion_name, char_before_cursor) lsp_type = get_lsp_completion_type(completion.type) completion_item = CompletionItem( label=completion_name, filter_text=completion_name, kind=lsp_type, sort_text=complete_sort_name(completion), insert_text=name_clean, insert_text_format=InsertTextFormat.PlainText, ) _MOST_RECENT_COMPLETIONS[completion_name] = completion if resolve_eagerly: completion_item = lsp_completion_item_resolve( completion_item, markup_kind=markup_kind ) if not enable_snippets: return completion_item if lsp_type not in _LSP_TYPE_FOR_SNIPPET: return completion_item signatures = completion.get_signatures() if not signatures: return completion_item try: snippet_signature = get_snippet_signature(signatures[0]) except Exception: # pylint: disable=broad-except return completion_item new_text = completion_name + snippet_signature completion_item.insertText = new_text completion_item.insertTextFormat = InsertTextFormat.Snippet return completion_item
def lsp_completion_item( name: Completion, char_before_cursor: str, enable_snippets: bool, markup_kind: MarkupKind, ) -> CompletionItem: """Using a Jedi completion, obtain a jedi completion item.""" name_name = name.name name_clean = clean_completion_name(name_name, char_before_cursor) lsp_type = get_lsp_completion_type(name.type) completion_item = CompletionItem( label=name_name, filter_text=name_name, kind=lsp_type, detail=name.description, documentation=MarkupContent(kind=markup_kind, value=name.docstring()), sort_text=complete_sort_name(name), insert_text=name_clean, insert_text_format=InsertTextFormat.PlainText, ) if not enable_snippets: return completion_item if lsp_type not in _LSP_TYPE_FOR_SNIPPET: return completion_item signatures = name.get_signatures() if not signatures: return completion_item try: snippet_signature = get_snippet_signature(signatures[0]) except Exception: # pylint: disable=broad-except return completion_item new_text = name_name + snippet_signature completion_item.insertText = new_text completion_item.insertTextFormat = InsertTextFormat.Snippet return completion_item