Skip to content

Commit

Permalink
Merge pull request #205397 from microsoft/rebornix/stuck-scallop
Browse files Browse the repository at this point in the history
Ruby indentation rules update
  • Loading branch information
rebornix authored Feb 16, 2024
2 parents 89bc8c3 + 025e11a commit 49f6e8b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extensions/ruby/language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
],
"indentationRules": {
"increaseIndentPattern": "^\\s*((begin|class|(private|protected)\\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\\sdo\\b)|([^#]*=\\s*(case|if|unless)))\\b([^#\\{;]|(\"|'|\/).*\\4)*(#.*)?$",
"decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif|when|in)\\b)"
"decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif)\\b)|((in|when)\\s)"
}
}
62 changes: 62 additions & 0 deletions src/vs/editor/contrib/indentation/test/browser/indentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,65 @@ suite('Editor Contrib - Keep Indent On Paste', () => {
});
});
});

suite('Editor Contrib - Auto Dedent On Type', () => {
let disposables: DisposableStore;

setup(() => {
disposables = new DisposableStore();
});

teardown(() => {
disposables.dispose();
});

ensureNoDisposablesAreLeakedInTestSuite();

test('issue #198350: in or when incorrectly match non keywords for Ruby', () => {
const languageId = "ruby";
const model = createTextModel("", languageId, {});
disposables.add(model);

withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
const languageService = instantiationService.get(ILanguageService);
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
disposables.add(languageService.registerLanguage({ id: languageId }));
const languageModel = languageConfigurationService.register(languageId, {
brackets: [
['{', '}'],
['[', ']'],
['(', ')']
],
indentationRules: {
decreaseIndentPattern: /\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif|when|in)\b)/,
increaseIndentPattern: /^\s*((begin|class|(private|protected)\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\sdo\b)|([^#]*=\s*(case|if|unless)))\b([^#\{;]|(\"|'|\/).*\4)*(#.*)?$/,
},
});

viewModel.type("def foo\n i", 'keyboard');
viewModel.type("n", 'keyboard');
// The 'in' triggers decreaseIndentPattern immediately, which is incorrect
assert.strictEqual(model.getValue(), "def foo\nin");
languageModel.dispose();

const improvedLanguageModel = languageConfigurationService.register(languageId, {
brackets: [
['{', '}'],
['[', ']'],
['(', ')']
],
indentationRules: {
decreaseIndentPattern: /\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif)\b)|((in|when)\s)/,
increaseIndentPattern: /^\s*((begin|class|(private|protected)\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\sdo\b)|([^#]*=\s*(case|if|unless)))\b([^#\{;]|(\"|'|\/).*\4)*(#.*)?$/,
},
});
viewModel.model.setValue("");
viewModel.type("def foo\n i");
viewModel.type("n", 'keyboard');
assert.strictEqual(model.getValue(), "def foo\n in");
viewModel.type(" ", 'keyboard');
assert.strictEqual(model.getValue(), "def foo\nin ");
improvedLanguageModel.dispose();
});
});
});

0 comments on commit 49f6e8b

Please sign in to comment.