First off all, sorry if this question already exist but my english is limited for this task.
I use Visual Studio on C# and of course, IntelliSense.
When I write a new method, an If or any other "method/constructor", IntelliSense write like that (when I press Tab or Enter to validate the suggestion)
Actual result :
if (true)
{
// code
}
private void Test()
{
// code
}
// ...
What I want :
if (true) {
// code
}
private void Test() {
// code
}
// etc. ...
See what I want to do ?
I prefer the second 'theme', most readable for me and row economizer.
Is an option behind, hidden in the dark side of VS to do that ?
Thanks for help.
Seems you're asking for javascript style formatting here. I found this link that might help.
1.Click Tools | Options…
2.Scroll down to the Text Editor node
3.Expand the C# node
4.Expand the Formatting node
5.Click on the New Lines node
6.You will see a list of options like in the image below which give you full control over when Visual Studio should put your open brace on
a new line
You can set that on Options window:
Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines
Related
I am trying to format C# code of a WinForms .NET Core 7.0 project in Visual Studio Community:
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<String, String> Dictionary = new Dictionary<String, String>
{
{ "operation", "login" },
{ "phone", "123"},
{ "country","456"} ,
{ "otp", "789"},
{"language","111" }
};
}
I have tried Ctrl+K, Ctrl+D, removing the last brace in the code and putting it back.
The extra spaced are not getting removed. Can these be removed in whole code automatically using a command? If not, is there a plugin / extension that can help in code formatting?
Use the shortcut key Ctrl+f.
Enter [^\S\r\n]{2,} in FIND
The value in the "replace" is empty
Select use regular expression(Alt+E)
Click the Replace All button(Alt+A)
Use the Auto Align shortcut (CTRL+K+D)
ReSharper works with VS Community and will reformat that case by either
removing the ; and re-entering it (format on typing)
or reformatting the whole file via Cleanup Code... on the context menu for the C# file.
You'd have to pay for ReSharper, though, unless you're a student, working on an open-source project, or otherwise qualify for the free license.
Visual Studio Community (and probably Pro and Enterprise) doesn't seem to reformat dictionaries regardless of what you seem to do with a .editorconfig file or what you have set in Tools | Options | Text Editor | C# | Code Style | Formatting | General.
There may be other extensions that do this. Perhaps you could find one on the Visual Studio Marketplace.
I need to set the value of a Visual Studio option found in Visual Studio -> Tools -> Options -> Text Editor -> JavaScript/TypeScript -> EsLint but I can't seem to find the CollectionPath for this option.
GetSubCollectionNames("Text Editor"); yield a number of results, while GetSubCollectionNames("Text Editor\\JavaScript"); yield 0 results.
TL;DR
How would one go about finding the right CollectionPath for the option pictured in the image below?
This is what I'm using currently.
[ImportingConstructor]
internal VSOptions([Import] SVsServiceProvider serviceProvider)
{
var settingsManager = new ShellSettingsManager(serviceProvider);
_writableSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings)
?? throw new Exception(nameof(settingsManager));
var textEditorSubCollections = _writableSettingsStore.GetSubCollectionNames("Text Editor");
var javaScriptSubCollections = _writableSettingsStore.GetSubCollectionNames("Text Editor\\JavaScript");
// TODO: set option value when we have the right CollectionPath
}
The WritabelSettingsStore class used to extend Visual Studio common settings in Visual Studio. You could use GetPropertyNames("Text Editor\JavaScript") to list all writabel settings for JavaScript, where you will find not all Properties under JavaScript sub collections are listed.
The EsLint is not common Visual Studio Settings. It is third part tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs.
So we could not change it directly with WritableSettingsStore class. You need to know how the EsLint added in Visual Studio and then modify its configuration file for Visual Studio.
does anyone know how i can get an indentation after pressing enter on a open brace?
Instead of:
public void SomeFunction()
{
[cursor here]
}
this here:
public void SomeFunction()
{
[cursor here]
}
So after typing the open { i don't want to have the same indention as the brackets but be indented by one tab
I ran into this earlier today. I found out that it's not ReSharper, but Visual Studio. Solution here: Visual Studio 2013 Indentation Not Working While Writing
If I enter some simple code such as:
public void Hello()
and then press enter and type a {, I get:
public void Hello()
{ }
I would like the result to be either:
public void Hello()
{ // no added '}'
or:
public void Hello()
{
} // the '}' on a new line
I've looked around Tools -> Options -> Text Editor -> C# -> Code Style and Tools -> Options -> Text Editor -> C# -> Formatting but cannot seem to find how to make the above changes.
Install Productivity Tools 2015
Auto brace completion is one of the many features it has to offer
Im writing a policy plugin for VS which checks several issues with the code. If an issue occurs it will be displayed in the policy warnings tab. Now I want to jump to the line where the issue occurs in the editor when I double click it in the policy warning tab. How can I do that?
namespace PolicyPlugin
{
[Serializable]
public class MyPolicyPlugin : PolicyBase
{
//...
//called if the user clicks on a policy warning
public override void Activate(PolicyFailure failure)
{
// make jump to line x
}
}
}
Thanks!
You could try to get DTE automation object first:
EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
or use alternative ways to get it.
An then execute standard command (that's what happens when you press CTRL+G in Visual Studio)
DTE.ExecuteCommand("Edit.Goto", "1234")
Note: I'm not sure about exact ExecuteCommand method signature. Also you can manipulate IDE the same way for other commands.