fix54092: return replacement ranges for completions on unclosed strings (#57839)

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
Isabel Duan 2024-03-20 13:41:48 -07:00 committed by GitHub
parent f70b068b3c
commit 4ecadc6c03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 2 deletions

View File

@ -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 */

View File

@ -0,0 +1,73 @@
///<reference path="fourslash.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: file7.ts
//// const a = { "foo.bar": 1 }
//// a["[|foo./*7*/|]
// @Filename: file8.ts
//// const a = { "foo.bar": 1 }
//// a["[|foo/*8*/|]
// @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['/*13*/
// tests 11-13 should return no replacementSpan
const markers = test.markers();
const ranges = test.ranges();
for (let i = 0; i < markers.length; i++) {
verify.completions({
marker: markers[i],
includes: [{
"name": "foo.bar",
"kind": "property",
"kindModifiers": "",
"replacementSpan": ranges[i],
}],
});
}