Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve label detail support in completions #2212

Merged
merged 5 commits into from
Apr 2, 2023
Merged
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: 12 additions & 11 deletions plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ def format_completion(
# labelDetails.detail is likely a function signature
trigger = lsp_label + lsp_label_detail
annotation = lsp_label_description or lsp_detail
elif lsp_label.startswith(lsp_filter_text):
trigger = lsp_label
annotation = lsp_detail
if lsp_label_detail:
details.append(html.escape(lsp_label + lsp_label_detail))
if lsp_label_description:
details.append(html.escape(lsp_label_description))
else:
trigger = lsp_filter_text
annotation = lsp_detail
details.append(html.escape(lsp_label + lsp_label_detail))
if lsp_label.startswith(lsp_filter_text):
trigger = lsp_label
if lsp_label_detail:
details.append(html.escape(lsp_label + lsp_label_detail))
else:
trigger = lsp_filter_text
details.append(html.escape(lsp_label + lsp_label_detail))
if lsp_label_description:
details.append(html.escape(lsp_label_description))
annotation = lsp_label_description
if lsp_detail:
details.append(html.escape(lsp_detail))
else:
annotation = lsp_detail
if item.get('deprecated') or CompletionItemTag.Deprecated in item.get('tags', []):
annotation = "DEPRECATED - " + annotation if annotation else "DEPRECATED"
text_edit = item.get('textEdit', item_defaults.get('editRange'))
Expand Down
35 changes: 33 additions & 2 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def check(
)
check(
resolve_support=False,
expected_regex=r"^f\(X& x\) \| does things$",
expected_regex=r"^f\(X& x\)$",
label="f",
label_details={"detail": "(X& x)", "description": "does things"}
)
Comment on lines 709 to 714
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those test are poor-mans version of the new ones so it would possibly be OK to remove those and convert to the new ones, if those test anything extra.

I say "poor-mans" version because those ignore "annotation" for example.

Expand All @@ -726,7 +726,7 @@ def check(
)
check(
resolve_support=True,
expected_regex=r"^<a href='subl:lsp_run_text_command_helper {\S+}'>More</a> \| f\(X&amp; x\) \| does things$", # noqa: E501
expected_regex=r"^<a href='subl:lsp_run_text_command_helper {\S+}'>More</a> \| f\(X&amp; x\)$", # noqa: E501
label="f",
label_details={"detail": "(X& x)", "description": "does things"}
)
Expand Down Expand Up @@ -973,6 +973,37 @@ def test_label_details_3(self) -> None:
annotation='NaiveDateTime'
)

def test_label_details_4(self) -> None:
# More relevant "labelDetails.description" ends up in the annotation rather than "detail".
self._verify_completion(
{
"detail": "Auto-import",
"label": "escape",
"labelDetails": {
"description": "html"
},
},
trigger='escape',
annotation='html',
details='Auto-import',
)

def test_label_details_5(self) -> None:
# filterText overrides label if doesn't match label+labelDetails.detail
self._verify_completion(
{
"detail": "Auto-import",
"filterText": "escapeNew",
"label": "escape",
"labelDetails": {
"detail": "(str)",
},
},
trigger='escapeNew',
annotation='Auto-import',
details='escape(str)',
)

def test_filter_text_1(self) -> None:
self._verify_completion(
{
Expand Down