Visual Studio code style preference csharp_prefer_braces not working - visual-studio

In Visual Studio 2017 I go to Tools > Options > Text Editor > C# > Code Style, and toggle the option "Prefer braces" from yes to no and back.
It does nothing. The preview below the options always has braces regardless of the setting.
Even an explicit .editorconfig file on csharp_prefer_braces = false:none does not change the behavior.
Is this a bug? Or is some other option overriding?

The property after the ":" will decide how this is treated in VS Code. So using none will mean that VSCode doesn't actually enforce this.
The MS docs here describe "none" as:
"None": Do not show anything to the user when this rule is violated. Code generation features generate code in this style, however. Rules with none severity never appear in the Quick Actions and Refactorings menu. In most cases, this is considered "disabled" or "ignored".
Perhaps you could try using csharp_prefer_braces = false:error instead?

Related

IntelliSense -> Enter AutoComplete for every language - Visual Studio

How to put the input of the first prompt on Enter from IntelliSense in Visual Studio?
For example, for C++ there is make so easy just change Member List Commit Aggressive to True at the settings, but how it make for other languages?
Tested on my side, and the default setting(IntelliSense) of C# highlighted and selected the default first prompt on Enter. Also tested with VB, it seems sometimes, under specific circumstances, the IntelliSense will not select the first prompt in the list, but select the most recommended code. If you continue to type more codes, the result will be the only (first) one.
Did you change some settings of IntelliSense in VS or install some extensions?
Please try to disable extensions temporary or/and reset settings, choose General on step 4, and see if it works.

How to turn off auto indent in Visual Studio 2019? (not VISUAL STUDIO CODE)

I usually use comma , to set the same variable type like the gif above.
But a problem is when I hit Enter after write second variable, the VS breaks the line automatically.
As a formal Atom user, it's a bit tedious because in Atom it doesn't break the line whatever the indent number is. (My current indent number is 2.)
I changed and tested it all of the options inTools > Options > Text Editor > Basic > Tabs, but none of these turn off the breaking line. Even disabling pretty listening won't work.
How do I turn off this feature?
Judging by the glimpse of Intellisense and the fact that Enter auto-formats, it looks like you're editing a JavaScript file.
To disable auto-formatting after hitting Enter, go to Tools > Options > Text Editor > JavaScript/TypeScript > Formatting > General and toggle Format completed line on Enter to unchecked:
The accepted answer doesn't work in Visual Studio 2019 with Visual Basic. These options on the image aren't even shown in the Options for Basic.
However, when the Pretty listing option is turned off, this behavior ceases.

How do I turn off intellisense for javascript?

