I am trying to write C# code in MonoDevelop for Ubuntu Linux, but the editor will not format the braces. It used to format them nicely, like so:
void Method()
{
if (condition)
{
//...
}
}
Then one time as I reopened MonoDevelop, the editor started leaving the left brace hanging:
void Method() {
//cursor left here after pressing Enter, no right brace
After I went to Edit > Preferences > Text Editor > Behavior > Checked "Insert matching brace", the editor started appending a } to the end of the block. However, the problem is that now my code is formatted Eclipse/Java-style, which I definitely don't want. See below:
void Method() {
if (condition) {
//...
}
}
For some reason, going to Edit > Preferences > Source Code > Code Formatting > C# > Setting policy to "Microsoft Visual Studio" doesn't help with this. "Enable on the fly code formatting" is checked off, too. Edit > Format > Document works perfectly though, so I don't know what's wrong.
Edit > Preferences > Source Code > Code Formatting are IDE settings which are used when creating new solutions/projects. You should go into your solution settings(double click on solution in SolutionPad) and change settings under "Source Code->Code Formatting->C# source code".
MonoDevelop supports per project(or solution if project has "inherit" policy set).
Related
After I type if (view=="") { and press Enter, VS formats and indents the curly braces to this:
if (view == "")
{
}
How can I change the settings in Visual Studio 2019 to just have it like this
if (view == "")
{
}
I've been looking and trying different combinations and can't seem to find the setting.
If you want to get the format you need, you can refer to the parameters of this option:
Tools>Options>Text Editor>C#>Code Style>Formatting>Indentation, uncheck the option ”Indent open and close braces”.
Since I switched to VS 2019 (from 2017) I am pretty sure I got a degraded IntelliSense experience. I looked for settings under Tools -> Options... but did not find anything helpful.
The matter is this: suppose I have a variable kvp that has a property Key, I could type "key.", scroll to the "Key" property (if this is not already selected) and then type ";" to complete the statement.
But this does not work anymore. Instead it now ignores what I selected and I get
key.;
The only way to get the selected property is to explicitly hit enter. Same when I type the first character(s) to select the desired option: when pressing ; it just leaves what I already typed and adds the ; immediately behind it, ignoring what I selected in the popup menu.
What happened and how do I get the proper behavior back?
I am using the Preview version but I already had a couple of updates and it does not improve so I guess it is by design or default behavior now.
Here's some of my code for Perry. It is just an example though, the problem (or what I regard to be a problem) occurs with any object variable.
private static void AddBlockNodes(TreeNode node, IDictionary<string, Block> blocks)
{
foreach (KeyValuePair<string, Block> kvp in blocks)
{
string name = kvp.Key;
Block block = kvp.Value;
TreeNode childNode = new TreeNode(name);
childNode.Tag = block;
node.Nodes.Add(childNode);
AddBlockNodes(childNode, block.Subblocks);
}
}
it just leaves what I already typed and adds the ; immediately behind
it, ignoring what I selected in the popup menu.What happened and how
do I get the proper behavior back?
It is quite an abnormal behavior and l have installed Visual Studio 16.6.0 Preview 2.1 and test your code in my side and it works well.
Type variable kvp. and then select property Key and it types as expected. I did not face missing property Key during the process.
You can try these steps to troubleshoot your issue:
Suggestion
1) reset all settings by Tools-->Import and Export Settings-->Reset all settings
2) close VS Instance, enter the project path and delete .vs hidden folder which stores some Intellisense settings, bin, obj folder and then restart your project again. I wonder if you migrate an old project into VS2019 preview version, I think you should complete this step.
3) disable any third party extensions if you have under Extensions-->Manage Extensions in case they cause this behavior.
4) delete all component caches under C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxx(16.0 is VS2019)\ComponentModelCache
5) try to create a new project in VS2019 Preview version and test whether this issue persists in the new platform and if it works, I think it is an issue of your project itself. Or you can try to migrate your project into the new project.
Hope it could help you.
In Visual Studio Code (MacOS) I've already spend hours finding how to put open brace to the new line when you type. I type this:
class Foo{
...and press Enter. I get the closing brace automatically:
class Foo{
}
But I want this (like VS 2017 did):
class Foo
{
}
I can do that with format command (Shift + Alt + F), but can I have it automatically?
I've tried different extensions (my lines from in User Settings).
ryannaddy.vscode-format: "format.newLine": { "brace": true }
Leopotam.csharpfixformat: "csharpfixformat.style.braces.onSameLine": false
"editor.formatOnType": true
Omnisharp: { "FormattingOptions": { "NewLinesForBracesIn...": true, } }
All without any success, none of these setting did this formatting on typing.
There should be an option in the VS Text Editor settings under
Tools -> Options -> Text Editor -> C# -> Formatting
Try to check them and see if that works.
Before I begin, I have googled this to death and there are many posts about how to prevent the save prompt. I am having an issue showing the save prompt.
I am building the template editing portion of a document generation system in C#. The system will edit 'dot' and 'dotx' files. Before outlining the problem, the environment I am using for development is running Visual Studio 2010 and Word 2010. It will eventually run on other versions, but i would like to get these versions functional first.
To set the scene I have a form open that has a list of columns returned from a stored procedure(Data Source) to add to the document as bookmarks. I have all of the bookmark and drag/drop operations functional. When I close the application, I catch the 'ApplicationEvents4_DocumentBeforeCloseEventHandler' event to close the form.
When I close the form, i check haw many documents there are open. If only one document is open, I close the application which prompts the user to save changes. If however there are multiple documents open (Most people have a number of different word documents open concurrently), I locate the correct document and close it with the flag set to prompt the user to save changes.
This is where the problem occurs. At this point, the save changes dialog never shows up and everything freezes up in Visual Studio. If I stop the debugging on Visual Studio 2010 the document flashes in the task bar indefinitely, and if you focus on it, it disappears and saves changes without a prompt.
This is the code to handle the form closing event:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (app != null)
{
if (app.Documents.Count < 2)
{
this.TopMost = false;
((Word._Application)app).Quit();
app = null;
}
else
{
foreach (Word.Document document in app.Documents)
{
if (document.FullName.Equals(wordDoc.FullName))
{
object saveChanges = Word.WdSaveOptions.wdPromptToSaveChanges;
((Word._Document)wordDoc).Close(ref saveChanges);
break;
}
}
}
}
}
The problem is this line should show a save changes dialog:
((Word._Document)wordDoc).Close(ref saveChanges);
I have tried debugging this without much luck. Putting a breakpoint on this line and on the
break;
line allows the program to stop at the 'Close' line but when you 'step' forward or 'continue' word becomes unresponsive, so does the form and the breakpoint on the very next line never gets hit.
Any help would be greatly appreciated as something this simple is so annoying to get stuck on.
To avoid the Prompt or to get the Prompt to you have to set the Saved property to true or false respectively:
var doco = WordApp.Documents.Add();
doco.Saved = true;
doco.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges, Type.Missing, Type.Missing);
Something fishy is going on if Word hangs on the line of code when you try to close the document. I recommend disposing of all the resources properly. Here is a great article on using VSTO Contrib that helps provide this functionality:
http://jake.ginnivan.net/vsto-com-interop
Update:
Enable your VSTO log file by adding the following on your system environment variables:
NAME: VSTO_LOGALERTS
VALUE: 1
There might be an exception error that is why your add-in is not loading.
You can check this source for more info on VSTO logging and alerts, but in essence you change two environment variable values depending on what you need to do:
Displaying VSTO Alert Prompts
To display each error in a message box, set the
VSTO_SUPPRESSDISPLAYALERTS variable to 0 (zero). You can suppress the
messages by setting the variable to 1 (one).
Logging VSTO Alerts to a Log file
To write the errors to a log file, set the VSTO_LOGALERTS variable to
1 (one).
Visual Studio Tools for Office creates the log file in the folder that contains the application manifest. The default name is .manifest.log. To stop logging errors, set the variable to 0 (zero).
How to do I stop Visual Studio 2010 from expanding outlines/regions automatically?
Right now whenever I create certain syntax errors (usually while editing, sometimes just from starting to type new code), it will auto expand every outline/region below that line.
I've been through the formating settings, but I can't find anything. Maybe I don't know the proper terminology that applies to the setting.
Example code that causes this behavior(one of many):
public string myMethod1(string myStr)
{
try //<-SELECT AND DELETE ME
{ //<-AND ME TOO, AT THE SAME TIME
return myStr + "success";
}
catch
{
return myStr + "failed";
}
}
//ALL OF THESE BELOW WERE COLLAPSED,
//BUT WILL EXPAND WHEN "TRY {" IS DELETED
#region HIDING
public string myMethod2(string myStr) { /*...*/ }
public string myMethod3(string myStr) { /*...*/ }
public string myMethod4(string myStr) { /*...*/ }
public string myMethod5(string myStr) { /*...*/ }
#endregion HIDING
Thanks for any help!
EDIT:
I can force to happen by removing any starting bracket {, anywhere in my code.
This is not normal behavior. It is possible that an add-on you have installed is incorrectly doing this. You can reset your environment to the default settings by going to
Tools -> Import and Export Settings ...
choose Reset all settings
click next
save your current settings if you want to
then choose the default setting (I prefer General Development Settings because I work on lots of different things)
Click finish
Saving your current settings allows you to keep your old stuff in case you do not like what defaults you have chosen. So there is really no chance for loss of your environment setup when you do this.