mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
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:
parent
f70b068b3c
commit
4ecadc6c03
@ -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 */
|
||||
|
||||
73
tests/cases/fourslash/stringCompletionsUnterminated.ts
Normal file
73
tests/cases/fourslash/stringCompletionsUnterminated.ts
Normal 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],
|
||||
}],
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user