Merge pull request #208291 from microsoft/aiday/addingIndentationForIfForWhile

Indent next line for if/for/while statement followed by whitespace
This commit is contained in:
Aiday Marlen Kyzy 2024-03-22 11:07:52 +01:00 committed by GitHub
commit a00f2e64f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 10 deletions

View file

@ -139,7 +139,7 @@
"pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$"
},
"indentNextLinePattern": {
"pattern": "^.*=>\\s*$"
"pattern": "^((.*=>\\s*)|((.*[^\\w]+|\\s*)(if|while|for)\\s*\\(.*\\)\\s*))$"
}
},
"onEnterRules": [

View file

@ -663,15 +663,13 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
});
});
test.skip('issue #43244: incorrect indentation', () => {
test('issue #43244: incorrect indentation after if/for/while without braces', () => {
// https://github.com/microsoft/vscode/issues/43244
// potential regex to fix: "^.*[if|while|for]\s*\(.*\)\s*",
const model = createTextModel([
'function f() {',
' if (condition)',
' return;',
'}'
].join('\n'), languageId, {});
disposables.add(model);
@ -679,23 +677,22 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
editor.setSelection(new Selection(3, 16, 3, 16));
editor.setSelection(new Selection(2, 19, 2, 19));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
'function f() {',
' if (condition)',
' return;',
'',
' ',
'}',
].join('\n'));
viewModel.type("return;");
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
'function f() {',
' if (condition)',
' return;',
'',
'',
' ',
'}',
].join('\n'));
});

View file

@ -8,5 +8,5 @@ export const javascriptIndentationRules = {
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/,
// e.g. * ...| or */| or *-----*/|
unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
indentNextLinePattern: /^.*=>\s*$/,
indentNextLinePattern: /^((.*=>\s*)|((.*[^\w]+|\s*)(if|while|for)\s*\(.*\)\s*))$/,
};