Skip to content

Commit 66cb969

Browse files
Daniel RosenwasserDaniel Rosenwasser
Daniel Rosenwasser
authored and
Daniel Rosenwasser
committed
Disabled completion list entries in template literal parts for the LS.
1 parent ddf93d6 commit 66cb969

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/services/services.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -2498,25 +2498,48 @@ module ts {
24982498
}
24992499

25002500
function isInStringOrRegularExpressionLiteral(previousToken: Node): boolean {
2501-
if (previousToken.kind === SyntaxKind.StringLiteral) {
2501+
if (previousToken.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(previousToken.kind)) {
25022502
// The position has to be either: 1. entirely within the token text, or
25032503
// 2. at the end position, and the string literal is not terminated
2504+
25042505
var start = previousToken.getStart();
25052506
var end = previousToken.getEnd();
2507+
25062508
if (start < position && position < end) {
25072509
return true;
25082510
}
25092511
else if (position === end) {
25102512
var width = end - start;
25112513
var text = previousToken.getSourceFile().text;
2512-
return width <= 1 ||
2513-
text.charCodeAt(start) !== text.charCodeAt(end - 1) ||
2514-
text.charCodeAt(end - 2) === CharacterCodes.backslash;
2514+
2515+
// If the token is a single character, or its second-to-last charcter indicates an escape code,
2516+
// then we can immediately say that we are in the middle of an unclosed string.
2517+
if (width <= 1 || text.charCodeAt(end - 2) === CharacterCodes.backslash) {
2518+
return true;
2519+
}
2520+
2521+
// Now check if the last character is a closing character for the token.
2522+
switch (previousToken.kind) {
2523+
case SyntaxKind.StringLiteral:
2524+
case SyntaxKind.NoSubstitutionTemplateLiteral:
2525+
return text.charCodeAt(start) !== text.charCodeAt(end - 1);
2526+
2527+
case SyntaxKind.TemplateHead:
2528+
case SyntaxKind.TemplateMiddle:
2529+
return text.charCodeAt(end - 1) !== CharacterCodes.openBrace
2530+
|| text.charCodeAt(end - 2) !== CharacterCodes.$;
2531+
2532+
case SyntaxKind.TemplateTail:
2533+
return text.charCodeAt(end - 1) !== CharacterCodes.backtick;
2534+
}
2535+
2536+
return false;
25152537
}
25162538
}
25172539
else if (previousToken.kind === SyntaxKind.RegularExpressionLiteral) {
25182540
return previousToken.getStart() < position && position < previousToken.getEnd();
25192541
}
2542+
25202543
return false;
25212544
}
25222545

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
/////*0*/` $ { ${/*1*/ 10/*2*/ + 1.1/*3*/ /*4*/} 12312`/*5*/
4+
////
5+
/////*6*/`asdasd${/*7*/ 2 + 1.1 /*8*/} 12312 {
6+
7+
test.markers().forEach(marker => {
8+
goTo.position(marker.position);
9+
10+
verify.completionListItemsCountIsGreaterThan(0)
11+
}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////`/*0*/ /*1*/$ /*2*/{ /*3*/$/*4*/{ 10 + 1.1 }/*5*/ 12312/*6*/`
4+
////
5+
////`asdasd$/*7*/{ 2 + 1.1 }/*8*/ 12312 /*9*/{/*10*/
6+
7+
test.markers().forEach(marker => {
8+
goTo.position(marker.position);
9+
10+
verify.completionListIsEmpty()
11+
}

0 commit comments

Comments
 (0)