From 76524ef5891f72a56be469fa8cb8744f8611b8db Mon Sep 17 00:00:00 2001 From: Shunsuke Iwamoto Date: Wed, 10 Feb 2021 10:05:21 +0900 Subject: [PATCH] Fixes 114236: Add a multi-line comment regex to unIndentedLinePattern (#114478) * Add a multi-line comment regex to unIndentedLinePattern * Add multi-line comment block indentation tests * Fix a multi-line comment block indentation test --- .../languageFeatures/languageConfiguration.ts | 4 +- .../src/test/unit/onEnter.test.ts | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/extensions/typescript-language-features/src/languageFeatures/languageConfiguration.ts b/extensions/typescript-language-features/src/languageFeatures/languageConfiguration.ts index ccd59d51773..75d32770a68 100644 --- a/extensions/typescript-language-features/src/languageFeatures/languageConfiguration.ts +++ b/extensions/typescript-language-features/src/languageFeatures/languageConfiguration.ts @@ -15,7 +15,9 @@ import * as languageModeIds from '../utils/languageModeIds'; const jsTsLanguageConfiguration: vscode.LanguageConfiguration = { indentationRules: { decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/, - increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/ + increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/, + // e.g. * ...| or */| or *-----*/| + unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/ }, wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, onEnterRules: [ diff --git a/extensions/typescript-language-features/src/test/unit/onEnter.test.ts b/extensions/typescript-language-features/src/test/unit/onEnter.test.ts index 0aeb8425b0a..cd0d99c0e41 100644 --- a/extensions/typescript-language-features/src/test/unit/onEnter.test.ts +++ b/extensions/typescript-language-features/src/test/unit/onEnter.test.ts @@ -67,4 +67,47 @@ suite.skip('OnEnter', () => { ` x`)); }); }); + + test('should not indent after a multi-line comment block 1', () => { + return withRandomFileEditor(`/*-----\n * line 1\n * line 2\n *-----*/\n${CURSOR}`, 'js', async (_editor, document) => { + await type(document, '\nx'); + assert.strictEqual( + document.getText(), + joinLines( + `/*-----`, + ` * line 1`, + ` * line 2`, + ` *-----*/`, + ``, + `x`)); + }); + }); + + test('should not indent after a multi-line comment block 2', () => { + return withRandomFileEditor(`/*-----\n * line 1\n * line 2\n */\n${CURSOR}`, 'js', async (_editor, document) => { + await type(document, '\nx'); + assert.strictEqual( + document.getText(), + joinLines( + `/*-----`, + ` * line 1`, + ` * line 2`, + ` */`, + ``, + `x`)); + }); + }); + + test('should indent within a multi-line comment block', () => { + return withRandomFileEditor(`/*-----\n * line 1\n * line 2${CURSOR}`, 'js', async (_editor, document) => { + await type(document, '\nx'); + assert.strictEqual( + document.getText(), + joinLines( + `/*-----`, + ` * line 1`, + ` * line 2`, + ` * x`)); + }); + }); });