Skip to content

Commit 229eb2a

Browse files
Merge pull request #1204 from Microsoft/taggedSigHelp
Tagged Template Signature Help Support in Language Service
2 parents 99eb271 + ad39bdf commit 229eb2a

File tree

46 files changed

+724
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+724
-115
lines changed

src/compiler/parser.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,15 @@ module ts {
487487
}
488488
}
489489

490+
export function getInvokedExpression(node: CallLikeExpression): Expression {
491+
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
492+
return (<TaggedTemplateExpression>node).tag;
493+
}
494+
495+
// Will either be a CallExpression or NewExpression.
496+
return (<CallExpression>node).func;
497+
}
498+
490499
export function isExpression(node: Node): boolean {
491500
switch (node.kind) {
492501
case SyntaxKind.ThisKeyword:
@@ -801,14 +810,19 @@ module ts {
801810
}
802811

803812
export function isUnterminatedTemplateEnd(node: LiteralExpression) {
804-
Debug.assert(node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail);
813+
Debug.assert(isTemplateLiteralKind(node.kind));
805814
var sourceText = getSourceFileOfNode(node).text;
806815

807816
// If we're not at the EOF, we know we must be terminated.
808817
if (node.end !== sourceText.length) {
809818
return false;
810819
}
811820

821+
// The literal can only be unterminated if it is a template tail or a no-sub template.
822+
if (node.kind !== SyntaxKind.TemplateTail && node.kind !== SyntaxKind.NoSubstitutionTemplateLiteral) {
823+
return false;
824+
}
825+
812826
// If we didn't end in a backtick, we must still be in the middle of a template.
813827
// If we did, make sure that it's not the *initial* backtick.
814828
return sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick || node.text.length === 0;

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ module ts {
760760
getAugmentedPropertiesOfType(type: Type): Symbol[];
761761
getRootSymbols(symbol: Symbol): Symbol[];
762762
getContextualType(node: Node): Type;
763-
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
763+
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature;
764764
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
765765
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
766766
isUndefinedSymbol(symbol: Symbol): boolean;

src/services/signatureHelp.ts

Lines changed: 212 additions & 77 deletions
Large diffs are not rendered by default.

src/services/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,9 @@ module ts {
320320
export function isPunctuation(kind: SyntaxKind): boolean {
321321
return SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation;
322322
}
323+
324+
export function isInsideTemplateLiteral(node: LiteralExpression, position: number) {
325+
return (node.getStart() < position && position < node.getEnd())
326+
|| (isUnterminatedTemplateEnd(node) && position === node.getEnd());
327+
}
323328
}

tests/cases/fourslash/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ module FourSlashInterface {
301301
FourSlash.currentTestState.verifySignatureHelpArgumentCount(expected);
302302
}
303303

304-
public currentSignatureParamterCountIs(expected: number) {
304+
public currentSignatureParameterCountIs(expected: number) {
305305
FourSlash.currentTestState.verifyCurrentSignatureHelpParameterCount(expected);
306306
}
307307

308-
public currentSignatureTypeParamterCountIs(expected: number) {
308+
public currentSignatureTypeParameterCountIs(expected: number) {
309309
FourSlash.currentTestState.verifyCurrentSignatureHelpTypeParameterCount(expected);
310310
}
311311

tests/cases/fourslash/genericParameterHelp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
////testFunction<, ,/*5*/>(null, null, null);
1515

1616
// goTo.marker("1");
17-
// verify.currentSignatureParamterCountIs(3);
17+
// verify.currentSignatureParameterCountIs(3);
1818
// verify.currentSignatureHelpIs("testFunction<T extends IFoo, U, M extends IFoo>(a: T, b: U, c: M): M");
1919

2020
// verify.currentParameterHelpArgumentNameIs("T");

tests/cases/fourslash/signatureHelpAnonymousFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
goTo.marker('anonymousFunction1');
99
verify.signatureHelpCountIs(1);
10-
verify.currentSignatureParamterCountIs(2);
10+
verify.currentSignatureParameterCountIs(2);
1111
verify.currentSignatureHelpIs('(a: number, b: string): string');
1212
verify.currentParameterHelpArgumentNameIs("a");
1313
verify.currentParameterSpanIs("a: number");

tests/cases/fourslash/signatureHelpAtEOF.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ verify.signatureHelpPresent();
1010
verify.signatureHelpCountIs(1);
1111

1212
verify.currentSignatureHelpIs("Foo(arg1: string, arg2: string): void");
13-
verify.currentSignatureParamterCountIs(2);
13+
verify.currentSignatureParameterCountIs(2);
1414
verify.currentParameterHelpArgumentNameIs("arg1");
1515
verify.currentParameterSpanIs("arg1: string");

tests/cases/fourslash/signatureHelpBeforeSemicolon1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ verify.signatureHelpPresent();
1010
verify.signatureHelpCountIs(1);
1111

1212
verify.currentSignatureHelpIs("Foo(arg1: string, arg2: string): void");
13-
verify.currentSignatureParamterCountIs(2);
13+
verify.currentSignatureParameterCountIs(2);
1414
verify.currentParameterHelpArgumentNameIs("arg1");
1515
verify.currentParameterSpanIs("arg1: string");

tests/cases/fourslash/signatureHelpCallExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
goTo.marker('1');
77
verify.signatureHelpCountIs(1);
8-
verify.currentSignatureParamterCountIs(2);
8+
verify.currentSignatureParameterCountIs(2);
99
verify.currentSignatureHelpIs('fnTest(str: string, num: number): void');
1010

1111
verify.currentParameterHelpArgumentNameIs('str');

0 commit comments

Comments
 (0)