-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Tagged Template Signature Help Support in Language Service #1204
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
Conversation
Conflicts: src/services/signatureHelp.ts
verify.signatureHelpCountIs(1); | ||
verify.signatureHelpArgumentCountIs(4); | ||
|
||
verify.currentSignatureParamterCountIs(4); |
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.
"Paramter"
@@ -813,6 +822,11 @@ module ts { | |||
return false; | |||
} | |||
|
|||
// We can only be unclosed if we have a tail or a no-sub template. | |||
if (node.kind !== SyntaxKind.TemplateTail && node.kind !== SyntaxKind.NoSubstitutionTemplateLiteral) { |
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.
What you mean unclosed in this context?
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.
I should probably be more explicit - it kind of sounds like I'm referring to a template expression without a template tail. I really mean unterminated, in the sense that your literal isn't explicitly sealed off with a backtick. I'll clarify it. Thanks!
if (node.kind === SyntaxKind.TaggedTemplateExpression) { | ||
return (<TaggedTemplateExpression>node).tag; | ||
} | ||
else { |
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.
Say that this can be call or new
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.
Also remove else
|
||
export function isInsideTemplateLiteral(node: LiteralExpression, position: number) { | ||
return (node.getStart() < position && position < node.getEnd()) | ||
|| (isUnterminatedTemplateEnd(node) && position >= node.getEnd()); |
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.
Maybe just ===
👍 |
Conflicts: src/services/signatureHelp.ts
LGTM |
Tagged Template Signature Help Support in Language Service
Signature Help for Tagged Templates
This PR enables signature help support in the language service for tagged template strings.
The idea is that a tagged template is a bit of an implicit function invocation. Whenever a user requests signature help (or it is triggered by the consuming environment), we should figure out what function a tag refers to, which overload should be chosen, and which parameter is currently being fed.
Substitution-Argument Correspondence
When a template expression is tagged, each substitution expression corresponds to an argument in invoking that tag. Specifically, the Nth substitution expression in a tagged template expression is the (N+1)th argument in an invocation.
TemplateStringsArray Argument
Whenever the cursor lies within a template literal (whether a no-substitution literal, or a fragment of a template expression), the parameter in question is the first parameter of the tag in question. This is because each template literal in a tagged template corresponds to an array element in the cooked/raw array object specified in ES6. This means that as the cursor moves through a template expression, parameters will not be highlighted from left-to-right consistently.