From 465ab147aff671d526ec5f5daef61fb0aa6fccb5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 12:36:04 -0700 Subject: [PATCH 1/6] Fixed test that disturbingly wasn't doing anything. --- .../fourslash/completionListAfterRegularExpressionLiteral1.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From dcfe9200641d7f6e0edf84705431cf8f8ea4c62e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 12:36:42 -0700 Subject: [PATCH 2/6] Added leading digit. --- .../completionListAfterRegularExpressionLiteral01.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts new file mode 100644 index 00000000000..558b4d1e791 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts @@ -0,0 +1,7 @@ +/// + +/////a/./**/ + +goTo.marker(); +verify.not.memberListContains('alert'); +verify.memberListContains('compile'); \ No newline at end of file From 0a3cbe083b7e63518407bf593efcf413dfca5f4a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 12:58:49 -0700 Subject: [PATCH 3/6] Added tests. --- .../completionListAfterRegularExpressionLiteral02.ts | 9 +++++++++ .../completionListAfterRegularExpressionLiteral03.ts | 10 ++++++++++ .../completionListAfterRegularExpressionLiteral04.ts | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts create mode 100644 tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts create mode 100644 tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts new file mode 100644 index 00000000000..677aae80513 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts @@ -0,0 +1,9 @@ +/// + +////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..7b767d5e008 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts @@ -0,0 +1,10 @@ +/// + +////let x = /absidey/ +/////**/ + +// Should not be blocked since there is a +// newline separating us from the regex flags. + +goTo.marker(); +verify.not.completionListIsEmpty(); \ 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..17a714c6f9d --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts @@ -0,0 +1,9 @@ +/// + +////let x = /absidey/ /**/ + +// Should not be blocked since there is a +// space separating us from the regex flags. + +goTo.marker(); +verify.not.completionListIsEmpty(); \ No newline at end of file From 589a01c51f704dc35791f9a3cdb8e25a0f640190 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 13:01:44 -0700 Subject: [PATCH 4/6] Block completion when in trailing flags of a regex. --- src/services/services.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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; } } From a71a826b5b2585b8eb2a9c4aeda2e806acca6c86 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 13:40:38 -0700 Subject: [PATCH 5/6] Use declared variables to confirm completion. --- .../fourslash/completionListAfterRegularExpressionLiteral01.ts | 3 ++- .../fourslash/completionListAfterRegularExpressionLiteral02.ts | 1 + .../fourslash/completionListAfterRegularExpressionLiteral03.ts | 3 ++- .../fourslash/completionListAfterRegularExpressionLiteral04.ts | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts index 558b4d1e791..ac8568d13f5 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts @@ -1,7 +1,8 @@ /// +////let v = 100; /////a/./**/ goTo.marker(); -verify.not.memberListContains('alert'); +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 index 677aae80513..2719d747d58 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts @@ -1,5 +1,6 @@ /// +////let v = 100; ////let x = /absidey//**/ // Should get nothing at the marker since it's diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts index 7b767d5e008..7c0e4d51446 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts @@ -1,5 +1,6 @@ /// +////let v = 100; ////let x = /absidey/ /////**/ @@ -7,4 +8,4 @@ // newline separating us from the regex flags. goTo.marker(); -verify.not.completionListIsEmpty(); \ No newline at end of file +verify.completionListContains("v"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts index 17a714c6f9d..06f31b8175b 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts @@ -1,9 +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.not.completionListIsEmpty(); \ No newline at end of file +verify.completionListContains("v"); \ No newline at end of file From 8b63795a55ab94e0509f96ea5436515f9cd5401a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 13:41:45 -0700 Subject: [PATCH 6/6] Added test where one trailing flag exists. --- .../completionListAfterRegularExpressionLiteral05.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts 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