From ede654c2afb19b7523b41ab6d3e54ee6d08ad198 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Mon, 18 Mar 2024 17:11:47 -0700 Subject: [PATCH 1/5] replace unterminated strings (unless empty strings) --- src/services/utilities.ts | 9 +++++++-- .../stringCompletionsUnterminated.ts | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/stringCompletionsUnterminated.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 62443ac2049b6..cfc9c629837d4 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2322,8 +2322,13 @@ export function createTextSpanFromNode(node: Node, sourceFile?: SourceFile, endN /** @internal */ export function createTextSpanFromStringLiteralLikeContent(node: StringLiteralLike) { - if (node.isUnterminated) return undefined; - return createTextSpanFromBounds(node.getStart() + 1, node.getEnd() - 1); + let replacementEnd = node.getEnd() - 1; + if (node.isUnterminated) { + // we return no replacement range only if unterminated string is empty + if (node.getStart() === replacementEnd) return undefined; + replacementEnd = node.getEnd(); + } + return createTextSpanFromBounds(node.getStart() + 1, replacementEnd); } /** @internal */ diff --git a/tests/cases/fourslash/stringCompletionsUnterminated.ts b/tests/cases/fourslash/stringCompletionsUnterminated.ts new file mode 100644 index 0000000000000..80e7519bbf081 --- /dev/null +++ b/tests/cases/fourslash/stringCompletionsUnterminated.ts @@ -0,0 +1,20 @@ +/// + +//// const a = { "foo.bar": 1} +//// a["[|foo.b/*0*/|] +//// a["[|foo.b /*1*/|] +//// a[ "[|foo.b/*2*/|] +//// a["[|foo.b/*3*/|]" +//// a["[|foo./*4*/b|] + +for (let i = 0; i < test.markers().length; i++) { + verify.completions({ + marker: test.markers()[i], + includes: [{ + "name": "foo.bar", + "kind": "property", + "kindModifiers": "", + "replacementSpan": test.ranges()[i], + }], + }); +} From 147d14424f407fd893e55c18b218ea2282d083a8 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Mon, 18 Mar 2024 17:20:36 -0700 Subject: [PATCH 2/5] more tests --- .../fourslash/stringCompletionsUnterminated.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/cases/fourslash/stringCompletionsUnterminated.ts b/tests/cases/fourslash/stringCompletionsUnterminated.ts index 80e7519bbf081..389259e9bc88c 100644 --- a/tests/cases/fourslash/stringCompletionsUnterminated.ts +++ b/tests/cases/fourslash/stringCompletionsUnterminated.ts @@ -1,12 +1,28 @@ /// -//// const a = { "foo.bar": 1} +// @Filename: file1.ts +//// const a = { "foo.bar": 1 } //// a["[|foo.b/*0*/|] //// a["[|foo.b /*1*/|] //// a[ "[|foo.b/*2*/|] //// a["[|foo.b/*3*/|]" //// a["[|foo./*4*/b|] +//// a['[|foo./*5*/b|] +//// a[`[|foo./*6*/b|] +// @Filename: file2.ts +//// const a = { "foo.bar": 1 } +//// a[`/*7*/ + +// @Filename: file3.ts +//// const a = { "foo.bar": 1 } +//// a["/*8*/ + +// @Filename: file4.ts +//// const a = { "foo.bar": 1 } +//// a['/*9*/ + +// tests 7-9 should return no replacementSpan for (let i = 0; i < test.markers().length; i++) { verify.completions({ marker: test.markers()[i], From 4ebd8174621b3b586799c7f23cf24910c2979d5f Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 19 Mar 2024 11:04:14 -0700 Subject: [PATCH 3/5] Update tests/cases/fourslash/stringCompletionsUnterminated.ts Co-authored-by: Daniel Rosenwasser --- tests/cases/fourslash/stringCompletionsUnterminated.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/cases/fourslash/stringCompletionsUnterminated.ts b/tests/cases/fourslash/stringCompletionsUnterminated.ts index 389259e9bc88c..d06a87a1acbaa 100644 --- a/tests/cases/fourslash/stringCompletionsUnterminated.ts +++ b/tests/cases/fourslash/stringCompletionsUnterminated.ts @@ -23,14 +23,17 @@ //// a['/*9*/ // tests 7-9 should return no replacementSpan -for (let i = 0; i < test.markers().length; i++) { +const markers = test.markers(); +const ranges = test.ranges(); + +for (let i = 0; i < markers.length; i++) { verify.completions({ - marker: test.markers()[i], + marker: markers[i], includes: [{ "name": "foo.bar", "kind": "property", "kindModifiers": "", - "replacementSpan": test.ranges()[i], + "replacementSpan": ranges[i], }], }); } From f37e694871a6ecad29f76b9017a6a79d6b82927e Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 19 Mar 2024 11:39:08 -0700 Subject: [PATCH 4/5] add tests --- .../stringCompletionsUnterminated.ts | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/tests/cases/fourslash/stringCompletionsUnterminated.ts b/tests/cases/fourslash/stringCompletionsUnterminated.ts index d06a87a1acbaa..6a7a9dfd9cec2 100644 --- a/tests/cases/fourslash/stringCompletionsUnterminated.ts +++ b/tests/cases/fourslash/stringCompletionsUnterminated.ts @@ -1,26 +1,60 @@ /// -// @Filename: file1.ts +// @Filename: file0.ts //// const a = { "foo.bar": 1 } //// a["[|foo.b/*0*/|] + +// @Filename: file1.ts +//// const a = { "foo.bar": 1 } //// a["[|foo.b /*1*/|] + +// @Filename: file2.ts +//// const a = { "foo.bar": 1 } //// a[ "[|foo.b/*2*/|] + +// @Filename: file3.ts +//// const a = { "foo.bar": 1 } //// a["[|foo.b/*3*/|]" + +// @Filename: file4.ts +//// const a = { "foo.bar": 1 } //// a["[|foo./*4*/b|] + +// @Filename: file5.ts +//// const a = { "foo.bar": 1 } //// a['[|foo./*5*/b|] + +// @Filename: file6.ts +//// const a = { "foo.bar": 1 } //// a[`[|foo./*6*/b|] -// @Filename: file2.ts +// @Filename: file7.ts //// const a = { "foo.bar": 1 } -//// a[`/*7*/ +//// a["[|foo./*7*/|] -// @Filename: file3.ts +// @Filename: file8.ts //// const a = { "foo.bar": 1 } -//// a["/*8*/ +//// a["[|foo/*8*/|] -// @Filename: file4.ts +// @Filename: file9.ts +//// const a = { "foo.bar": 1 } +//// a["[|foo./*9*/|]" + +// @Filename: file10.ts +//// const a = { "foo.bar": 1 } +//// a["[|foo/*10*/|]" + +// @Filename: empty1.ts +//// const a = { "foo.bar": 1 } +//// a[`/*11*/ + +// @Filename: empty2.ts +//// const a = { "foo.bar": 1 } +//// a["/*12*/ + +// @Filename: empty3.ts //// const a = { "foo.bar": 1 } -//// a['/*9*/ +//// a['/*13*/ // tests 7-9 should return no replacementSpan const markers = test.markers(); From 1b6db01ac14b7ba2ed4dd8ea5cc172bfc629ac00 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 19 Mar 2024 14:56:53 -0700 Subject: [PATCH 5/5] update test typo --- tests/cases/fourslash/stringCompletionsUnterminated.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/stringCompletionsUnterminated.ts b/tests/cases/fourslash/stringCompletionsUnterminated.ts index 6a7a9dfd9cec2..4d5736d4795a1 100644 --- a/tests/cases/fourslash/stringCompletionsUnterminated.ts +++ b/tests/cases/fourslash/stringCompletionsUnterminated.ts @@ -56,7 +56,7 @@ //// const a = { "foo.bar": 1 } //// a['/*13*/ -// tests 7-9 should return no replacementSpan +// tests 11-13 should return no replacementSpan const markers = test.markers(); const ranges = test.ranges();