Merge pull request #3347 from Microsoft/irregularExpressionCompletion

Block completion when in the flags of a regular expression
This commit is contained in:
Daniel Rosenwasser 2015-06-02 14:15:47 -07:00
commit 4d8d1cc956
7 changed files with 59 additions and 6 deletions

View File

@ -3130,16 +3130,20 @@ module ts {
if (previousToken.kind === SyntaxKind.StringLiteral
|| previousToken.kind === SyntaxKind.RegularExpressionLiteral
|| isTemplateLiteralKind(previousToken.kind)) {
// The position has to be either: 1. entirely within the token text, or
// 2. at the end position of an unterminated token.
let start = previousToken.getStart();
let end = previousToken.getEnd();
// To be "in" one of these literals, the position has to be:
// 1. entirely within the token text.
// 2. at the end position of an unterminated token.
// 3. at the end of a regular expression (due to trailing flags like '/foo/g').
if (start < position && position < end) {
return true;
}
else if (position === end) {
return !!(<LiteralExpression>previousToken).isUnterminated;
if (position === end) {
return !!(<LiteralExpression>previousToken).isUnterminated ||
previousToken.kind === SyntaxKind.RegularExpressionLiteral;
}
}

View File

@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
////let v = 100;
/////a/./**/
goTo.marker();
verify.not.memberListContains('v');
verify.memberListContains('compile');

View File

@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
////let v = 100;
////let x = /absidey//**/
// Should get nothing at the marker since it's
// going to be considered part of the regex flags.
goTo.marker();
verify.completionListIsEmpty();

View File

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
////let v = 100;
////let x = /absidey/
/////**/
// Should not be blocked since there is a
// newline separating us from the regex flags.
goTo.marker();
verify.completionListContains("v");

View File

@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
////let v = 100;
////let x = /absidey/ /**/
// Should not be blocked since there is a
// space separating us from the regex flags.
goTo.marker();
verify.completionListContains("v");

View File

@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
////let v = 100;
////let x = /absidey/g/**/
// Should get nothing at the marker since it's
// going to be considered part of the regex flags.
goTo.marker();
verify.completionListIsEmpty()

View File

@ -3,5 +3,5 @@
/////a/./**/
goTo.marker();
//verify.not.memberListContains('alert');
//verify.memberListContains('compile');
verify.not.memberListContains('alert');
verify.memberListContains('compile');