Posted 3 years ago by William Cutler - CNC Software Inc.
Version: 21.1.2
Avatar

Hello Actipro,

I am looking to customize the Syntax editor component for C# scripting but am not seeing how to customize the outlining behavior. Right now, using the default CSharpOutlining that comes with the Syntax editor, it provides outlining for using statements, class definitions (and interfaces, etc.), and method definitions within those classes. However, we are hoping to have outlining behavior more like in visual studio. For the code sample below, Visual Studio outlines the 'if' statement, the 'for' loop, and the property assignment for 'MyObj'. Additionally, because our editor will be used for scripting, we would like to enable outlining of methods that are not defined within a class. (If images would help, please let me know, I am just unsure how to upload them to this forum).

namespace Scratch
{
    public class MyObj
    {
        public int Number;
        public string Str;
    }

    public class App
    {
        static void Main(string[] args)
        {
            if (true) // Collapse here in VS
            {
                for (int i = 0; i < 10; i++) // Collapse here in VS
                {
                    var x = new MyObj
                    {
                        Number = 5,
                        Str = "Hello"
                    };
                }
            }
        }
    }
}

I would like to customize the default CSharpOutliner that comes with the syntax editor to outline these additional categories ("if", "for", object creation) in addition to enabling outlining for code outside of classes. I have looked into the CSharpOutliner and the CSharpOutliningSource and their accompanying documentation but am not seeing how to customize this. Any help is much appreciated. Thanks!

- William

Comments (3)

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi William,

At the current time, the .NET Languages Add-on supports C# 7.3 syntax.  Support for C# 8.0 syntax will be coming in v21.2.  However top-level statements (which it sounds like you may be referencing in your description) won't yet be available there since those were added in C# 9.0.  C# 9.0 is on the TODO list for future implementation.

As for adding more extensive outlining, we will try and add that for the next major version.  Right now CSharpOutliningSource is programmed to stop at member bodies and not recurse deeper.  We'll try and add an option (defaulting true) for whether to dive into code-level constructs as well for code outlining.

If you want this feature immediately, you'd have to clone CSharpOutliningSource's code and update it to support recursion into more AST node types, then add outlining nodes for things like BlockStatement.  CSharpOutliner would also need to be cloned and updated to create and use an instance of your cloned CSharpOutliningSource class.  If your company has a Blueprint source code license of the add-on, you could see how it's implemented right now to determine how to clone it.


Actipro Software Support

Posted 3 years ago by William Cutler - CNC Software Inc.
Avatar

I appreciate the quick reply - I'll look into our options moving forward. Thanks!

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi William,

As an update to this thread, we expect to launch C# 9.0 support, including top-level statements, for the SyntaxEditor .NET Languages Add-on in v24.1.


Actipro Software Support

The latest build of this product (v24.1.1) was released 21 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.