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
Add settings to allow initial indentation for script and style #1806
Comments
We are running into this as well. To my personal aesthetics I also prefer the script tag to be indented - though I could live with it. The problem for us is we use a mixed environment of C# and TS/Vue code. Some of those C# bits are WebForms and other languages/frameworks that aren't supported in VS Code (more specifically, easily running them is not supported). As a result, we have a mix of users on VS2022 and VS Code. The issue is that VS2022 indents the script tag in the .vue files since it just sees it as an XML/HTML file and that is the standard formatting it does. I looked and could not find a setting to change this. So when people auto format the document on VS 2022, it adds the 4 character indentation inside the script tag. But then when people auto-format in VS Code, it removes the 4 character indentation. So it would be nice to be able to configure Volar to add/keep the indentation so it matches - or at least is a very close match. |
I notice that Vetur had two options, |
Was trying to implement this myself, but I couldn't even figure out how to debug the VS Code Volar Vue formatting engine! From what I can tell from the system overview diagram, though, this feature would probably need to be implemented in |
@jez9999 You can add a new VSCode setting and fetch and use it at here. https://github.com/johnsoncodehk/volar/blob/2758510a8e519563f16ce023c700ab98b8b65ad8/packages/vue-language-service/src/plugins/typescript.ts#L246-L252 |
@johnsoncodehk Right but how do you debug the formatting code? When I open the Volar project and hit F5, it opens a new VS Code window, but inside that window there is no Volar code formatter configured for .vue files. |
@jez9999 You need to open an other workspace such as github.com/johnsoncodehk/volar-starter to the new VSCode window, or just open new untitled vue document on the window for testing. |
@johnsoncodehk That appears to work but I now have a new problem; it doesn't appear to be changing indentation at all for |
Also, no breakpoints are binding in |
PR submitted. |
@johnsoncodehk Thanks for merging! However, I think your refactor means that "Format Selection" will reformat an entire section of a .vue file if any of that section is selected, rather than just formatting the code within the selected range. What I tried to do was only format the code in the selected range. This is admittedly pretty difficult for style and JSON, but at least with Typescript/Javascript you might want to go back to the method I used of passing the indent through to |
It's also causing the entire |
Another idea that might work in a more general sense is to have an algorithm like:
|
The new setting "volar.format.initialIndent" seems to be ignored. The default is for only HTML to have the initial indent, but in my experience, the initial indent is applied everywhere (in script setup files, at least), whether they are set to 'false' or not. Additionally, this new feature seems to add the initial indent not just at the beginning of the script tag, but after new lines in the interior of the script tag code. I'm afraid it's become somewhat frustrating for me and I've had to revert back to 0.40.1 to restore the original functionality. I've tried explicitly setting each language to false in the setting, but it still adds the initial indent in each section of the script setup file. This behavior starts in 0.40.2. Given that it changes the original functionality, I don't think this feature should be implemented without the ability to turn it off. |
Odd, I'm running 0.40.13 and this config gets rid of all the indentation:
|
I think if you select all and format selection it will remove the indentation. The specific bug seems to be the indentation given when you hit Enter, which does seem to give indentation if these are set to false. Perhaps worth opening an issue on that specific behaviour? |
Yes, formatting the document after the fact removes the indentation, but having to type "enter + backspace" every time the user would have normally just had to type "enter" harms productivity. This feature isn't complete as long as this bug exists, so I thought it would be better to detail the problem here rather than create a new issue. But I'll open a new issue if that's appropriate. |
Volar uses the VS Code settings for indentation of code, but it doesn't put an initial indent in for the
script
orstyle
tags invue
files. Could you add in a couple of settings that allows us to have that indent? I know the Vue default style may not have it, but to my eyes it looks horrible having opening and close tags with no indent. I'd like to have the indent option for auto-formatting.The text was updated successfully, but these errors were encountered: