[C++] I wrote a visual studio extension to fix the annoying smart indenting issues around UE4 macros

tried this plugin followed everything but when i click edit> format document it indents itself. is it really like this?

What’s about such command? It fixes current doc after format by replacing >1 indents with exactly 1 on the specifier line and next if empty after macro ignoring access modifiers.

using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;

public class C : VisualCommanderExt.ICommand
    private static readonly string MACRO_REGEX = @"^(?<leading_whitespace>\s]*)(UPROPERTY|UFUNCTION|GENERATED_(USTRUCT_|UCLASS_|(U|I)INTERFACE_)?BODY)\(.*\)\s*(?<body>\S]*).*";
    private static readonly string ACCESS_MODIFIER = @"^.*(public|private|protected)\:.*";

    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
        string macroLine;
        string indent = "";
        bool fixNext = false;
        TextSelection sel = (TextSelection)DTE.ActiveDocument.Selection;
        var editPoint = sel.ActivePoint.CreateEditPoint();
        var lineNum = editPoint.Line;
        var macroLineNum = 0;

        while (++macroLineNum <= lineNum) {
            macroLine = editPoint.GetLines(macroLineNum, macroLineNum+1);
            if (fixNext) {
                var modMatch=Regex.Match(macroLine, ACCESS_MODIFIER);
                if (!modMatch.Success && indent != "") sel.Indent();
                fixNext = false;
            var macroMatch=Regex.Match(macroLine, MACRO_REGEX);
            if (macroMatch.Success) {
                indent = macroMatch.Groups"leading_whitespace"].ToString();
                if (indent != "") sel.Indent();
                fixNext = (macroMatch.Groups"body"].ToString() == "");

Not working on VS2017, I guess. :frowning:

Can confirm it doesn’t work in VS2017

Thank you!

Works great for VS2017, those who said it didn’t probably didn’t follow the instructions.
Thank you!

I definitely followed the instructions, and it is not working in VS2017 for me either.

OMG thanks!
You are my hero!

Please update for VS 2019

Just logging in to say thank you.
Haven’t really used it much yet but this should help quite a bit.

This doesnt compile anymore since a new visual commander update: