Skip to content

Commit

Permalink
Disabled completion list entries in template literal parts for the LS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rosenwasser authored and Daniel Rosenwasser committed Oct 28, 2014
1 parent ddf93d6 commit 66cb969
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2498,25 +2498,48 @@ module ts {
}

function isInStringOrRegularExpressionLiteral(previousToken: Node): boolean {
if (previousToken.kind === SyntaxKind.StringLiteral) {
if (previousToken.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(previousToken.kind)) {
// The position has to be either: 1. entirely within the token text, or
// 2. at the end position, and the string literal is not terminated

var start = previousToken.getStart();
var end = previousToken.getEnd();

if (start < position && position < end) {
return true;
}
else if (position === end) {
var width = end - start;
var text = previousToken.getSourceFile().text;
return width <= 1 ||
text.charCodeAt(start) !== text.charCodeAt(end - 1) ||
text.charCodeAt(end - 2) === CharacterCodes.backslash;

// If the token is a single character, or its second-to-last charcter indicates an escape code,
// then we can immediately say that we are in the middle of an unclosed string.
if (width <= 1 || text.charCodeAt(end - 2) === CharacterCodes.backslash) {
return true;
}

// Now check if the last character is a closing character for the token.
switch (previousToken.kind) {
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
return text.charCodeAt(start) !== text.charCodeAt(end - 1);

case SyntaxKind.TemplateHead:
case SyntaxKind.TemplateMiddle:
return text.charCodeAt(end - 1) !== CharacterCodes.openBrace
|| text.charCodeAt(end - 2) !== CharacterCodes.$;

case SyntaxKind.TemplateTail:
return text.charCodeAt(end - 1) !== CharacterCodes.backtick;
}

return false;
}
}
else if (previousToken.kind === SyntaxKind.RegularExpressionLiteral) {
return previousToken.getStart() < position && position < previousToken.getEnd();
}

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/cases/fourslash/completionListInTemplateLiteralParts1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

/////*0*/` $ { ${/*1*/ 10/*2*/ + 1.1/*3*/ /*4*/} 12312`/*5*/
////
/////*6*/`asdasd${/*7*/ 2 + 1.1 /*8*/} 12312 {

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListItemsCountIsGreaterThan(0)
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

////`/*0*/ /*1*/$ /*2*/{ /*3*/$/*4*/{ 10 + 1.1 }/*5*/ 12312/*6*/`
////
////`asdasd$/*7*/{ 2 + 1.1 }/*8*/ 12312 /*9*/{/*10*/

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListIsEmpty()
}

0 comments on commit 66cb969

Please sign in to comment.