mblode / vscode-twig-language

VS Code extension with snippets, syntax highlighting, hover, and formatting for Twig.
https://marketplace.visualstudio.com/items?itemName=mblode.twig-language
MIT License
42 stars 7 forks source link

Formatting indented block comments pushes them out to infinity #41

Open OldStarchy opened 5 years ago

OldStarchy commented 5 years ago

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 commented 5 years ago

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

alexd73 commented 4 years ago

I have some issue.

elmofromok commented 4 years ago

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

mblode commented 4 years ago

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

elmofromok commented 4 years ago

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

dzpt commented 3 years ago

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

OldStarchy commented 3 years ago

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.

BellemareMederic commented 3 years ago

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

fgdaniel commented 1 year ago

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,
artveraa commented 7 months ago

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

OldStarchy commented 7 months ago

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.