angular: Angular 17: visual studio code doesn't format control flow
Which @angular/* package(s) are the source of the bug?
language-service
Is this a regression?
No
Description
In visual studio code 1.84.1 with Angular Extension at version 17.0.0, indenting control flow like this:
@if(true){
foo
} else {
bar
}
after document format become
@if(true){
foo
} else {
bar
}
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 17.0.0
Node: 18.18.2
Package Manager: pnpm 8.6.3
OS: win32 x64
Angular: 17.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, localize, material, material-date-fns-adapter
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1700.0 (cli-only)
@angular-devkit/build-angular 17.0.0
@angular-devkit/core 17.0.0 (cli-only)
@angular-devkit/schematics 17.0.0 (cli-only)
@schematics/angular 17.0.0 (cli-only)
rxjs 7.8.1
typescript 5.2.2
zone.js 0.14.2
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Reactions: 20
- Comments: 24 (7 by maintainers)
Unfortunately prettier has a TON of extra html formatting rules which, to me, are garbage. We just want default vscode html formatting + angular control flow, and I don’t want to spend hours configuring prettier to ignore 90% of it’s rules just so we can get indentation on
@if (..) { }
Most angular development is probably done on VSCode and the shiny new control flow syntax is busted (as in it looks bad when it’s whole purpose was to look better) unless you configure an aftermarket overpowered formatting tool?VSCode uses the
HTML Language Features
extension by default, as stated before. This extension uses js-beautify to format the code, as stated here. There is an ongoing issue in the js-beautify repository about the formatting of the new syntax.Any working solutions? It has been a while
Then I guess I’m missing something. I don’t have this extension installed, however, everything works as expected in vscode (except control flow).
This issue is about control flow formatting in vscode and the given solution is to install an extension.
According to me, it does not answer the original question. Who is responsible to implement control flow in vscode without using Prettier then? vscode itself then?
(I’m not saying it’s not a good solution, I’m just trying to understand who is responsible for what 😃)
There’s gotta be a more flexible solution for this. When the cyclomatic complexity starts growing, the template becomes unreadable. The lack of proper formatting is holding this great new feature back…
Then I guess you never used an “if” in a “for” and ended up with something like
} }
Wondering what is what ^^
Formatting is not controlled by our extension. Closing as out of scope.
The Prettier teams is working on formatting with control flow in Angular.
Couldn’t make this work.
when using prettier, update your prettierrc file
Hi, pretty late in the perty…
I have noticed that Vscode doesn’t highlight the new syntax. what is the solution for that.
Exact same situation here. I don’t like prettier but then I guess an issue should be created on the vscode GitHub repo, but I fear they’ll say that they can implement that as it is not standard html.
Ok now it makes sense to me 😃
Thanks for the explanation.
Closing again. Contributing a language does not affect the formatting command, which is controlled by the formatting provider. This is out of scope for our extension. That said, we have been in contact with Prettier to support them in making this work in their extension.