-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent incorrect indentation for Ruby's in and when keywords #198349
Prevent incorrect indentation for Ruby's in and when keywords #198349
Conversation
39ed9bd
to
8cda707
Compare
This happens with |
cb05c42
to
413e38e
Compare
Co-authored-by: Soutaro Matsumoto <[email protected]>
413e38e
to
bd0c11e
Compare
@jscheel Yeah, we should fix that as well, although I'll split it in a separate PR. For the |
@rebornix any concerns with this PR? |
@vinistock thanks for your contribution. It looks great to me, I'd like to test this thoroughly (maybe we could add some tests for it) before merging the PR. Really appreciate your help. |
I'm happy to add tests for it. Is there an example test for these language configuration files that I can base it on? |
@vinistock it would be great if we can have tests like vscode/src/vs/editor/contrib/indentation/test/browser/indentation.test.ts Lines 289 to 305 in b9511a9
|
@rebornix I put together a test, but I'm having trouble with my local setup. I can't seem to If you don't mind, I'd appreciate you pushing the tests to this branch. This is what I had: // Other tests
// ...
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 }));
disposables.add(languageConfigurationService.register(languageId, {
brackets: [
['{', '}'],
['[', ']'],
['(', ')']
],
indentationRules: rubyIndentationRules,
}));
viewModel.type("def foo\n in");
assert.strictEqual(model.getValue(), "def foo\n in");
});
}); |
@vinistock it seems there are issues with the branch that our CI failed to run properly. I cherry picked your commit and packed in another PR #205397. Let's track it over there. Thanks again for your contribution! |
@vinistock your change is merged via #205397 and should be available in next Insiders, cheers! |
Thank you @rebornix! |
@vinistock @rebornix I'm still thinking about |
Yeah, I agree we should fix it. I believe matching on line breaks would make the most sense, since that's when you want to have it dedented. I made an attempt, but it doesn't seem to be working. I suspect it's something with the line break regex. @rebornix do you see anything obvious that might be wrong in the new regex? Does VS Code accept |
@vinistock the regular expression was validated against the line content, which excludes the line breaks, thus it won't match. That's what we have for the whole regex based system, it would be a huge change if we change that. Regex system is never perfect and I personally believe a "range" formatter is always a better fit. |
Thanks for the context. If we can't match on line breaks, then I don't think it's possible to fix this without on type formatting indeed. We need to add something to the Ruby LSP to correct format the expression after VS Code's regular dedent. |
Currently, the language configuration decreases indentation immediately after the words
in
orwhen
are typed. However, that produces some incorrect decreases.For example, if you are including a module, the include keyword gets incorrectly dedented back.
The
when
keyword has similar issues, since you can create methods namedwhen_something_happens
and then invoking the method gets dedented incorrectly.If we change the regex to wait for one blank space after both
in
andwhen
keywords, then the indentation decrease works properly - since the blank spaces after both of them is required to specify the branch condition.