Skip to content

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

Merged
merged 23 commits into from
Nov 25, 2014

Conversation

DanielRosenwasser
Copy link
Member

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.

sighelptemplates2

verify.signatureHelpCountIs(1);
verify.signatureHelpArgumentCountIs(4);

verify.currentSignatureParamterCountIs(4);
Copy link
Member Author

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) {
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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

Copy link
Contributor

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just ===

@JsonFreeman
Copy link
Contributor

👍

@yuit
Copy link
Contributor

yuit commented Nov 25, 2014

LGTM

DanielRosenwasser added a commit that referenced this pull request Nov 25, 2014
Tagged Template Signature Help Support in Language Service
@DanielRosenwasser DanielRosenwasser merged commit 229eb2a into master Nov 25, 2014
@DanielRosenwasser DanielRosenwasser deleted the taggedSigHelp branch November 25, 2014 01:48
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants