-
Notifications
You must be signed in to change notification settings - Fork 185
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
Use filterText as trigger, if it's present #990
Conversation
The LSP-filterText is truly the suitable thing for the ST-trigger. If an LSP-filterText is present, we have a bit of a problem on where to stuff all of the interesting things. I decided to put the LSP-label into the ST-annotation field. That leaves us with only the ST-details to fill in. If there's an LSP-detail, use that. Otherwise, use the LSP-documentation for the ST-details. In case there's no LSP-filterText, we are supposed to use the LSP-label for the ST-trigger. In that case there are enough fields: the LSP-detail can go into the ST-annotation, and the LSP-documentation and go into the ST-details.
I know we had some discussion about this in the past, and we ultimately decided to keep using the LSP-label for ST-trigger. We went back to the LSP-label because the completions looked too "bare". But now we can stuff the LSP-label in the ST-annotation field. This fixes the clangd problem of decorated labels. @ayoub-benali, could you try out this branch and see if metals is working better with this, now that we have an ST4 AC widget? This PR is also inspired by findings and investigations in https://gist.github.com/jskinner/4dfa6d86f848e1e1e583883507369b67 |
@rwols, can you check Implement all members for metals? #771
|
plugin/completion.py
Outdated
st_trigger = lsp_filter_text | ||
st_annotation = lsp_label | ||
# Try to keep fields non-empty. If there's no `detail` field, attempt to use the `documentation` field. | ||
if lsp_detail: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of if/else
maybe just one or
?
st_details = html.escape(lsp_detail) or self.normalized_documentation(item)
So I'm pretty sure we came to the wrong conclusion in #771. In that comment:
When the user types a In #771:
When the user types an |
plugin/completion.py
Outdated
def normalized_documentation(self, lsp_item: Dict[str, Any]) -> str: | ||
lsp_documentation = lsp_item.get("documentation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function expensive?
I tried the PR locally,
When I trigger the AC in LSP-elm it takes >20s for this line finish. The AC doesn't show up at the end.
items = list(map(self.format_completion, response_items))
maybe the reason it is the combination of normalized_documentation
and transform_region
being applied to all items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transform_region is not that expensive,
but normalized_documentation is. If I comment out the normalized_documentation
calls, the AC show up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are some good points. Waiting potentially 20 seconds before completions show up is of course unacceptable. Performance from mdpopups.md2html is apparently not good enough (perhaps @facelessuser is willing to improve it, if that it even possible). I think the problem is ultimately on our side since we're rendering potentially >200 markdown strings to html.
Ideally, documentation would only be rendered once the user highlights a particular completion item (lazy rendering). But right now we're forced to render all markdown docs to html before presenting completions (cc @jskinner)
That said, from some initial experience with this PR I think putting the documentation into the ST-details is not a good fit. This is because we don't know how many lines/sentences a server will put into the docs. And there is only place for at most one sentence in the ST-details field.
So either we'll have to come up with a way to extract the "most important sentence" from the returned markdown string, or we have to think of something else.
One idea that's been floating in my head is as follows:
Use the new subl://
scheme in the ST-details to make a href to a command (let's call it LspShowDocumentationCommand
). So that href will appear in the ST-details field at the bottom of the completion widget. The user can click it. The LspShowDocumentationCommand
would then show the docs in a popup with mdpopups.show_popup
and with the flag sublime.COOPERATE_WITH_AUTO_COMPLETE
. This would allow us to do the lazy rendering as we can store the LSP-documentations of all items somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we currently don't know the what the highlighted completion item is in the AC,
Just to chain on your idea.
Instead of just calling LspShowDocumentationCommand,
the documentation field may not be there unless that completion item is resolved.
I would just suggest first calling the completionItem/resolve
before showing the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same for Metals, client is expected to call completionItem/resolve
while scrolling through the completion list because the documentation is expensive to compute.
Is it possible to request completionItem/resolve
via the new AC API ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do that, because we don't know which completion item is highlighted in the AC widget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we know up-front whether server can resolve docs through the resolveProvider
server capability. So if that's not present or set to false then we won't show the hyperlink.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if that's a server capability and not per-completion then I suppose some completions might still return nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't know which completion item is highlighted in the AC widget.
I got misled by this
https://discordapp.com/channels/280102180189634562/280102180189634562/704475737088065566
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if that's a server capability and not per-completion then I suppose some completions might still return nothing.
Yes.
@rwols @predragnikolic I tested #771 |
Revisit some tests. I've modified the payloads to be "real" payloads. One test fails now, a pure insertion text edit. This is to be expected and we should be able to handle this in an upcoming ST API.
The LSP-typescript example confuses me a bit, tbh. Should the |
I agree it's kinda unnecessary and busy. I believe that duplication would be gone if the |
It's not guaranteed that if one LSP-label starts with its associated LSP-filterText, then all LSP-labels start with their associated LSP-filterText. For instance look at the metals language server. We have a funky However from some testing I found that most completion items from metals do have the "starts with" property. But I fear that it might be confusing for users. We could definitely give it a try though. Also, carefully look at the behavior of ST's fuzzy string matching and see if it doesn't deteriorate when using the LSP-label for the trigger. |
See also: sublimehq/sublime_text#819 Using filterText is safer to use as it should contain only alphanumeric characters (PowershellEditorServices language server seems to have a different opinion on this). |
Indeed, I was reminded about sublimehq/sublime_text#819 earlier today and this is definitely a show stopper for non-alphanumerics in the trigger. Trying to find a general algorhithm to remove redundant duplication when it makes sense, but leave it when it wouldn't sounds like a doable but tough endeavour. |
The LSP-filterText is truly the suitable thing for the ST-trigger.
If an LSP-filterText is present, we have a bit of a problem on where
to stuff all of the interesting things.
I decided to put the LSP-label into the ST-annotation field.
That leaves us with only the ST-details to fill in. If there's an LSP-detail,
use that. Otherwise, use the LSP-documentation for the ST-details.
In case there's no LSP-filterText, we are supposed to use the LSP-label
for the ST-trigger. In that case there are enough fields: the LSP-detail
can go into the ST-annotation, and the LSP-documentation and go into the
ST-details.