Disabled completion list entries in template literal parts for the LS.

This commit is contained in:
Daniel Rosenwasser 2014-10-28 13:55:56 -07:00
parent d522c88295
commit ead3c1bde8
3 changed files with 49 additions and 4 deletions

View File

@ -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;
}

View File

@ -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)
}}

View File

@ -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()
}