From 5cc65d29ab3d77f6fedf322623ecdb9eb390bcad Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Wed, 20 Mar 2024 17:41:07 +0100 Subject: [PATCH] arrow function --- .../language-configuration.json | 8 +++++- .../test/browser/indentation.test.ts | 25 ++++++++++++++++--- .../modes/supports/javascriptOnEnterRules.ts | 4 +++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 2d14b1cab19..d2652244965 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -215,6 +215,12 @@ "action": { "indent": "outdent" } - } + }, + { + "beforeText": "^\\s*(var|const|let)\\s+\\w+\\s*=\\s*\\(.*\\)\\s*=>\\s*$", + "action": { + "indent": "indent" + } + }, ] } diff --git a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts index 6b78736694f..83ea2a23d0f 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -545,9 +545,9 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { // Failing tests from issues... - test.skip('issue #116843: indent after arrow function', () => { + test('issue #208215: indent after arrow function', () => { - // https://github.com/microsoft/vscode/issues/116843 + // https://github.com/microsoft/vscode/issues/208215 const model = createTextModel("", languageId, {}); disposables.add(model); @@ -562,11 +562,28 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { 'const add1 = (n) =>', ' ', ].join('\n')); - viewModel.type('n + 1;'); + }); + }); + + test.skip('issue #116843: indent after arrow function', () => { + + // https://github.com/microsoft/vscode/issues/116843 + + const model = createTextModel("", languageId, {}); + disposables.add(model); + + withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => { + + registerLanguage(instantiationService, languageId, Language.TypeScript, disposables); + + viewModel.type([ + 'const add1 = (n) =>', + ' n + 1;', + ].join('\n')); viewModel.type("\n", 'keyboard'); assert.strictEqual(model.getValue(), [ 'const add1 = (n) =>', - ' n + 1;', + ' n + 1;', '', ].join('\n')); }); diff --git a/src/vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts b/src/vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts index 12c05394dd9..16b5bfd131b 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts @@ -40,4 +40,8 @@ export const javascriptOnEnterRules = [ beforeText: /^\s+([^{i\s]|i(?!f\b))/, action: { indentAction: IndentAction.Outdent } }, + { + beforeText: /^\s*(var|const|let)\s+\w+\s*=\s*\(.*\)\s*=>\s*$/, + action: { indentAction: IndentAction.Indent } + }, ];