oleg-shilo / PyMap.VSIX

CodeMap extension for Visual Studio 2017-2022
18 stars 3 forks source link

Exceptions thrown with regions in certain layouts #11

Closed rd-pck closed 1 year ago

rd-pck commented 1 year ago

I'm encountering an ArgumentNullException showing messages in the CodeMap window in red text whenever a file has an enum followed by a region. Additionally, a NullReferenceException when an enum is followed by a region. No stacktrace is visible. No related messages can be found in the Activity Log.

I am able to repeat this in a fresh VS2022 experimental instance with no other extensions, with the following "minimal" file content:

using System;

namespace ConsoleApp1
{
    public static class Program
    {
        static void Main(string[] args) { }
    }

    public enum SomeOtherEnum
    {
        Empty = 0,
        SomethingId = 1
    }

    #region someregion

    public delegate void SomethingDelegate(int par);

    #endregion
}

This throws an ArgumentNullException with Parameter name: source.

I am also able to repeat the NullReferenceException, when an enum is followed by a region:

namespace ConsoleApp1
{
    public enum SomethingEnum
    {
        None = 0,
    }

    #region morestuff

    public delegate void SomethingHandler();

    #endregion morestuff
}

Files that are laid out like this will throw these exceptions regardless of what is added between the offending components. This is especially problematic with large, disorganized legacy code.

This issue did not occur in v2.1.2, prior to region support.

oleg-shilo commented 1 year ago

Yes, it is an unfortunate mistake in the region support implementation. Please update the extension. I just published the fix: v2.1.5.0.

rd-pck commented 1 year ago

Version 2.1.5.0 fixes this, thank you.

oleg-shilo commented 1 year ago

You probably noticed that now when you navigate from the tree the text editor highlights the corresponding line so the user can better see it.