制作' Code Jumper'扩展(源代码)与Vb.Net Modules

时间:2016-04-02 10:33:47

标签: c# .net vb.net visual-studio-extensions visual-studio-sdk

SCENARIO

Code Jumper Visual Studio 的节省时间的扩展/插件,它添加了一种导航面板,可以轻松地在代码成员之间跳转单击一下。

对于大型API,它非常有用,因为它可以避免滚动数千行,打开#regions,隐藏Xml文档,搜索方法或成员名称等等...它是必须的扩展,因为它真的可以节省很多时间:

enter image description here

问题

Code Jumper 对我的需求有一个大问题,无论产品说明中有什么说明,它都无法解析Vb.Net模块,因为现实是它可以&#39 ;(由C#家伙写的所以也许他不知道模块的存在......)

打开模块时,代码跳线的窗口为空,显示任何成员。

问题

Here Code Jumper 的可下载源代码,用C#编写。

我需要做些哪些修改才能使其与Vb.Net模块一起使用?

可选问题

有人知道与 Code Jumper 相似且更好的扩展名吗?

研究

我认为这是DocumentParser.cs文件中最相关的代码:

public void RecurseCodeElements(CodeElements elements, CodeElementAggregate aggregate) {

    if (elements == null)
        return;
    _recurseCount++;

    if (_recurseCount % 2 == 0) {
        if (ParserProgress != null)
            _appConfig.elementView.Dispatcher.BeginInvoke((Action)(() => ParserProgress(this)));
    }

    foreach (CodeElement element in elements) {

        System.Threading.Thread.Sleep(10);

        if (element.Kind == vsCMElement.vsCMElementClass) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementInterface) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementStruct) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementNamespace) {
            RecurseCodeElements(GetMembers(element), aggregate);
        }

        if (element.Kind == vsCMElement.vsCMElementEnum) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementFunction ||
            element.Kind == vsCMElement.vsCMElementProperty ||
            element.Kind == vsCMElement.vsCMElementVariable ||
            element.Kind == vsCMElement.vsCMElementDelegate ||
            element.Kind == vsCMElement.vsCMElementEvent)
        {
            var func = element as CodeFunction;
            aggregate.Add(element);
        }
    }
}

private CodeElements GetMembers(CodeElement element) {

    if (element == null)
        return null;

    if (element.Kind == vsCMElement.vsCMElementNamespace) {
        return (element as CodeNamespace).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementClass) {
        return (element as CodeClass).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementInterface) {
        return (element as CodeInterface).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementEnum) {
        return (element as CodeEnum).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementStruct) {
        return (element as CodeStruct).Members;
    }
    return null;
}

我尝试为 vsCMElement.vsCMElementModule 添加其他条件,但是,它仍然无法正常工作,我不确定我是否会这样做在正确的方向:

public void RecurseCodeElements(CodeElements elements, CodeElementAggregate aggregate) {

    if (elements == null)
        return;
    _recurseCount++;

    if (_recurseCount % 2 == 0) {
        if (ParserProgress != null)
            _appConfig.elementView.Dispatcher.BeginInvoke((Action)(() => ParserProgress(this)));
    }

    foreach (CodeElement element in elements) {

        System.Threading.Thread.Sleep(10);

        if (element.Kind == vsCMElement.vsCMElementClass) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementModule) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementInterface) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementStruct) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementNamespace) {
            RecurseCodeElements(GetMembers(element), aggregate);
        }

        if (element.Kind == vsCMElement.vsCMElementEnum) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }

        if (element.Kind == vsCMElement.vsCMElementFunction ||
            element.Kind == vsCMElement.vsCMElementProperty ||
            element.Kind == vsCMElement.vsCMElementVariable ||
            element.Kind == vsCMElement.vsCMElementDelegate ||
            element.Kind == vsCMElement.vsCMElementEvent)
        {
            var func = element as CodeFunction;
            aggregate.Add(element);
        }
    }
}

private CodeElements GetMembers(CodeElement element) {

    if (element == null)
        return null;

    if (element.Kind == vsCMElement.vsCMElementNamespace) {
        return (element as CodeNamespace).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementModule) {
        return (element as CodeClass).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementClass) {
        return (element as CodeClass).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementInterface) {
        return (element as CodeInterface).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementEnum) {
        return (element as CodeEnum).Members;
    }

    if (element.Kind == vsCMElement.vsCMElementStruct) {
        return (element as CodeStruct).Members;
    }
    return null;
}

1 个答案:

答案 0 :(得分:1)

我无法进行编译,但如果你查看CodeElementType.Class的所有参考文献,几乎所有参考文献都必须是#34;重复的"使用CodeElementType.Module,尤其是IsStackableElement,可能会回答您的问题。

解释所需修改的部分代码:

public void RecurseCodeElements(CodeElements elements, CodeElementAggregate aggregate) {
    // ...
    foreach (CodeElement element in elements) {
        // ...
        if (element.Kind == vsCMElement.vsCMElementModule) {
            RecurseCodeElements(GetMembers(element), aggregate.Add(element));
        }
        // ...
    }
}

private CodeElements GetMembers(CodeElement element) {
    // ...
    if (element.Kind == vsCMElement.vsCMElementModule) {
        return (element as CodeClass).Members;
    }
    // ...
}
public bool IsStackableElement {
    get
    {
        if (IsRoot) 
            // ...
            return (ElementType == CodeElementType.Class || ElementType == CodeElementType.Module || ... )
            // ...
    }
}

public static CodeElementType GetElementType(CodeElement element) {
    switch (element.Kind) {
        // ...
        case vsCMElement.vsCMElementModule:
            return CodeElementType.Module;
        // ...
    }
}

public void Draw() {
    // ...
    if (ElementType == CodeElementType.Module) {
        _elementStackPanel.Background = _appConfig.ClassBackgroundBrush;
    }
    // ...
}

public void Update() {
    // ...
    if (ElementType == CodeElementType.Module)
    {
        ElementLabel.AddExpander(_elementStackPanel);
        ElementLabel.AddPictureToSingleGrid(ElementInfo.ElementImage);
        ElementLabel.AddPictureToSingleGrid(ElementInfo.Accessibility.AccessibilityImage);
        ElementLabel.AddText(ElementInfo.Name, _appConfig.ClassTextBrush, _appConfig.HyperlinkTextImageSpacer, FontWeights.Bold);
    }
    // ...
}

private bool GetElementInfo() {
    // ...
    if (ElementInfo.ElementType == CodeElementType.Module) {
        ElementInfo.ElementImage = _appConfig.GetImage("staticclass");
    }
    // ...
}

private void ParseCodeElement() {
    // ...
    if (ElementInfo.ElementType == CodeElementType.Module)
    {
        ElementInfo.IsStackable = true;
        var codeClass = (CodeClass)Original;
        var codeClass2 = (CodeClass2)Original;
        ElementInfo.Accessibility = new AccessibilityContainer(_appConfig, codeClass.Access);
        ElementInfo.IsStatic = true;
    }
    // ...
}