Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions pylsp/plugins/jedi_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def pylsp_completion_item_resolve(
document,
):
"""Resolve formatted completion for given non-resolved completion"""

if (
"LAST_JEDI_COMPLETIONS" not in document.shared_data
or completion_item["label"] not in document.shared_data["LAST_JEDI_COMPLETIONS"]
):
return None

shared_data = document.shared_data["LAST_JEDI_COMPLETIONS"].get(
completion_item["label"]
)
Expand All @@ -158,15 +165,13 @@ def pylsp_completion_item_resolve(
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)

if shared_data:
completion, data = shared_data
return _resolve_completion(
completion,
data,
markup_kind=preferred_markup_kind,
signature_config=config.settings().get("signature", {}),
)
return completion_item
completion, data = shared_data
return _resolve_completion(
completion,
data,
markup_kind=preferred_markup_kind,
signature_config=config.settings().get("signature", {}),
)


def is_exception_class(name):
Expand Down
22 changes: 22 additions & 0 deletions pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,31 @@ def pylsp_completions(
)
if len(results) > MAX_RESULTS_COMPLETIONS:
results = results[:MAX_RESULTS_COMPLETIONS]

# most recently retrieved completion items, used for resolution
document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"] = {
# label is the only required property; here it is assumed to be unique
result["label"]: ...
for result in results
}

return results


@hookimpl
def pylsp_completion_item_resolve(config, completion_item, document):
"""Resolve formatted completion for given non-resolved completion"""

if (
"LAST_ROPE_AUTOIMPORT_COMPLETIONS" not in document.shared_data
or completion_item["label"]
not in document.shared_data["LAST_ROPE_AUTOIMPORT_COMPLETIONS"]
):
return None

return completion_item


def _document(import_statement: str) -> str:
return """# Auto-Import\n""" + import_statement

Expand Down
14 changes: 9 additions & 5 deletions pylsp/plugins/rope_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ def pylsp_completions(config, workspace, document, position):
@hookimpl
def pylsp_completion_item_resolve(config, completion_item, document):
"""Resolve formatted completion for given non-resolved completion"""

if (
"LAST_ROPE_COMPLETIONS" not in document.shared_data
or completion_item["label"] not in document.shared_data["LAST_ROPE_COMPLETIONS"]
):
return None

shared_data = document.shared_data["LAST_ROPE_COMPLETIONS"].get(
completion_item["label"]
)
Expand All @@ -102,11 +109,8 @@ def pylsp_completion_item_resolve(config, completion_item, document):
item_capabilities = completion_capabilities.get("completionItem", {})
supported_markup_kinds = item_capabilities.get("documentationFormat", ["markdown"])
preferred_markup_kind = _utils.choose_markup_kind(supported_markup_kinds)

if shared_data:
completion, data = shared_data
return _resolve_completion(completion, data, preferred_markup_kind)
return completion_item
completion, data = shared_data
return _resolve_completion(completion, data, preferred_markup_kind)


def _sort_text(definition):
Expand Down