From 5fd0701ce52cd6ae99d5f48e78762df4cc039710 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 25 Nov 2014 14:37:40 -0800 Subject: [PATCH 1/2] Fixed bug where tagged templates with a literal adjacent to EOF showed sig help. --- src/compiler/emitter.ts | 4 ++-- src/compiler/parser.ts | 7 ++++--- src/services/signatureHelp.ts | 2 +- .../signatureHelpTaggedTemplatesNegatives2.ts | 11 +++++++++++ .../signatureHelpTaggedTemplatesNegatives3.ts | 11 +++++++++++ .../signatureHelpTaggedTemplatesNegatives4.ts | 11 +++++++++++ .../signatureHelpTaggedTemplatesNegatives5.ts | 11 +++++++++++ 7 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives2.ts create mode 100644 tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives3.ts create mode 100644 tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives4.ts create mode 100644 tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5cdf98aa63e..4595c8cb475 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -715,7 +715,7 @@ module ts { }; } } - + function emitEnumDeclaration(node: EnumDeclaration) { if (resolver.isDeclarationVisible(node)) { emitJsDocComments(node); @@ -3558,7 +3558,7 @@ module ts { return leadingComments; } - + function getLeadingCommentsToEmit(node: Node) { // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8d7bf9e4fe7..f60fd051cb1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -823,9 +823,10 @@ module ts { return false; } - // If we didn't end in a backtick, we must still be in the middle of a template. - // If we did, make sure that it's not the *initial* backtick. - return sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick || node.text.length === 0; + // If we didn't end in a backtick, we must still be in the middle of a template literal, + // but if it's the *initial* backtick (whereby the token is 1 char long), then it's unclosed. + var width = node.end - getTokenPosOfNode(node); + return width < 2 || sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick; } export function isModifier(token: SyntaxKind): boolean { diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index e2b65e3c6e1..aa2f5d32c50 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -296,7 +296,7 @@ module ts.SignatureHelp { Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression); // If we're just after a template tail, don't show signature help. - if (node.kind === SyntaxKind.TemplateTail && position >= node.getEnd() && !isUnterminatedTemplateEnd(node)) { + if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(node, position)) { return undefined; } diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives2.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives2.ts new file mode 100644 index 00000000000..e7a5078dcd0 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives2.ts @@ -0,0 +1,11 @@ +/// + +//// function foo(strs, ...rest) { +//// } +//// +//// /*1*/fo/*2*/o /*3*/`abcd${0 + 1}abcd{1 + 1}`/*4*/ /*5*/ + +test.markers().forEach(m => { + goTo.position(m.position); + verify.not.signatureHelpPresent(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives3.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives3.ts new file mode 100644 index 00000000000..c84b92fee4f --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives3.ts @@ -0,0 +1,11 @@ +/// + +//// function foo(strs, ...rest) { +//// } +//// +//// /*1*/fo/*2*/o /*3*/`abcd${0 + 1}abcd{1 + 1}abcd`/*4*/ /*5*/ + +test.markers().forEach(m => { + goTo.position(m.position); + verify.not.signatureHelpPresent(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives4.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives4.ts new file mode 100644 index 00000000000..338a8dc65ca --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives4.ts @@ -0,0 +1,11 @@ +/// + +//// function foo(strs, ...rest) { +//// } +//// +//// /*1*/fo/*2*/o /*3*/``/*4*/ /*5*/ + +test.markers().forEach(m => { + goTo.position(m.position); + verify.not.signatureHelpPresent(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts new file mode 100644 index 00000000000..204a30fa1bd --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts @@ -0,0 +1,11 @@ +/// + +//// function foo(strs, ...rest) { +//// } +//// +//// /*1*/fo/*2*/o /*3*/`abcd`/*4*/ /*5*/ + +test.markers().forEach(m => { + goTo.position(m.position); + verify.not.signatureHelpPresent(); +}); \ No newline at end of file From 46991b79e04deeb3b3e49f7b0063275d271b4077 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 25 Nov 2014 14:42:15 -0800 Subject: [PATCH 2/2] Fixed test. --- tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts index 204a30fa1bd..02383df9267 100644 --- a/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesNegatives5.ts @@ -3,7 +3,7 @@ //// function foo(strs, ...rest) { //// } //// -//// /*1*/fo/*2*/o /*3*/`abcd`/*4*/ /*5*/ +//// /*1*/fo/*2*/o /*3*/`abcd`/*4*/ test.markers().forEach(m => { goTo.position(m.position);