Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave block on single line formatting ineffective without brace completion (regression) #2837

Closed
miloush opened this issue May 17, 2015 · 15 comments · Fixed by #4644
Closed
Assignees
Milestone

Comments

@miloush
Copy link

miloush commented May 17, 2015

Settings to reproduce:
C# > Formatting > Wrapping > Leave block on single line on (on by default)
C# > Automatic brace completion off (newly on by default)

namespace ConsoleApplication1
{
    class Program
    {
        static bool Property
        {
            get { return true|
    }
}

If semicolon is typed at this point, the formatter decides to reformat the block:

            get {
                return true;

Likely because it thinks the next closing bracket belongs to the getter which it does not. This parsing strategy (exhibited in other contexts, too) makes the leave block on single line setting ineffective, and the issue is hit very often during typing and is time consuming to fix.

This was not a problem in previous version of Visual Studio (without brace completion).

@Pilchie
Copy link
Member

Pilchie commented May 18, 2015

@miloush
Copy link
Author

miloush commented May 18, 2015

Oh yes, I knew I filed it somewhere, but was unable to find it! And given the VS is in RC and I am hitting it every day, I thought it might be worth mentioning it at GitHub.

@mattwar
Copy link
Contributor

mattwar commented May 27, 2015

This is exactly what @miloush claims. We go ahead and format the line on the typing of the ';' key, and the formatting engine has a rule that keeps the block on the same line if it is already on the same line, except is sees it as broken across two lines because the matching brace is on the next line (according to the parser). The reason this worked in prior VS was that we did not do any formatting after the semi-colon key if there were parse errors.

Still investigating possible solutions.

@miloush
Copy link
Author

miloush commented May 28, 2015

Not attempting to do formatting in the presence of parse errors sounds quite reasonable to me. In general I have to say that the IDE now feels rather aggressive (and the written code less 'stable') whenever there are parse errors.

@DustinCampbell DustinCampbell modified the milestones: 1.1, 1.0 (stable) Jun 8, 2015
@ygoe
Copy link

ygoe commented Aug 7, 2015

Not attempting to do formatting in the presence of parse errors sounds quite reasonable to me.

I'd second this. I see invalid reformatting all over the place while editing code now. The editor can't wait until I'm done and constantly pushes things around in the wrong direction. If you don't want to disable this new "ability" completely, can there be at least an option in "Text editor; C#; Formatting; General"?

@ygoe
Copy link

ygoe commented Aug 10, 2015

I noticed another weird behaviour of the VS 2015 editor. When pasting a line with #if something then all following #region ... and #endregion lines in the document are moved from their current indentation to the first column. Is this the same bug?

@Pilchie
Copy link
Member

Pilchie commented Aug 10, 2015

Actually, that looks like #2487.

@Pilchie Pilchie assigned CyrusNajmabadi and unassigned mattwar Aug 18, 2015
@Pilchie
Copy link
Member

Pilchie commented Aug 18, 2015

@CyrusNajmabadi is going to think about this for a while

@Pilchie
Copy link
Member

Pilchie commented Aug 26, 2015

Fixed by #4644

@Pilchie Pilchie closed this as completed Aug 26, 2015
@miloush
Copy link
Author

miloush commented Nov 4, 2015

Running Update 1 RC (24627) and it seems just the example above has been hotfixed. It still messes with e.g.:

namespace ConsoleApplication1
{
    class Program
    {
        public static bool One { get|

        static void Main(string[] args)
        {
        }
    }
}

and wraps it:

        public static bool One {
            get;

The same with:

public static void Test() { return|

I still think it is a good idea to avoid formatting (at least automatic) if there are parse errors.

If it helps, I have noticed that if you cancel the autocomplete suggestions of get/return it does not do it.

@Pilchie
Copy link
Member

Pilchie commented Dec 3, 2015

Hmm - the fact that it only happens if autocomplete is up means this is actually a different issue. Can you file something new to track it?

@miloush
Copy link
Author

miloush commented Feb 29, 2016

Running Update 2 CTP (25008) and still,

try { }
catch { continue|

gets wrapped as

try { }
catch {
    continue;

Is that a different issue? This one is not triggered by autocomplete.

@CyrusNajmabadi
Copy link
Member

This is a different issue.

@miloush
Copy link
Author

miloush commented Feb 29, 2016

OK, is that being tracked or should I create it?

@CyrusNajmabadi
Copy link
Member

You shoudl create it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants