Fix auto indentation after a key with an anchor - #1289
Conversation
The increaseIndentPattern in language-configuration.json contained the HTML entity & instead of &, so lines such as 'base: &base' never matched. Signed-off-by: kwy404 <thekaway404@gmail.com>
h55n
left a comment
There was a problem hiding this comment.
Checked this against master. The pattern in language-configuration.json still has the HTML-escaped &, so "base: &base" and "- &item" never matched. I ran the old and new regex in node: both of those now match, and "key: value" and "- item" still don't, so nothing else changes. The test reads the real config file, which is good. One thing for later, not for this PR: "key: &anc # comment" still doesn't indent, since the anchor is followed by a comment.
|
Thanks for checking it so thoroughly @h55n. Good point about |
|
If I have something like this: root:
second: &refAnd press enter after root:
second: &ref-eranceand you hit enter after |
|
Thanks @datho7561, good catch. The pattern only allowed word characters after |
What does this PR do?
Root cause:
increaseIndentPatterninlanguage-configuration.jsoncontains the HTML entity&where it should have a plain&. Because of that, the optional anchor group(&\w+)?never matches a real anchor, so a line likebase: &baseor- &itemis not seen as opening a block.The extension defaults
editor.autoIndenttokeepfor YAML, so this shows up for users who set"[yaml]": { "editor.autoIndent": "full" }. With that setting, pressing Enter afterbase:indents the next line, but pressing Enter afterbase: &basedoes not.Fix: replace
&with&in the pattern. Nothing else changes.What issues does this PR fix or reference?
No existing issue. The same pattern has been in the file since 2018.
Is it tested? How?
Added
test/languageConfiguration.test.ts. It loadslanguage-configuration.jsonand checks thatincreaseIndentPatternmatchesbase: &baseand- &item. It fails on main (assert.ok(increaseIndentPattern.test('base: &base'))is false) and passes with the fix. The fullnpm testsuite passes.To check it by hand: set
"[yaml]": { "editor.autoIndent": "full" }, typebase: &basein a YAML file and press Enter. The new line is now indented by two spaces, as it is afterbase:.