Skip to content

Commit 4d8d1cc

Browse files
Merge pull request #3347 from Microsoft/irregularExpressionCompletion
Block completion when in the flags of a regular expression
2 parents 80e0557 + 8b63795 commit 4d8d1cc

7 files changed

+59
-6
lines changed

src/services/services.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -3130,16 +3130,20 @@ module ts {
31303130
if (previousToken.kind === SyntaxKind.StringLiteral
31313131
|| previousToken.kind === SyntaxKind.RegularExpressionLiteral
31323132
|| isTemplateLiteralKind(previousToken.kind)) {
3133-
// The position has to be either: 1. entirely within the token text, or
3134-
// 2. at the end position of an unterminated token.
31353133
let start = previousToken.getStart();
31363134
let end = previousToken.getEnd();
31373135

3136+
// To be "in" one of these literals, the position has to be:
3137+
// 1. entirely within the token text.
3138+
// 2. at the end position of an unterminated token.
3139+
// 3. at the end of a regular expression (due to trailing flags like '/foo/g').
31383140
if (start < position && position < end) {
31393141
return true;
31403142
}
3141-
else if (position === end) {
3142-
return !!(<LiteralExpression>previousToken).isUnterminated;
3143+
3144+
if (position === end) {
3145+
return !!(<LiteralExpression>previousToken).isUnterminated ||
3146+
previousToken.kind === SyntaxKind.RegularExpressionLiteral;
31433147
}
31443148
}
31453149

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let v = 100;
4+
/////a/./**/
5+
6+
goTo.marker();
7+
verify.not.memberListContains('v');
8+
verify.memberListContains('compile');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let v = 100;
4+
////let x = /absidey//**/
5+
6+
// Should get nothing at the marker since it's
7+
// going to be considered part of the regex flags.
8+
9+
goTo.marker();
10+
verify.completionListIsEmpty();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let v = 100;
4+
////let x = /absidey/
5+
/////**/
6+
7+
// Should not be blocked since there is a
8+
// newline separating us from the regex flags.
9+
10+
goTo.marker();
11+
verify.completionListContains("v");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let v = 100;
4+
////let x = /absidey/ /**/
5+
6+
// Should not be blocked since there is a
7+
// space separating us from the regex flags.
8+
9+
goTo.marker();
10+
verify.completionListContains("v");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////let v = 100;
4+
////let x = /absidey/g/**/
5+
6+
// Should get nothing at the marker since it's
7+
// going to be considered part of the regex flags.
8+
9+
goTo.marker();
10+
verify.completionListIsEmpty()

tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/////a/./**/
44

55
goTo.marker();
6-
//verify.not.memberListContains('alert');
7-
//verify.memberListContains('compile');
6+
verify.not.memberListContains('alert');
7+
verify.memberListContains('compile');

0 commit comments

Comments
 (0)