Bug 25602 - "Automatic" Indentation adds or removes Tabs!
Summary: "Automatic" Indentation adds or removes Tabs!
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: 5.5
Hardware: All All
: Normal normal
Target Milestone: master
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2014-12-23 20:23 UTC by zezba9000
Modified: 2015-01-08 04:43 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description zezba9000 2014-12-23 20:23:01 UTC
Hi I have a bug thats been in Xamarin Studios 5.x + thats been around for a very long time now.
I don't think it existed in 4.0.x and does not exist in Unity3Ds version of MonoDevelop.
This bug has existed for at least 6 months on both OSX and Windows (not sure about Linux).

I write a lot of Unity3D plugin code that uses "Compiler Directives" in many areas throughout the projects. This is about the most annoying thing ever. I also run into this bug on any code project that uses any code complexity. iOS, Android, OSX, Windows ect ect... platform or .NET version doesn't matter.

NOTE: Make sure you set "Automatic" formatting settings in XamarinStudios under "Preferences->Text Editor->Behavior".
On this basic console example i'm running into it not adding a tab if: (NOTE: it will start to break everywhere once the project gets bigger)
1) Set your cursor to the end of the line "// Some test code here bla baaa..."
2) Then hit return and will not add the tab.
Here is the code you can copy in a Console app: http://pastebin.com/EnJtY0rZ

using System;

#if DEBUG
namespace TestBadFormating
#endif
{
    // Some test code here bla baaa...
    class MainClass
    {
        #if DEBUG2
        public static void Main (string[] args)
        #else
        public static void Main (string[] args)
        #endif
        {
            int i = 0;
            Console.WriteLine ("Hello World!");
            if (0 == 0)
            {
                Console.Write("Hello World!");
            }
            #if WP8
            else if (i == 123)
            {

            }
            #endif
            else
            {
                try
                {
                    int i2 = i;
                    throw new Exception("Blaa");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
    }
}
Comment 1 Ram Chandra 2014-12-29 12:31:41 UTC
I have checked this issue and I am able to reproduce the reported behavior.

When I set the "Indentation Mode" to "Automatic" and hit the return key after following statement I observed that XS removes the tab. I am getting the same behavior when I set the "Indentation Mode" to "None"

Screencast: http://www.screencast.com/t/7vgzQsimru

I’ll need confirmation from the developer if this is a bug. Leaving as NEW for now.

Environment Info:

Mac OS X 10.10.0
Xamarin Studio : 5.5.4 (build 15)
Mono 3.10.0 ((detached/92c4884)
GTK+ 2.24.23 (Raleigh theme)
Package version: 310000031

=== Build Information ===
Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8
Comment 2 Mike Krüger 2015-01-05 06:55:06 UTC
fixed in 5.8.0.143

btw. we're discussing about removing that feature at all and only support one way of indenting. 

Why are you using automatic indent ?
Comment 3 zezba9000 2015-01-05 19:02:09 UTC
"Why are you using automatic indent ?"
-- Because I hate the IDE formatting my code in a way that doesn't fit the code block  correctly in particular contexts.  One size does not fit all.

NOTE: This bug also effects "Smart" mode as well.  Try to copy and paste code around in a larger project that makes heavy use of compiler directives and you will see this behavior (and its almost worse).

If you need a project that replicates this behavior I might be able to come up with something...?
Comment 4 Mike Krüger 2015-01-06 02:55:21 UTC
I couldn't repro that with smart mode. If you've failing smart mode indentation I'm interested in these use cases.
Comment 5 Mike Krüger 2015-01-07 02:54:17 UTC
btw. that bug has been fixed. If you find smart indentation bugs please file a new one otherwise it's hard to track these issues.
Comment 6 zezba9000 2015-01-07 03:23:18 UTC
Ok here is a repo case for both "Indent" AND "Smart" modes.
Dropbox link: https://www.dropbox.com/s/5zk1lzyg2gq0yh5/WaterTest.zip?dl=0

Its a Unity3D project Water simulation.  You don't need Unity3D to test this though as the CS project is included.

Directions to repo (Tested on OSX 10.10, XamarianStudios 5.5.4):
1) Download and extract the zip file.
2) Open to "WaterTest-csharp.sln".
3) In the "Assembly-CSharp-vs" project, open the file "Water.cs".
4) In "Indent" mode, copy line #11.
5) Hit return to add a new line after and paste the code you copied.
5.5) Notice how it adds and extra tab.
6) Undo what you just did.
7) In "Smart" mode, set your carrot to the end of line #11.
8) Hit return and will notice an extra tab is added.

Are you able to repo with your build?
I will make a new case for "Smart" mode.
Comment 7 zezba9000 2015-01-07 03:24:52 UTC
Also NOTE: The MonoDevelop version that comes with Unity does not have this issue.  Thats version 4.0.1
Comment 8 Mike Krüger 2015-01-07 03:36:59 UTC
It's a weird project setting.

The indentation is set to 8. Open the solution options

source code->code formatting->text

tab is set to 4 and indent is set to 8. That's why 2 tabs get inserted to get to the indent level. Set both values to the same and it'll work.
Comment 9 zezba9000 2015-01-07 03:49:08 UTC
"tab is set to 4 and indent is set to 8."
-- But the project setting is set to "Inherited Policy".  This means it should ignore that setting?  So still looks like a bug to me just in a different area.  Probably some if statement is out of wack or was removed.
Comment 10 zezba9000 2015-01-07 03:50:17 UTC
EDIT: This means it should ignore that project setting and use the global one from preferences thats set correctly to 4 by 4?
Comment 11 Mike Krüger 2015-01-07 07:02:37 UTC
It's defined in the solution.
Settings are layered

global -> solution -> project

and if project inherits it takes the solution settings if that's set to inherit it takes the global ones. In that solution the setting is set on solution level.
Comment 12 zezba9000 2015-01-07 18:16:20 UTC
Why is there no "Inherited Policy" for SLN files in XamarianStudios?
So now I can't use global settings unless I create a new solution... thats silly.  I might look into adding that myself later if I have time.
Comment 13 Mike Krüger 2015-01-08 04:43:35 UTC
This is a good question - I didn't change that :(.

I always thought that we have that at this level. It may make sense because that prevents that a solution opened with different global settings behaves the same.