From 32aaeac3d6453e26fa22708b08fcd5a18c07fd5d Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 11:04:24 +0100 Subject: [PATCH 1/7] adding pattern for if for and while --- .../language-configuration.json | 3 +++ .../test/browser/indentation.test.ts | 21 ++++++++++++------- .../supports/javascriptIndentationRules.ts | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 2d14b1cab19..5c0c1184ac7 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -137,6 +137,9 @@ // e.g. * ...| or */| or *-----*/| "unIndentedLinePattern": { "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" + }, + "indentNextLinePattern": { + "pattern": "^.*[if|while|for]\\s*\\(.*\\)\\s*" } }, "onEnterRules": [ 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 6ef21225b56..b91ef13839a 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -672,15 +672,13 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test.skip('issue #43244: incorrect indentation', () => { + test('issue #43244: incorrect indentation', () => { // 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); @@ -688,13 +686,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)', + ' ', + '}', + ].join('\n')); + + viewModel.type("return;"); viewModel.type("\n", 'keyboard'); assert.strictEqual(model.getValue(), [ 'function f() {', ' if (condition)', ' return;', - '', + ' ', '}', ].join('\n')); @@ -703,8 +710,8 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { 'function f() {', ' if (condition)', ' return;', - '', - '', + ' ', + ' ', '}', ].join('\n')); }); diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index 12fb83c4925..d448df7e91f 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -7,5 +7,6 @@ export const javascriptIndentationRules = { decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/, increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| - unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/ + unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, + indentNextLinePattern: /^.*[if|while|for]\s*\(.*\)\s*/ }; From d1e28c49f3f0e405857dd72235b072fe72ffdd55 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 11:24:10 +0100 Subject: [PATCH 2/7] fixing the tests --- .../test/browser/indentation.test.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) 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 b91ef13839a..64dd4bab45b 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -566,7 +566,7 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test.skip('issue #208215: outdented after semicolon detected after arrow function', () => { + test.skip('issue #208215: outdent after semicolon detected after arrow function', () => { // Notes: we want to outdent after having detected a semi-colon which marks the end of the line, but only when we have detected an arrow function // We could use one outdent pattern corresponding per indent pattern, and not a generic outdent and indent pattern @@ -672,7 +672,7 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test('issue #43244: incorrect indentation', () => { + test('issue #43244: incorrect indentation after if/for/while without braces', () => { // https://github.com/microsoft/vscode/issues/43244 @@ -717,6 +717,35 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); + test.skip('issue #43244: incorrect indentation after if/for/while without braces 2', () => { + + // https://github.com/microsoft/vscode/issues/43244 + + const model = createTextModel([ + 'function f() {', + ' if (condition)', + ' return;', + ' ', + '}', + ].join('\n'), languageId, {}); + disposables.add(model); + + withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => { + + registerLanguage(instantiationService, languageId, Language.TypeScript, disposables); + editor.setSelection(new Selection(4, 5, 4, 5)); + viewModel.type("\n", 'keyboard'); + assert.strictEqual(model.getValue(), [ + 'function f() {', + ' if (condition)', + ' return;', + ' ', + ' ', + '}', + ].join('\n')); + }); + }); + test.skip('issue #208232: incorrect indentation inside of comments', () => { // https://github.com/microsoft/vscode/issues/208232 From bdf352fe4e6821a8f6550433dbdcd0d28ea3d6d7 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 11:28:47 +0100 Subject: [PATCH 3/7] remove part of test --- .../indentation/test/browser/indentation.test.ts | 10 ---------- 1 file changed, 10 deletions(-) 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 64dd4bab45b..7b4f667fc0c 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -704,16 +704,6 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { ' ', '}', ].join('\n')); - - viewModel.type("\n", 'keyboard'); - assert.strictEqual(model.getValue(), [ - 'function f() {', - ' if (condition)', - ' return;', - ' ', - ' ', - '}', - ].join('\n')); }); }); From 5228f5a8b6dbb3339be374cae5cdc382eb89571f Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 12:13:20 +0100 Subject: [PATCH 4/7] adding dollar sign at the end of the regex to match the full line --- extensions/typescript-basics/language-configuration.json | 2 +- .../test/common/modes/supports/javascriptIndentationRules.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 5c0c1184ac7..961461d6889 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -139,7 +139,7 @@ "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" }, "indentNextLinePattern": { - "pattern": "^.*[if|while|for]\\s*\\(.*\\)\\s*" + "pattern": "^.*[if|while|for]\\s*\\(.*\\)\\s*$" } }, "onEnterRules": [ diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index d448df7e91f..36cbfce502b 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -8,5 +8,5 @@ export const javascriptIndentationRules = { increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, - indentNextLinePattern: /^.*[if|while|for]\s*\(.*\)\s*/ + indentNextLinePattern: /^.*[if|while|for]\s*\(.*\)\s*$/ }; From 62275bbca63a6dd6ada395277bec8415a9ccfdff Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 12:43:17 +0100 Subject: [PATCH 5/7] changing to round brackets inside of the regex pattern --- extensions/typescript-basics/language-configuration.json | 2 +- .../test/common/modes/supports/javascriptIndentationRules.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 961461d6889..39923f90e06 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -139,7 +139,7 @@ "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" }, "indentNextLinePattern": { - "pattern": "^.*[if|while|for]\\s*\\(.*\\)\\s*$" + "pattern": "^.*(if|while|for)\\s*\\(.*\\)\\s*$" } }, "onEnterRules": [ diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index 36cbfce502b..1915c15a67b 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -8,5 +8,5 @@ export const javascriptIndentationRules = { increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, - indentNextLinePattern: /^.*[if|while|for]\s*\(.*\)\s*$/ + indentNextLinePattern: /^.*(if|while|for)\s*\(.*\)\s*$/ }; From 5d1d7d98a6dcc7b69109cdd4c9f32f2105f2df1f Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 17:14:53 +0100 Subject: [PATCH 6/7] adding parentheses aroudn the two different alternatives --- extensions/typescript-basics/language-configuration.json | 2 +- .../test/common/modes/supports/javascriptIndentationRules.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index e27ed98e1b9..3d3cc38e659 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -139,7 +139,7 @@ "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" }, "indentNextLinePattern": { - "pattern": "^(.*=>\\s*|.*(if|while|for)\\s*\\(.*\\)\\s*)$" + "pattern": "^((.*=>\\s*)|(.*(if|while|for)\\s*\\(.*\\)\\s*))$" } }, "onEnterRules": [ diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index f45d0d8a0d5..49a4c57944d 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -8,5 +8,5 @@ export const javascriptIndentationRules = { increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, - indentNextLinePattern: /^(.*=>\s*|.*(if|while|for)\s*\(.*\)\s*)$/, + indentNextLinePattern: /^((.*=>\s*)|(.*(if|while|for)\s*\(.*\)\s*))$/, }; From 20b54ec19e300ece363b50d43f74096d17d831aa Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Thu, 21 Mar 2024 17:24:52 +0100 Subject: [PATCH 7/7] making the regex pattern so that we don't match if/for/while inside of a word --- .../language-configuration.json | 2 +- .../test/browser/indentation.test.ts | 29 ------------------- .../supports/javascriptIndentationRules.ts | 2 +- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/extensions/typescript-basics/language-configuration.json b/extensions/typescript-basics/language-configuration.json index 3d3cc38e659..f081fa23f7c 100644 --- a/extensions/typescript-basics/language-configuration.json +++ b/extensions/typescript-basics/language-configuration.json @@ -139,7 +139,7 @@ "pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*\\*([ ]([^\\*]|\\*(?!/))*)?$" }, "indentNextLinePattern": { - "pattern": "^((.*=>\\s*)|(.*(if|while|for)\\s*\\(.*\\)\\s*))$" + "pattern": "^((.*=>\\s*)|((.*[^\\w]+|\\s*)(if|while|for)\\s*\\(.*\\)\\s*))$" } }, "onEnterRules": [ 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 3fc3e23f87a..b203c17480f 100644 --- a/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts +++ b/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts @@ -698,35 +698,6 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => { }); }); - test.skip('issue #43244: incorrect indentation after if/for/while without braces 2', () => { - - // https://github.com/microsoft/vscode/issues/43244 - - const model = createTextModel([ - 'function f() {', - ' if (condition)', - ' return;', - ' ', - '}', - ].join('\n'), languageId, {}); - disposables.add(model); - - withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => { - - registerLanguage(instantiationService, languageId, Language.TypeScript, disposables); - editor.setSelection(new Selection(4, 5, 4, 5)); - viewModel.type("\n", 'keyboard'); - assert.strictEqual(model.getValue(), [ - 'function f() {', - ' if (condition)', - ' return;', - ' ', - ' ', - '}', - ].join('\n')); - }); - }); - test.skip('issue #208232: incorrect indentation inside of comments', () => { // https://github.com/microsoft/vscode/issues/208232 diff --git a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts index 49a4c57944d..9842856423d 100644 --- a/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts +++ b/src/vs/editor/test/common/modes/supports/javascriptIndentationRules.ts @@ -8,5 +8,5 @@ export const javascriptIndentationRules = { increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/, // e.g. * ...| or */| or *-----*/| unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/, - indentNextLinePattern: /^((.*=>\s*)|(.*(if|while|for)\s*\(.*\)\s*))$/, + indentNextLinePattern: /^((.*=>\s*)|((.*[^\w]+|\s*)(if|while|for)\s*\(.*\)\s*))$/, };