Bug 39664 - Auto-formatting forces multi-line formatting
Summary: Auto-formatting forces multi-line formatting
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: 6.0.0 (C7)
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Mike Krüger
: 39586 ()
Depends on:
Reported: 2016-03-15 19:48 UTC by Cody Beyer (MSFT)
Modified: 2017-07-18 11:27 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Cody Beyer (MSFT) 2016-03-15 19:48:46 UTC
# Description

Attempting to insert a method upon a single line will result in auto-formatting that forces multiline methods

The expected behavior is how Visual Studio operates in this circumstance

# Video


# Steps to Reproduce

1. Create a console project
2. Attempt to create a new method in a single line

# Expected Results

Single line formatting should be respected

# Actual Results

Auto formatting breaks up the lines

# Versions

=== Xamarin Studio ===

Version 6.0 (build 4761)
Installation UUID: 3c5a3580-d902-45db-8f94-df4e19aba44a
	Mono 4.3.2 (mono-4.3.2-branch/ba2e5e4) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 403020467

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.2.1 (9548.1)
Build 7C1002

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 58ba2bc
Branch: master
Build date: 2016-03-03 09:05:19-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 600004761
Git revision: 6913a43555e7434103860008ffa7d913d22819a7
Build date: 2016-03-08 15:54:12-05
Xamarin addins: 866256c8c5c8db3a07af37b579375505d5d88729
Build lane: monodevelop-lion-cycle7

=== Operating System ===

Mac OS X 10.11.3
Darwin clb-macbook-pro.local 15.3.0 Darwin Kernel Version 15.3.0
	Thu Dec 10 18:40:58 PST 2015
	root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Comment 1 Mike Krüger 2016-03-16 06:20:48 UTC
Looks like a roslyn bug. I recommend to turn on auto brace insertion - that fixes that.
Comment 2 Mike Krüger 2016-03-17 08:21:13 UTC
*** Bug 39586 has been marked as a duplicate of this bug. ***
Comment 3 Mike Krüger 2016-03-17 08:24:20 UTC
Fixing that requires internal access - it's off the limits of what I can fix with reflection. I need to implement a custom formatting rule (internal interface/base class) and give that to an internal API.

Moving to C8 - a quick fix would be the auto brace insertion - in that case the formatter doesn't force a new line there.
Comment 4 Mike Krüger 2016-06-13 06:15:46 UTC
*** Bug 41742 has been marked as a duplicate of this bug. ***
Comment 5 Roy Leban 2016-06-13 07:06:38 UTC
The bug I reported (41742) was marked as a duplicate of this bug, but the symptoms are different. This bug talks about multi-line being forced, I'm seeing a newline being removed. Adding this comment to make sure what I reported is not lost.

Reproduced in 6.0 with C# and on-the-fly code formatting turned on.

Steps to reproduce the problem:
1. Use Visual Studio style for C# where { is on the next line and lines up with }
2. Type something with { } like an if (...) <return> { <return> }
3. When you type the } the { will move up to the line of the if statement rather than staying on the line below

Proper formatting should be:
    void f()

Actual formatting is:
    void f() {

The { moves up a line when you type the } even if you start a new line before typing the {.

The only workaround I found was to turn OFF on-the-fly formatting, but I also didn't look very hard for anything else.

I also speculated that bug 34356 might be related even though there are no #if statements here.
Comment 6 Mike Krüger 2016-06-13 07:38:26 UTC
Ok I can't reproduce that - only that newlines are added.

Can you give me a repro case or screencast ?
Comment 7 Mike Krüger 2016-06-13 07:43:28 UTC
I'll handle 41742 as a different case.
Comment 9 Mike Krüger 2017-07-18 11:27:43 UTC
Good news - that bug got fixed at some point.

We now use the internal formatting API which is less intrusive.

Works in master.