Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code analyzer to check the type passed to ProvideOptionDialogPageAttribute and ProvideProfileAttribute #284

Merged

Conversation

reduckted
Copy link
Contributor

Related to #279.

Using the wrong type in ProvideOptionPageAttribute seemed like a good candidate for a code analyzer to catch the problem early and to suggest a fix (where possible).

CVST003 will detect the wrong type being provided to ProvideLanguageEditorOptionPageAttribute, ProvideOptionPageAttribute and ProvideToolboxPageAttribute (they all expect a DialogPage)

CVST004 will detect the wrong type being provided to ProvideProfileAttribute (it expects an IProfileManager, which DialogPage implements).

Both diagnostics have a code fix that will suggest changing the type to a type that is nested within the type nested type that inherits/implements the correct type. For example, give this:

internal partial class OptionsProvider
{
    [ComVisible(true)]
    public class GeneralOptions : BaseOptionPage<General> { }

    [ComVisible(true)]
    public class OtherOptions : BaseOptionPage<Other> { }
}

and providing an options page like this:

[ProvideOptionPage(typeof(OptionsProvider), nameof(TestExtension), "General", 0, 0, true)]

The code fix will suggest:

  • Changing typeof(OptionsProvider) to typeof(OptionsProvider.GeneralOptions)
  • Changing typeof(OptionsProvider) to typeof(OptionsProvider.OtherOptions)

Demo:
code-fix

…ogPageAttribute and ProvideProfileAttribute.
@ErikEJ
Copy link

ErikEJ commented Jan 26, 2022

Sweet!

@madskristensen madskristensen merged commit e2d88dd into VsixCommunity:master Jan 26, 2022
@madskristensen
Copy link
Contributor

That's awesome. Thank you

@reduckted reduckted deleted the feature/options-page-analyzer branch January 26, 2022 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants