From 039487c84e518cb6de798d1011dca7e9db624315 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 11 Apr 2019 12:47:10 -0700 Subject: [PATCH] Also skip TemplateHeads --- src/server/session.ts | 2 +- .../unittests/tsserver/selectionRange.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 90a8aa2f00f..f64674b129a 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -2136,7 +2136,7 @@ namespace ts.server { // TemplateSpans, along with the SyntaxLists containing them, // are a somewhat unintuitive grouping of things that should be // considered independently. Dive in without pushing a selection range. - if (isBlock(node) || isTemplateSpan(node) || prevNode && isTemplateHead(prevNode)) { + if (isBlock(node) || isTemplateSpan(node) || isTemplateHead(node) || prevNode && isTemplateHead(prevNode)) { parentNode = node; break; } diff --git a/src/testRunner/unittests/tsserver/selectionRange.ts b/src/testRunner/unittests/tsserver/selectionRange.ts index 4b95f929bf9..ce88b4072cc 100644 --- a/src/testRunner/unittests/tsserver/selectionRange.ts +++ b/src/testRunner/unittests/tsserver/selectionRange.ts @@ -273,7 +273,10 @@ type X = { it("works for string literals and template strings", () => { // tslint:disable-next-line:no-invalid-template-strings const getSelectionRange = setup("/file.ts", "`a b ${\n 'c'\n} d`"); - const locations = getSelectionRange([{ line: 2, offset: 4 }]); + const locations = getSelectionRange([ + { line: 2, offset: 4 }, + { line: 1, offset: 4 }, + ]); assert.deepEqual(locations, [ { textSpan: { // c @@ -298,7 +301,15 @@ type X = { parent: { textSpan: { // whole template string start: { line: 1, offset: 1 }, - end: { line: 3, offset: 5 } } } } } } } + end: { line: 3, offset: 5 } } } } } } }, + { + textSpan: { // whole template string without backticks + start: { line: 1, offset: 2 }, + end: { line: 3, offset: 4 } }, + parent: { + textSpan: { // whole template string + start: { line: 1, offset: 1 }, + end: { line: 3, offset: 5 } } } }, ]); });