Resharper uses different code style than Visual Studio - visual-studio

I am using VS2017 RC to write C# and have lately added Resharper Ultimate. However, Resharper Ultimate seems to ignore the code style I have set in Visual Studio and instead use another (probably the default C#) code style. Since Resharper often auto applies its code style, this is very annoying. I verified that it is indeed resharper by doing this:
Select some code, hit Edit -> Advanced -> Format Selection:
This is the visual studio formatter and it formats my code as desired
Select some code, hit Alt+Enter -> Format Selection:
This is Resharper's format command, and it messes up my codestyle.
So my questions are:
How can I tell resharper to use VS's code style?
If this is not possible, then where can I change the code style that resharper uses, so I can at least adjust the code style manually.
Why does Resharper have its own code style in the first place? Wouldn't it make a lot more sense to always use VS's code style?

As for question #3:
Why does Resharper have its own code style in the first place? Wouldn't it make a lot more sense to always use VS's code style?
I haven't compared the features of Resharper with recent Visual Studio versions in depth, but compared with older versions such as VS2010, the Resharper formatting engine is light-years ahead. Much more settings and flexibility to accomplish the formatting you want (and many sane defaults though that could be a matter of opinion of course). It has been enhanced even more in the 2017/2018 releases.
Resharper can also save the formatting settings to several layers of shared configuration files (committed to VCS) to make sure everyone automatically follows the same rules. This also allows for different rules to apply for different projects.

Related

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

VS Intellisense: removing some autocomplete words

I like that the intellisense in VS corrects me when I make mistakes, but sometimes I don't make any mistakes and it corrects me still. I'm coding for Unity and I cannot write "var" without it being changed to "SerializePrivateVariables" as soon as I press space.
Is there a way to remove some of the autocomplete triggers in the intellisense? I couldn't find how to do so.
You cannot disable specific words from autocompletion in C# in Visual Studio 2015 as far as I know.
In your case, however, you can enable keywords in completion lists. Then the intellisense should understand that var is a proper C# and not replace it.
You can do this by going to TOOLS > Options > Text Editor > C# > Intellisense and checking the "Place keywords in completion lists" option.
There is a bit more options in VS2017 and VS2013 (and older), but none of them have the exact feature you have in mind.

How do R# live templates interact with VS code snippets?

R# has a feature called "live templates" that seems to duplicate the "Code Snippets" feature in built into VS, although it's probably more featureful.
How do the 2 features interact? E.g. I see R# has imported its templates from VS's snippets. What if I edit a VS snippet, that also already exists as a R# template?
VS version: 2015
R# version: 10
They don't interact at all, they're completely separate features. The imported tag that ReSharper uses is a bit of a misnomer. They're not really imported, just copied from the default set of VS snippets. The tag is intended to show that they provide the same functionality as VS snippets, but are separate.
If you edit a VS snippet, it won't affect a ReSharper template, and vice versa. ReSharper will use ReSharper templates in code completion and the editor, but will also expand a VS snippet if you type it and hit Tab. You can also use the keyboard shortcuts or VS menu items to invoke the default VS snippet insertion UI and insert VS snippets that way.

Is there an add-on to get better code formatting?

I've used the Banner style indention scheme for years (http://en.wikipedia.org/wiki/Indent_style), but the last two releases of Microsoft Visual Studio no longer handle this correctly and all day long I'm having to manually reformat code which is a huge pain.
Does anyone know if there are add-on tools that support Banner style indention inside Visual Studio?
Or perhaps you've found a way to trick VS into handling Banner style correctly?
Sure. Resharper can handle this.
Resharper has a 'Code Cleanup' feature that can reformat your entire code base according to your indentation preferences.

Can I make Visual Studio's code completion window more like Eclipse (Java)?

Is it possible to make Visual Studio 2010's code completion window more like that of Eclipse (Java)?
In particular, I'd love the code completion window to give me a variable's type, and a method's return type and expected parameters, without needing to hover the highlight over that particular variable/method. Here's Eclipse's:
VS's code completion's little icons that indicate if something is a property, method etc are useful, but they just aren't enough.
Unfortunately, there's no built-in way to do this. Visual Studio offers only very limited options related to customizing its Intellisense display.
You'll have to turn to third-party solutions or add-ins, or settle down to write your own using one of the existing options as a guide. Here are a few that can be found around the web:
Visual Studio Intellisense Presenter (looks like it might be very close to what you're looking for)
CSharpIntellisensePresenter
Visual Assist X (commercial software with 30-day free trial)

Resources