VS Code Autoformatting

This isn’t specific to this lesson, but is there really no way to adjust the autocomplete/autoformatting behavior in VS Code so that it doesn’t add “private” and also put the open curly brace on the next line instead of the end of the line? He keeps having to do that every time (and I don’t like having to do it either).

Hi,

Welcome to our community! :slight_smile:

Have you already taken a look at the preferences?

If the autocompletation does not work, please follow the instruction on this website and make sure all required extensions are installed: https://code.visualstudio.com/docs/other/unity

Did this help?


See also:

Ok, so far… I can get it to kind of sort of do what I’m looking for… kind of. I followed everything at Visual Studio Code and Unity and made sure it was all installed.

That stackoverflow thread was talking about settings for Java and Typescript, so the settings they referenced don’t exist for C#. However, digging through it led me here: Auto Formatting Curly Braces on the Same Line in C# in VSCode | by No Such Dev | Medium

Creating that .json file allows VS Code to reformat selected code by highlighting, then hitting Ctrl+K followed by Ctrl+F. That’s a lot of keypresses. Definitely not great, but like I said, it kinda sorta works. Is there really no way to structure how it formats the auto complete?

Also your reply didn’t address the way it inserts “private” into autocompleted methods. It doesn’t technically hurt anything (since they’re private by default anyway), but it’s yet another autoformat behavior. Can it not be changed in settings or config?

That’s a false conclusion. Just because the thread is about another language does not automatically mean that the same options are not available for C#. Given you installed the C# support as an extension, the JSON file at the bottom of the linked article on Medium is represented in the preferences in VS Code. The JSON file of the settings for Java and Typescript looks similar to the one you would use for C#.

Definitely not great, but like I said, it kinda sorta works. Is there really no way to structure how it formats the auto complete?

That sounds as if you are looking for a prettier/prettifier. I found this one. You could test it. If it doesn’t work well, look for C# prettifier and C# prettier online.

Also your reply didn’t address the way it inserts “private” into autocompleted methods. It doesn’t technically hurt anything (since they’re private by default anyway), but it’s yet another autoformat behavior. Can it not be changed in settings or config?

If you cannot archieve that in VS Code and if you cannot find any extension that does that for you, I’d suggest to install and use Visual Studio. The things you mentioned here are definitely possible with VS.

Well thanks for trying to help. I can’t seem to find a solution to the issue; just workarounds. In the end I’m realizing that Visual Studio is just the better option. It’s designed for C#. I gave VS Code a shot because that’s what this course is using. It’s good, but the small limitations have a way of driving me bonkers. All the same, thanks anyway.

VS Code is a good tool but you have to configure a lot to achieve certain things. As for me, I prefer to use VS for C#. Feel free to do the same.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms