Water editor try/finally block default formatting

hydrogene

(Chris) #1

In Water C# code, when the file is reformatted (Edit -> Reformat File), I think the finally blocks are indented incorrectly (at least different than the catch blocks).

This is what I get after a reformat:

            try
            {
                
            }
            catch(Exception e)
            {
                
            }
            
            try
            {
                
            }
            finally
                {
                
                }

(marc hoffman) #2

Does that happen in any context? or can you give me a complete file as tetscase? thanx!


(RemObjects) #3

Thanks, logged as bugs://81437


(Chris) #4

Yes, seems to happen in any context. The indenting happens correctly initially while typing and adding the curly braces, but if something signals a reformat, or if you choose it from the edit menu, the finally curlys get indented more.

Water test case:

File -> New Project -> Echos -> Winforms

Then modify Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace WindowsApplication
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += OnThreadException;
            using (MainForm lMainForm = new MainForm())
            {
                Application.Run(lMainForm);
            }
            
            try
            {
                // try something
            }
            catch (Exception e)
            {
                // oops
            }
            
            try
            {
                // do something else
            }
            finally
            {
                // done with something else
            }
            
        }

        void OnThreadException(Object sender, ThreadExceptionEventArgs e)
        {
            System.Windows.Forms.MessageBox.Show(e.Exception.Message);
        }
    }
}

Then go to Edit -> Reformat File, and you will get this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace WindowsApplication
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += OnThreadException;
            using (MainForm lMainForm = new MainForm())
            {
                Application.Run(lMainForm);
            }
            
            try
            {
                // try something
            }
            catch (Exception e)
            {
                // oops
            }
            
            try
            {
                // do something else
            }
            finally
                {
                    // done with something else
                }
            
        }

        void OnThreadException(Object sender, ThreadExceptionEventArgs e)
        {
            System.Windows.Forms.MessageBox.Show(e.Exception.Message);
        }
    }
}

(marc hoffman) #5

glad the editing part is fine, coz that’s my code in water ;). the reformat is done my the manager project system, and that’s out of my hand to fix or worry about ;).

ps: some new editor features in 2345. let me know what you think!


(Chris) #6

I can’t seem to figure out what the new features are. Hints please?


(marc hoffman) #7

for example, type “if”.


(Chris) #8

Nice!!!


(viktoriad) #9

Hello,
I couldn’t reproduce the problem with reformatting here. Two weeks ago I had that bug logged, and I fixed it on Nov 9. So if you have the earlier build, could you please download latest and check with it. If you’ve got recent up-to-date elements, please give me some video on how you are reproducing the problem.
Thanks in advance.


(Chris) #10

Hi,

In the latest build it isn’t happening with just comments inside the finally block, so you probably aren’t seeing the problem there.

Try following the steps in my original post, but paste this in instead:

            try
            {
                Application.Run();
            }
            catch (Exception e)
            {
                Application.Run();
            }
            
            try
            {
                Application.Run();
            }
            finally
            {
                Application.Run();
            }

After going to Edit -> Reformat File the final curly brace will indent itself too far. Curiously enough, the first curly brace in the finally block stays put now.

Let me know if that doesn’t show the problem for you and I will try to figure out how to do a video of some sort.


(viktoriad) #11

Yes, reproduced with your testcase now.
Thanks.


(RemObjects) #12

bugs://81437 got closed with status fixed.