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
Retrigger signatureHelp on new signature selection #608
Comments
Since the LSP client doesn't do any filtering of user input I guess this is already a behavior in VS Code. Looping in @jrieken. Is there a reason why the arrow up / down key doesn't retrigger this. |
@mjbvz made these changes |
Also, the |
Within the same parameter you should end up with the same result. A provider which is changing the list of signatures on retriggers that are pure navigation at the same cursor position would seem like a bad provider more than anything.
This is not entirely the case in Python, where the active parameter's index can be different per signature. You can largely specify parameters in any order you'd like so long as you're naming them, and different overloads can have different signatures with entirely different mappings.
Sure. Take the following Python code, which uses typing annotations to hint the user on valid signatures (and for potential type checking in addition to a better editor experience): from typing import Any, Optional, overload
@overload
def func(a: int) -> int: ...
@overload
def func(a: int, b: int, c: int = 1234, d: Optional[str] = None, **kwargs: Any) -> str: ...
def func(*args, **kwargs):
# Real implementation here.
# This might be in a .py file while the above is in a stub distributed separately. Assume the user is typing out a call, like: func(1234|) Where
There's no problem yet; they all have the same active parameter index, 0. Navigation without retrigger will appear to work; the first parameter is selected in all cases. Now, change the user's code to: func(1234, d=|) The signatures should look like this:
The active parameter indexes are different. Currently, we can only indicate a single active signature (index 1) and its active parameter (index 3). But if the user navigates down to the next signature, there's nothing we can do to change the parameter index and say the UI should be highlighting If the client were to retrigger on this navigation, we'd see that the user is now selecting a different signature and be able to update the parameter index to work within this API's constraints. This is not a problem in a language like TypeScript, where optional parameters are just syntactic sugar and you must provide them in order left to right. In that case, the index always works for every signature; signatures where the index goes out of range simply don't have their parameter highlighted and it all works out implicitly. (Note that this all is working around the problem that we can't just mark for each signature its active parameter; if we could do that then the UI would have all of the information it needs without any queries.) |
Thanks. So if you could set different active parameters for each signature, that would fix the issue? Can you please file an issue against VS Code for that? |
Yes and no; we're in a language server and cannot use things that aren't in the LSP specification. Adding it to VS Code will sort of solve it, but we won't be able to make use of it, hence why I'm asking for the retriggering on navigation where the client resends the same request (the same trigger kind; Also, if a per-parameter active property were added, I think the entire |
VS Code is usually the best place to start since we often test new language API before moving it on the LSP. Either that or file an issue against the LSP: https://github.com/Microsoft/language-server-protocol/issues Again, having VS Code re-trigger sounds like a workaround that will impact all existing providers. We should have proper API to support your use case |
I have opened microsoft/vscode#94637. |
@jakebailey please ping me when this lands in VS Code and I can make a proposed version of it in the LSP which you then can consume. |
I will do that, thanks. Should this issue be retitled to capture the new API, since my original focus was on adding more retriggering (and not a whole new API)? |
I think it is fine until we know what the new API will look like. |
See microsoft/vscode#94637 for the new API. |
Code and spec updated. |
I'm working on better selecting an active parameter in the signature help for Python code. Python differs from many languages in that you can generally specify parameters in any order you'd like by naming them, or to have them be put into
*args
or**kwargs
completely independently of their passed position. Since the LSP specification only lets you specify one active parameter for the entire signature help response (versus one active parameter per signature), this is difficult to model.LSP 3.15 introduced the signature help context, where the active signature (what the user has selected) is passed back on a retrigger. I've used this to some success to update the active parameter to the selected signature in lieu of per-signature active parameters (which is awkward compared to just allowing an active boolean on each parameter, but it's too late).
The specification says:
Which I take to include movement up and down in the signature tooltip, as it's "the user navigating through available signatures". But, I only get sent a request with an updated context when moving left and right (the actual editor cursor) or when editing the file, which prevents me from changing the active parameter index when the user is just browsing the list. I've confirmed this by setting a breakpoint in the
provideSignatureHelp
function in the client and observing it is only called once.I'm unsure if this is intended behavior, or just a bug. If the current behavior is as-designed, can this extra retrigger be done in addition to the current behavior? I would think that navigating the signature menu would be beneficial and be within specification.
I'm uncertain if I should be opening this on VS Code (since this library's just a passthrough to
provideSignatureHelp
and the implementation likely in VS Code proper), but figured I would try asking here first as it's the overlap between the specification and VS Code's behavior.The text was updated successfully, but these errors were encountered: