-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Add context information to SignatureHelpProvider #54972
Comments
Same as #34737 / maybe one should be closed? |
Fixes #54972 Adds `SignatureHelpContext`. This tells providers why signature help was requested TODO: - [ ] Better understand semantics of retrigger. Should `retrigger` be an flag instead of a `triggerReason`? - [ ] Fix skipped test - [ ] Add more tests for trigger reasons / trigger characters
Prototype PR up at #58135 I'd like feedback on the proposed api from a few other language authors to make sure we design an api that will work well for a variety of languages. /cc @DonJayamanne @DustinCampbell @DanTup @ramya-rao-a @aeschli @fbricon @DanielRosenwasser Some starting questions:
Also @dbaeumer heads-up for language server protocol |
Whoops - I hadn't noticed this was missing (and require it to implement automatic triggering in a way that doesn't annoy users). The proposal looks good for me, though we'd planned on not requiring the specific character in the API to the server but rather just whether it was automatically triggered (and if not, only return data of the offset is in a position that is the start of an argument). |
Fixes #54972 Adds `SignatureHelpContext`. This tells providers why signature help was requested TODO: - [ ] Better understand semantics of retrigger. Should `retrigger` be an flag instead of a `triggerReason`? - [ ] Fix skipped test - [ ] Add more tests for trigger reasons / trigger characters
Reopening :) API is still in-design but I've merged in the current proposal so that we can get some real world testing of how the current design works for javascript and typescript. Please continue to share feedback here |
Yes, the client value of |
Introduces the concept of a re-trigger character to the signature help provider. This is a seperate set of characters that are registered with the provider. Typing a retrigger character fires a new signature help request if signature help is already showing. #54972
#54972 Instead of having a generic `Retrigger` reason, add a new field on the `SignatureHelpContext` that tracks if this was a retrigger or not. This allows retrigger for all the different trigger reasons, including invoke. Replace the old `Retriggger` trigger reason with `ContentChange` which tracks cursor movement and text updates.
#33413 will likely not be in first edition of this api but we've designed the api so that this data could be introduced easily in the future. Current proposal is: /**
* How a [Signature provider](#SignatureHelpProvider) was triggered
*/
export enum SignatureHelpTriggerReason {
/**
* Signature help was invoked manually by the user or by a command.
*/
Invoke = 1,
/**
* Signature help was triggered by a trigger character.
*/
TriggerCharacter = 2,
/**
* Signature help was triggered by the cursor moving or by the document content changing.
*/
ContentChange = 3,
}
/**
* Contains additional information about the context in which a
* [signature help provider](#SignatureHelpProvider.provideSignatureHelp) is triggered.
*/
export interface SignatureHelpContext {
/**
* Action that caused signature help to be requested.
*/
readonly triggerReason: SignatureHelpTriggerReason;
/**
* Character that caused signature help to be requested.
*
* This is `undefined` when signature help is not triggered by typing, such as when invoking signature help
* or when moving the cursor.
*/
readonly triggerCharacter?: string;
/**
* Whether or not signature help was previously showing when triggered.
*
* Retriggers occur when the signature help is already active and can be caused by typing a trigger character
* or by a cursor move.
*/
readonly isRetrigger: boolean;
}
export interface SignatureHelpProvider {
provideSignatureHelp(document: TextDocument, position: Position, token: CancellationToken, context: SignatureHelpContext): ProviderResult<SignatureHelp>;
}
export interface SignatureHelpProviderMetadata {
readonly triggerCharacters: ReadonlyArray<string>;
readonly retriggerCharacters: ReadonlyArray<string>;
}
namespace languages {
export function registerSignatureHelpProvider(
selector: DocumentSelector,
provider: SignatureHelpProvider,
metadata: SignatureHelpProviderMetadata
): Disposable;
} Will try finalizing next iteration. Possible changes at the moment:
|
Is this being considered for LSP too? It's likely I'll get around to implementing it in an LSP server before the extension directly (since our existing server protocol doesn't support it, but for LSP I'm implementing it server-side). |
Yes, this will very likely make its way into LSP as well. |
Problem
Signature help providers sometimes need more information to determine which signature to return. microsoft/TypeScript#1150 for example discusses how typing a comma inside of a string could mistakenly triggering TypeScript signature help. Using the current VS Code api, a signature help provider cannot easily distinguish the cases:
Proposal
Add a
context
when requesting signature help. This context should supply at least the following:This proposal is based on what typescript has implemented which in turn is based on rosyln
retriggger
presents one additional complication. This is needed for nested function calls and would be invoked when you type a closing brace with signature help already showing, such as:when the user has just typed
)
. See Daniel's comment for more context: microsoft/TypeScript#1150 (comment)The text was updated successfully, but these errors were encountered: