vscode-twig-language icon indicating copy to clipboard operation
vscode-twig-language copied to clipboard

Formatting indented block comments pushes them out to infinity

Open OldStarchy opened this issue 5 years ago • 11 comments

twig indent bug

Version: 1.39.0-insider (user setup)
Commit: bdd1971f2cd9d08a8a90e02740f1850afe03da66
Date: 2019-09-17T06:02:08.670Z
Electron: 6.0.9
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18362

OldStarchy avatar Sep 19 '19 01:09 OldStarchy

Same issue as https://github.com/mblode/vscode-twig-language-2/issues/50

OldStarchy avatar Sep 19 '19 01:09 OldStarchy

I have some issue.

alexd73 avatar Nov 16 '19 12:11 alexd73

This is happening to us as well. It is causing problems in our workflow. Any solution?

elmofromok avatar Jul 23 '20 19:07 elmofromok

Hey guys, thank you for creating issues and using my extension. Definitely check out Prettier twig melody because that seems to be in active development and has a big company behind it. This extension relies on PrettyDiff 3 and so some bugs are out of my ability to fix. I’ll ensure that the version of PrettyDiff is updated, however, I’m not certain it will fix this annoying bug

mblode avatar Jul 28 '20 21:07 mblode

Thank you for the reply Matthew. I will check out that extension. I appreciate all the work you have done on this project.

elmofromok avatar Jul 29 '20 04:07 elmofromok

anyone know how to fix this annoying error? i have to put to avoid block indent

dzpt avatar Oct 15 '21 15:10 dzpt

This underlying formatter PrettyDiff hasn't seen any attention for a while now. I know it's no help but I ended up disabling the formatter completely, since there are also other issues like not respecting whitespace. Having no formatter is better than a formatter that is going to potentially break your code.

OldStarchy avatar Oct 18 '21 01:10 OldStarchy

have the same problem here and ... i disable the extension, because i lost more time unindent than formating XD

BellemareMederic avatar Oct 29 '21 14:10 BellemareMederic

I solve this problem with 'prettier-plugin-twig-melody' and prettier config only for twig files

Use .prettierrc.json

{
	"endOfLine": "crlf",
	"tabWidth": 4,
	"useTabs": true,
	"printWidth": 120,
	"singleAttributePerLine": true,
	"twigPrintWidth": 120,
	"twigAlwaysBreakObjects": true,
	"twigMultiTags": [
		"nav,endnav",
		"switch,case,default,endswitch",
		"ifchildren,endifchildren",
		"cache,endcache"
	],
	"plugins": ["./node_modules/prettier-plugin-twig-melody"]
}

My VSCode Settings for twig

"[twig]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"twig-language-2.braces": false,
"twig-language-2.bracePadding": true,
"twig-language-2.formatting": false,
"twig-language-2.formatArray": "indent",
"twig-language-2.formatObject": "indent",
"twig-language-2.ternaryLine": true,

fgdaniel avatar Apr 26 '23 08:04 fgdaniel

@OldStarchy did you find a solution? I have the same problem

artveraa avatar Mar 15 '24 08:03 artveraa

No. I stopped using a formatter and just did it manually.

I realized the problem is intrinsic to text-based templating languages, which is pretty much all of them. Its impossible to "correctly" format a templating language because its possible for the template to produce invalid output which cannot be formatted. Unless you just ignore the output and only format the control structures of the template language itself, but that won't necessarily make it look nice.

Now I don't use any templating language and instead use (p)react.

OldStarchy avatar Mar 28 '24 05:03 OldStarchy