While editing javascript content VisualStudio is starting to bug me with how it keeps inserting highlighted suggestions. For example it keeps inserting valueOf( if I type val(. This is really annoying.
I want to invoke intellisense manually just like I can with C#, is there any way of turning off the auto-complete suggestion or at least preventing it from selecting an entry for me?
In Visual Studio Tools > Options > Text Editor > JScript
In corresponding panel as Statement completion
Uncheck Autolist members & Parameter Information
I think that should do the trick
I realize resharper isn't mentioned in the question, however there is an easy solution if you're using it.
Navigate to Resharper -> Options -> Intellisense -> Completing Character. Once there, add ".val(" to the "Do not complete on" text field beside the JavaScript row.
Like so:
I tried Myra's solution but it didn't solve it completely for me due to ReSharper. Turned out it was the ReSharper intellisense that autocompleted whatever I was writing to the current/top option in the intellisense list, not the VS default intellisense.
I fixed this by turning off ReSharper's JavaScript support completely by going to ReSharper -> Options -> Products & Features -> Uncheck JavaScript and TypeScript.
This might not be a good solution if you depend on any other JavaScript- or TypeScript-related features in ReSharper but I finally got control of the intellisense. Peace, at last...
(Just to be clear, I still have the "Autolist members" and "Parameter Information" options as described in Myra's post above checked/activated, and the "Only use Tab or Enter to commit" option as described in Brett Ryan's comment above also checked/activated)
for me it was also resharper (replacing my .each with .forEach), and what I did is go to
menu
Resharper -> Options
Environment -> IntelliSense -> Autopopup
select JavaScript tab
"After dot" -> select "Display but do not preselect" in the dropdown

Visual Studio Formatting -- Change Method Color

The default appearance of a method for example, ".ToString()" is by default the color black. I want to make it a different color to stand out but I do not see any options that reference this option specifically.
I remember one of former collegues showing me his VS IDE years ago and he had it setup this way but I cannot recall what he did.
Does anyone have any ideas on how to do this?
In VS 2019 go to Tools - Options - Text Editor - C# - Advanced - Editor Color Scheme and change it to Visual Studio 2019. Method names are now colored and everything has little bit better colors.
You can do this with an extension: SemanticColorizer is what I use.
Tools -> Extensions and Updates -> Online -> Search for SemanticColorizer
It allows you to modify the colors of methods, static functions, constants, member variables, and just about anything else you can think of.
For Visual Studio 2010
Tools > Options
Environment > Fonts and Colors
Change "User Types"
To change the color of the Method Calls go to
Tools > Options > Environment > Fonts and Colors > User Members - Methods > Item foreground Color > Select desired color.
This will also work in Visual Studio 2019.
Go to Visual Studio "Tools>Options>Environment>Fonts and Colors" the menu shows a "Display Items" list, select "Identifiers"(out of which 'methods' is a member). Use the format controls to personalize the displaying of your chosen item. Unfortunately, variables, instances and namespaces are members of "Identifiers" so they will affected too.
If you are using Resharper then a more specific list of items is displayed.
For myself, I wrote a simple, lightweight "editor classifier extension" for Visual Studio based on the async Roslyn APIs to Syntax Highlighting user tags in C# and Visual Basic code.
It has syntax highlighting for:
"Events"
"Fields"
"Fields (Constant)"
"Fields (Inside Enums)"
"Local Variables"
"Methods"
"Methods (Extension)"
"Methods (Static)"
"Namespaces"
"Parameters"
"Properties"
In the future, perhaps coming on the "syntax highlighting" for something else.
You can install this extension from the Visual Studio Marketplace by following the link below:
Download: "Enhanced Syntax Highlighting".
You can change the syntax highlighting settings by going to "Tools" > "Options" > "Environment" > "Fonts and Colors" > "Text Editor" and scrolling to properties starting with the prefix "User Tags - ...".
The syntax highlighting options for "Classes", "Delegates", "Enums", "Interfaces", "Modules", "Structures" and "Type Parameters" are just below, they have the prefix "User Types - ..." and are built-in default.
Good luck.
The built-in syntax highlighters use lexical analysis. A lexer can classify identifiers, comments, literals, numbers, keywords. The parts you find back in the Tools > Options > Environment > Fonts and Colors dialog.
Recognizing that an identifier is a method, property, field requires parsing. Parsing generally only works well when you've got a well-formed program, you rarely have one while you are typing code. So wasn't favored by Microsoft. You can find alternatives in the Visual Studio gallery.
Thanks to "#Ian" said User Types. For me "User Members - Methods" worked.
Tools
Options
Enviromment
Fonts and Colors
In Display items: "User Members - Methods"
Change Item foreground
Semantic Colorizer didn't work for me (VS 2019 Preview).
Enhanced Syntax Highlighting did exactly what I needed.
Tools > Options > Environment > Fonts and Colors has an extensive list of things you can change both font face, font size, color, style, etc.
Also, Jeff Atwood had a great post a few years ago about IDE font and colour schemes that you might find interesting.
In a previous version of visual studio (I think 2010) there was a plugin that allowed you to color code methods. I don't remember the name of it now as we have continued to progress forward in versions. The author did not keep up with the version updates of VS.
Update: VS10x allows you to color code methods in Visual Studio all the way through VS2015. A link to the authors Visual Studio Galleries page can be found here: https://visualstudiogallery.msdn.microsoft.com/1c54d1bd-d898-4705-903f-fa4a319b50f2?SRC=VSIDE
I am currently using this in VS2013 successfully.

Visual Studio Macro to Indent C/C++ Braces

We have an old project that we maintain that uses brace indenting. Rather than having to change my Visual Studio options every time I switch projects, I'd like to be able to do this quickly and easily.
I'm trying to write a macro in Visual Studio to turn Brace Indenting on and off.
The checkbox is under Text Editor -> C/C++ -> Formatting
Indentation: Indent Braces
This doesn't work:
DTE.Properties("TextEditor", "C/C++").Item("IndentBraces").Value = True
I get "Value does not fall within the expected range."
Any ideas? I haven't been able to find anything on this.
I found the following is the correct macro code to make this work
DTE.Properties("TextEditor", "C/C++ Specific").Item("IndentBraces").Value = True
see: "Determining Names of Property Items in Tools Options Pages" which is only mildly helpful in this situation but gave me enough of a clue to find it.

Resources