diff --git a/src/services/services.ts b/src/services/services.ts index b5871711aa7..980c22f529d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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 !!(previousToken).isUnterminated; + + if (position === end) { + return !!(previousToken).isUnterminated || + previousToken.kind === SyntaxKind.RegularExpressionLiteral; } } diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts new file mode 100644 index 00000000000..ac8568d13f5 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts @@ -0,0 +1,8 @@ +/// + +////let v = 100; +/////a/./**/ + +goTo.marker(); +verify.not.memberListContains('v'); +verify.memberListContains('compile'); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts new file mode 100644 index 00000000000..2719d747d58 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts @@ -0,0 +1,10 @@ +/// + +////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(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts new file mode 100644 index 00000000000..7c0e4d51446 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts @@ -0,0 +1,11 @@ +/// + +////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"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts new file mode 100644 index 00000000000..06f31b8175b --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts @@ -0,0 +1,10 @@ +/// + +////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"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts new file mode 100644 index 00000000000..7ac0d1cd71c --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts @@ -0,0 +1,10 @@ +/// + +////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() \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts index 870e83c5118..558b4d1e791 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts @@ -3,5 +3,5 @@ /////a/./**/ goTo.marker(); -//verify.not.memberListContains('alert'); -//verify.memberListContains('compile'); \ No newline at end of file +verify.not.memberListContains('alert'); +verify.memberListContains('compile'); \ No newline at end of file