fix indentation (#141997)

* fix indentation

* add tests

* make regex valid
This commit is contained in:
Andrew Jones
2022-02-03 13:51:57 +10:00
committed by GitHub
parent cdd2af7919
commit 9dc211a499
2 changed files with 19 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ import * as languageModeIds from '../utils/languageIds';
const jsTsLanguageConfiguration: vscode.LanguageConfiguration = {
indentationRules: {
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/,
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/,
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`/]*|(\t|[ ])*\/\/.*)|\([^)"'`/]*|\[[^\]"'`/]*)$/,
// e.g. * ...| or */| or *-----*/|
unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/
},

View File

@@ -168,4 +168,22 @@ suite('OnEnter', () => {
testIndentAction('', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction(' ', ' * test() {', '', IndentAction.Indent, null, 0);
});
test('issue #141816', () => {
let support = new OnEnterSupport({
onEnterRules: javascriptOnEnterRules
});
let testIndentAction = (beforeText: string, afterText: string, expected: IndentAction) => {
let actual = support.onEnter(EditorAutoIndentStrategy.Advanced, '', beforeText, afterText);
if (expected === IndentAction.None) {
assert.strictEqual(actual, null);
} else {
assert.strictEqual(actual!.indentAction, expected);
}
};
testIndentAction('const r = /{/;', '', IndentAction.None);
testIndentAction('const r = /{[0-9]/;', '', IndentAction.None);
testIndentAction('const r = /[a-zA-Z]{/;', '', IndentAction.None);
});
});