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

Move lsp detail into autocomplete annotation #1569

Merged
merged 3 commits into from
Feb 19, 2021
Merged

Move lsp detail into autocomplete annotation #1569

merged 3 commits into from
Feb 19, 2021

Conversation

dvcrn
Copy link
Contributor

@dvcrn dvcrn commented Feb 5, 2021

Move item.get("detail") into st_annotation to effectively inline typehints

Tested so far only with Golang

References #1549

@rchl
Copy link
Member

rchl commented Feb 5, 2021

There is no need to have a duplicate text in the "detail" field (at the bottom of the popup). The logic should probably be to flip those values.

@rwols
Copy link
Member

rwols commented Feb 5, 2021

For clangd, this results in:

before:
Schermafbeelding 2021-02-05 om 20 58 42

after:
Schermafbeelding 2021-02-05 om 21 00 36

@rwols
Copy link
Member

rwols commented Feb 5, 2021

So the lsp_label is now "forgotten" with this PR. Perhaps the label can go into the st_details field?

@dvcrn
Copy link
Contributor Author

dvcrn commented Feb 6, 2021

For clangd, this results in:

before:
Schermafbeelding 2021-02-05 om 20 58 42

after:
Schermafbeelding 2021-02-05 om 21 00 36

Hrrm I wonder what a good solution for this is. Either come up with some logic to pick the right thing, or maybe have it settable per lsp?

@rwols
Copy link
Member

rwols commented Feb 6, 2021

I think having the lsp_label in the st_details slot should be sufficient. Try this?

diff --git a/plugin/core/views.py b/plugin/core/views.py
index ac54b66..de70476 100644
--- a/plugin/core/views.py
+++ b/plugin/core/views.py
@@ -662,21 +662,19 @@ def format_completion(
 
     lsp_label = item["label"]
     lsp_filter_text = item.get("filterText")
-    lsp_detail = html.escape(item.get("detail") or "").replace('\n', ' ')
-
-    if lsp_filter_text and lsp_filter_text != lsp_label:
-        st_trigger = lsp_filter_text
-    else:
-        st_trigger = lsp_label
-
-    st_annotation = item.get("detail") or ""
+    st_annotation = (item.get("detail") or "").replace('\n', ' ')
 
     st_details = ""
     if can_resolve_completion_items or item.get("documentation"):
         st_details += make_command_link("lsp_resolve_docs", "More", {"index": index})
-        st_details += " | " if lsp_detail else ""
 
-    st_details += "<p>{}</p>".format(lsp_detail)
+    if lsp_filter_text and lsp_filter_text != lsp_label:
+        st_trigger = lsp_filter_text
+        if st_details:
+            st_details += " | "
+        st_details += "<p>{}</p>".format(html.escape(lsp_label))
+    else:
+        st_trigger = lsp_label
 
     # NOTE: Some servers return "textEdit": null. We have to check if it's truthy.
     if item.get("textEdit") or item.get("additionalTextEdits") or item.get("command"):

@dvcrn
Copy link
Contributor Author

dvcrn commented Feb 10, 2021

Sorry I didn't have time on hand yet to try this. I'll be getting back to this on the weekend

@predragnikolic
Copy link
Member

Keep in mind that CompletionItem.detail is optional.

By default the request can only delay the computation of the detail and documentation properties.

Which means that there are probably servers that will return the detail only when a completion item is resolved.

@dvcrn
Copy link
Contributor Author

dvcrn commented Feb 15, 2021

I applied the patch from rwols and wanted to test this a bit. I noticed that on tyescript/javascript the support is still lacking a good bit behind vscode, but that's probably unrelated to this because the information is neither in label nor detail

ST3:
Screen Shot 2021-02-15 at 12 50 44
Screen Shot 2021-02-15 at 12 50 50

Vscode:
Screen Shot 2021-02-15 at 12 52 07

@rwols for clangd, how is the support with the latest patch that you provided?

@rwols
Copy link
Member

rwols commented Feb 19, 2021

I totally missed that you wrote a reply, sorry for the delay.

for clangd, how is the support with the latest patch that you provided?

It looks okay. I think we should move to putting the lsp_label in the st_detail slot anyway, because we can use minihtml in the st_detail slot. That means that we can add coloring for #1570.

Which means that there are probably servers that will return the detail only when a completion item is resolved.

True. But the lsp_details are then shown with the "More" button.

Copy link
Member

@rwols rwols left a comment

Choose a reason for hiding this comment

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

Let's try this out. It's a tiny diff so it's easy to blame/revert anyway.

@rwols rwols merged commit c0ae90f into sublimelsp:st4000-exploration Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants