How to stop VisualStudio from expanding everything while removing {} brackets

I asked this question a few days ago and did not receive an answer, so I will try again to clarify it a bit.

I like it when my code is collapsed using collapsed methods, comments, and xml summaries, which I am not currently using. However, every time I edit some curly braces in a method, loop, switch statement, or any part of the code (anything containing a { or } parenthesis), everything below is revealed after 1 second. Everything expands to the end of the current file (or region, if the edited code lies inside it).

I can't take it anymore. I was tired of using Ctrl + M + O all the time, and then re-edited the field again. Is there any option or extension for VS2010 that would solve my problem?

Update I am starting to realize that there is no way to solve the problem. However, I could also accept the answer to the amended question: Is there a way or tool that would allow me to automatically delete pairs { and } containing only 1 instruction? . This would be an acceptable workaround for my problem.

+7
c # visual-studio refactoring
source share
5 answers

I use falsification for a static class containing localization text, and it's pretty nice to be able to hide / show things, just like TreeView does with nodes:

Static strings

And I never encountered the described problem or was not annoyed by what VS does.

However, when you edit the code, this behavior is too much for Intellisense I think (as already described in another answer). Perhaps you should change your "way of thinking"?

Take a look:

Members list

You can quickly move between members or have a brief overview of them using this special window, with all the code deployed.

I have seen people like #region . But you can achieve the same (if not better in all dimensions) by using partial and breaking one class into pieces.

ps: and with the last question, why don't you just select what you need to delete first and then click Delete ? Or what will this tool do for you? Automatically browse sources, detect and delete? If you are a programmer, then creating software that will do this should not take more than writing a question here = D

+1
source share

If I understand what you need, you ask how to stop the code below the line that I am editing from automatically expanding. , I would like to say that there is no solution either from official sources or because of anything. The codec collapses with the idea of ​​ideal code editors such as Visual Studio.

Let me explain to you why this is happening and how to prevent it. First, let me explain the basic conditions for collapsing code to work. Code code editors use Lexers and Parsers to support the language, parsers use regular expressions for the syntax of the corresponding language, entered by the Coder or someone else, in this sequence code editor stores all locations where characters such as ; , { and } , " .

For the collapse of the code to work effectively, there must be an equal number of characters specified in the exact order in the editable code, whenever there is something in the source code that does not correspond to the syntax of the language, the parser flags inform about the editing and formatting of this error.

Returning to your problem, let's talk about what you are faced with, in order to better understand it, consider a simple block of code;

Code Collapsing works perfectly upto this point

and consider that there are a few more functions below AddNumbers that are also reset. Now, if I understand you, then you said that if I edit MultiplyNumbers and remove its starting curly brace {`, then all the code below this point will automatically expand.

Misplaced starting curly brace

If so, the problem is that the parser is trying to match the syntax of the language and is looking for any trailing braces under this dot that are in AddNumbers's trailing braces.

Update:

There is no solution to this problem in one line, this is due to the fact that Visual Studio performs parsing in real time, as it shows you errors in real time. In fact, this is not a problem, why it was never reported because of which nothing is available from official sources. However, you can prevent this by changing the coding habits a bit, for example, when you create a function, suppose SomeFunction (int a, int b) tries to complete the outer side of the function first, as shown below;

 private void SomeFunction(int a,int b) { //Write code later. } 

First create a function outline, as described above, and then write the code in it, as shown below:

 private void SomeFunction(int a,int b) { int z=a+b; Console.WriteLine(z); int x=a*b; Console.WriteLine(x); int p=a/b; Console.WriteLine(p); int q=ab; Console.WriteLine(q); } 

Next, consider what you write if statement , first fill out the outside as follows:

 if(//We'll define condition later) { //Write function body later. } 

If you used code snippets in Visual Studio, you may have noticed that Visual Studio first creates the outer side of snipett, and then puts the caret in the first argument.

So, these are some recommendations that can prevent the problem.

Now move on to the solution, to prevent this situation when you create a function try to first place its { and } braces before writing any code in it.

Hope this will prevent the problem you are having. If you have anything else, please let me know.

+3
source share

I don’t know exactly what the problem is, because it certainly does not look like normal behavior (I have never experienced this).

There are several options though (not knowing more about the problem) that may help you.

First, someone gave a very good answer to another thread about setting up a visual studio intellisense: Custom Intellisense Extension

If this is not an option, perhaps check out the extensions that are provided for Visual Studio 2010.

Performance Power Tools can help you with some of your refactoring. You can get this through Visual Studio by choosing Tools - Extension Mananger. Then select an option and install it. Power tools are quite limited, so this may not be enough. I'm sure people can offer other alternatives, but I would definitely recommend ReSharper: http://www.jetbrains.com/resharper/ . You can get a free trial, but after that you will have to pay for it. I use it, and the extensions it provides are fantastic. You can completely change the way Visual Studio behaves for your personal preferences.

Sorry, I can not offer any other help, but if you can provide additional information, then maybe we can find a solution (for example, what do you mean by other ways to expand, etc.).

0
source share

Well, this problem you are facing is universal, and sometimes it can be annoying. In my experience, the visual studio works with haywire, especially when you write many block statements in a large code file, whenever this happens, you can save your work and restart VS. But to answer your question, make sure that you first try to open any minimized code that you want to edit, and also for copying / cutting, first try highlighting the minimized code before executing the editing parameters, which informs the editor that you want to edit the selected code segment. Hope this helps.

0
source share

vs options

Maybe this can help?

0
source share

All Articles