Bug 14482 - C# preprocessor directives formatted incorrectly
Summary: C# preprocessor directives formatted incorrectly
Status: VERIFIED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: 4.0.12
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: master
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-09-06 12:21 UTC by alexchandel
Modified: 2016-11-25 05:35 UTC (History)
3 users (show)

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


Attachments
Xamarin Studio has incorrectly added 3 newlines here. (62.22 KB, image/png)
2013-09-06 12:21 UTC, alexchandel
Details


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:
Status:
VERIFIED FIXED

Description alexchandel 2013-09-06 12:21:47 UTC
Created attachment 4794 [details]
Xamarin Studio has incorrectly added 3 newlines here.

Description of Problem:
When and #if-#else-#endif is used at the end of a class, the formatting is broken.

A newline is arbitrarily inserted before the #endif, and every time autoformatting occurs, an additional newline is inserted.

Furthermore, if the #endif immediately precedes the class's endbrace, the endbrace is incorrectly unindented. The example below demonstrates this.

Steps to reproduce the problem:
1. Paste the following code into a new C# file, and save with autoformatting:

namespace SolarCar {
	class Test {
		#if DEBUG
		public const int Interval = 100;
		#else
		public const int Interval = 1;
		#endif
	}
}

Actual Results:
It is reformatted to this:

namespace SolarCar {
	class Test {
		#if DEBUG
		public const int Interval = 100;
		#else
		public const int Interval = 1;
		
		#endif
}
}

Expected Results:
The newline shouldn't be inserted, and the indentation shouldn't be broken.

How often does this happen? 
Every time. Note this only happens to the FIRST #if-#else-#endif construct fitting this pattern in the file.

Additional Information:
There are no options to adjust the formatting of preprocessor directives in the C# code formatting preference pane. This may be related to the formatting errors.
Comment 1 Mike Krüger 2013-09-06 12:25:12 UTC
fixed in master.
Comment 2 Mike Krüger 2013-09-06 12:25:12 UTC
fixed in master.
Comment 3 Prashant manu 2014-03-27 03:47:25 UTC
Now when we save with autoformatting, newline is not inserted and indentation is fine.

Environment Info:
Xamarin Studio
Version 4.2.4 (build 266) 
Build Information
Git revision: 57fa6b7639703775ae1d5c46536e42ab424cb177
Xamarin addins: eee141c29724a19529e77b8e743086d95b29f5ba
Mono 3.2.6
Xamarin.iOS 7.2.2.14 
Hash: 16bef0b
Xamarin.Android 4.13.0-144 (MAC)
Comment 4 PAHeartBeat 2016-11-25 05:35:32 UTC
New Xamarin 6.1.x has some issue with auto formating for C# preprocessor directives. Now each C# preprocessor directives formatted to start of line at coloumn 0 like..


#if USE_POWER
        if (powerType==NodePowerType.None) {
            sr.color = GPLogic.Me.GetColor(_score);
            _cellText.text = _score.ToString();    
        } else {
            _cellText.text = "";       
            sr.color = Color.white;
        }
#else
	UpdateCellScore ();
	sr.color = GPLogic.Me.GetNodeVisualInfo (_score).color;
#endif


Proposed formate like
=====================
public void UpdateCellColorSprite() {
	#if USE_POWER
        if (powerType==NodePowerType.None) {
            sr.color = GPLogic.Me.GetColor(_score);
            _cellText.text = _score.ToString();    
        } else {
            _cellText.text = "";       
            sr.color = Color.white;
        }
	#else
	UpdateCellScore();
	sr.color = GPLogic.Me.GetNodeVisualInfo(_score).color;
	#endif
}



this issue happens only in version later 6.x I have another versions of Xamarin (Mono) 5.9.6 which has proper working with auto format for indentation 


Issue with version:
===================
Version Detail:
Xamarin Studio Community
Version 6.2 (build 1413)
Installation UUID: 0dec0350-909e-4c7c-b4a1-483144ca32d9
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/f5fbc32) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000344

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 7.3 (10183.3)
Build 7D175

Xamarin.iOS
Not Installed

Xamarin.Mac
Not Installed

Xamarin.Android
Not Installed

Xamarin Android Player
Not Installed

Build Information
Release ID: 602001413
Git revision: 742745078826af5470848930d858e671bb825a16
Build date: 2016-11-14 18:58:31-05
Xamarin addins: b6f6ce0cf65974359966b8da408450221780f711
Build lane: monodevelop-lion-cycle9

Operating System
Mac OS X 10.11.6
Darwin IND635.local 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64