Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/VisualStudio/Core/Def/ID.RoslynCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class RoslynCommands
public const int SetSeverityHidden = 0x0113;
public const int SetSeverityNone = 0x0114;
public const int OpenDiagnosticHelpLink = 0x0116;
public const int SetActiveRuleSet = 0x0118;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason 15 and 17 were skipped?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x0115 and 0x0117 are IDs for menu groups. They're used in the .vsct file to put the menu items in the right places, but the language services don't make use of them.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
{
internal static class IVsHierarchyExtensions
{
public static bool TryGetProperty<T>(this IVsHierarchy hierarchy, int propertyId, out T value)
public static bool TryGetItemProperty<T>(this IVsHierarchy hierarchy, uint itemId, int propertyId, out T value)
{
object property;
if (ErrorHandler.Failed(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, propertyId, out property)) ||
if (ErrorHandler.Failed(hierarchy.GetProperty(itemId, propertyId, out property)) ||
!(property is T))
{
value = default(T);
Expand All @@ -22,11 +22,22 @@ public static bool TryGetProperty<T>(this IVsHierarchy hierarchy, int propertyId
return true;
}

public static bool TryGetProperty<T>(this IVsHierarchy hierarchy, int propertyId, out T value)
{
const uint root = VSConstants.VSITEMID_ROOT;
return hierarchy.TryGetItemProperty(root, propertyId, out value);
}

public static bool TryGetProperty<T>(this IVsHierarchy hierarchy, __VSHPROPID propertyId, out T value)
{
return hierarchy.TryGetProperty((int)propertyId, out value);
}

public static bool TryGetItemProperty<T>(this IVsHierarchy hierarchy, uint itemId, __VSHPROPID propertyId, out T value)
{
return hierarchy.TryGetItemProperty(itemId, (int)propertyId, out value);
}

public static bool TryGetGuidProperty(this IVsHierarchy hierarchy, int propertyId, out Guid guid)
{
return ErrorHandler.Succeeded(hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, propertyId, out guid));
Expand All @@ -47,6 +58,11 @@ public static bool TryGetName(this IVsHierarchy hierarchy, out string name)
return hierarchy.TryGetProperty(__VSHPROPID.VSHPROPID_Name, out name);
}

public static bool TryGetItemName(this IVsHierarchy hierarchy, uint itemId, out string name)
{
return hierarchy.TryGetItemProperty(itemId, __VSHPROPID.VSHPROPID_Name, out name);
}

public static bool TryGetParentHierarchy(this IVsHierarchy hierarchy, out IVsHierarchy parentHierarchy)
{
return hierarchy.TryGetProperty(__VSHPROPID.VSHPROPID_ParentHierarchy, out parentHierarchy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal class AnalyzersCommandHandler : IVsUpdateSolutionEvents
private MenuCommand _referencesContextAddMenuItem;
private MenuCommand _removeMenuItem;
private MenuCommand _openRuleSetMenuItem;
private MenuCommand _setActiveRuleSetMenuItem;

private MenuCommand _setSeverityErrorMenuItem;
private MenuCommand _setSeverityWarningMenuItem;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void Initialize(IMenuCommandService menuCommandService)
_removeMenuItem = AddCommandHandler(menuCommandService, ID.RoslynCommands.RemoveAnalyzer, RemoveAnalyzerHandler);

_openRuleSetMenuItem = AddCommandHandler(menuCommandService, ID.RoslynCommands.OpenRuleSet, OpenRuleSetHandler);
_setActiveRuleSetMenuItem = AddCommandHandler(menuCommandService, ID.RoslynCommands.SetActiveRuleSet, SetActiveRuleSetHandler);

_setSeverityErrorMenuItem = AddCommandHandler(menuCommandService, ID.RoslynCommands.SetSeverityError, SetSeverityHandler);
_setSeverityWarningMenuItem = AddCommandHandler(menuCommandService, ID.RoslynCommands.SetSeverityWarning, SetSeverityHandler);
Expand Down Expand Up @@ -141,14 +143,20 @@ private void SelectedItemIdChangedHandler(object sender, EventArgs e)

private void UpdateMenuItemVisibility()
{
bool selectedProjectSupportsAnalyzers = SelectedProjectSupportAnalyzers();
bool selectedProjectSupportsAnalyzers = SelectedProjectSupportsAnalyzers();
_addMenuItem.Visible = selectedProjectSupportsAnalyzers;
_projectAddMenuItem.Visible = selectedProjectSupportsAnalyzers;
_projectContextAddMenuItem.Visible = selectedProjectSupportsAnalyzers && _tracker.SelectedItemId == VSConstants.VSITEMID_ROOT;
_referencesContextAddMenuItem.Visible = selectedProjectSupportsAnalyzers;

_openHelpLinkMenuItem.Visible = _tracker.SelectedDiagnosticItems.Length == 1 &&
!string.IsNullOrWhiteSpace(_tracker.SelectedDiagnosticItems[0].Descriptor.HelpLinkUri);


string itemName;
_setActiveRuleSetMenuItem.Visible = selectedProjectSupportsAnalyzers &&
_tracker.SelectedHierarchy.TryGetItemName(_tracker.SelectedItemId, out itemName) &&
Path.GetExtension(itemName).Equals(".ruleset", StringComparison.OrdinalIgnoreCase);
}

private void UpdateMenuItemsChecked()
Expand All @@ -165,7 +173,7 @@ private bool AnyDiagnosticsWithSeverity(ReportDiagnostic severity)
return _selectedDiagnosticItems.Any(item => item.EffectiveSeverity == severity);
}

private bool SelectedProjectSupportAnalyzers()
private bool SelectedProjectSupportsAnalyzers()
{
EnvDTE.Project project;
return _tracker != null &&
Expand Down Expand Up @@ -328,6 +336,17 @@ private void OpenDiagnosticHelpLinkHandler(object sender, EventArgs e)
}
}

private void SetActiveRuleSetHandler(object sender, EventArgs e)
{
EnvDTE.Project project;
string fileName;
if (_tracker.SelectedHierarchy.TryGetProject(out project) &&
_tracker.SelectedHierarchy.TryGetItemName(_tracker.SelectedItemId, out fileName))
{
UpdateProjectConfigurationsToUseRuleSetFile(project, fileName);
}
}

private string CreateCopyOfRuleSetForProject(string pathToRuleSet, EnvDTE.Project envDteProject)
{
string fileName = GetNewRuleSetFileNameForProject(envDteProject);
Expand Down
28 changes: 27 additions & 1 deletion src/VisualStudio/Setup/Commands.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<Group guid="guidRoslynGrpId" id="grpDiagnosticProperties" priority="0x002">
<Parent guid="guidRoslynGrpId" id="cmdidDiagnosticContextMenu"/>
</Group>

<Group guid="guidRoslynGrpId" id="grpSetActiveRuleSet">
</Group>
</Groups>

<Buttons>
Expand Down Expand Up @@ -242,7 +245,7 @@
<CommandName>SetSeverityNone</CommandName>
</Strings>
</Button>
<!-- Buttons to open the diagnostic help link -->
<!-- Button to open the diagnostic help link -->
<Button guid="guidRoslynGrpId" id="cmdidOpenDiagnosticHelpLink" priority="100" type="Button">
<Parent guid="guidRoslynGrpId" id="grpDiagnosticProperties" />
<CommandFlag>DynamicVisibility</CommandFlag>
Expand All @@ -254,6 +257,18 @@
<CommandName>ViewHelp</CommandName>
</Strings>
</Button>
<!-- Button to set the active rule set -->
<Button guid="guidRoslynGrpId" id="cmdidSetActiveRuleSet" priority="100" type="Button">
<Parent guid="guidRoslynGrpId" id="grpSetActiveRuleSet" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<ButtonText>&amp;Set as Active Rule Set</ButtonText>
<CanonicalName>SetAsActiveRuleSet</CanonicalName>
<LocCanonicalName>SetAsActiveRuleSet</LocCanonicalName>
<CommandName>SetAsActiveRuleSet</CommandName>
</Strings>
</Button>
</Buttons>

<Menus>
Expand Down Expand Up @@ -323,6 +338,15 @@
<CommandPlacement guid="guidVSStd97" id="cmdidPropSheetOrProperties" priority="200">
<Parent guid="guidRoslynGrpId" id="grpDiagnosticProperties" />
</CommandPlacement>

<!-- "Set as Active Rule Set" entries -->
<CommandPlacement guid="guidRoslynGrpId" id="grpSetActiveRuleSet" priority="0x0200">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
</CommandPlacement>

<CommandPlacement guid="guidRoslynGrpId" id="grpSetActiveRuleSet" priority="0x0200">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_WEBITEMNODE"/>
</CommandPlacement>
</CommandPlacements>

<UsedCommands>
Expand Down Expand Up @@ -372,6 +396,8 @@
<IDSymbol name="cmdidSetSeverityNone" value="0x0114" />
<IDSymbol name="grpDiagnosticProperties" value="0x0115" />
<IDSymbol name="cmdidOpenDiagnosticHelpLink" value="0x0116" />
<IDSymbol name="grpSetActiveRuleSet" value="0x0117" />
<IDSymbol name="cmdidSetActiveRuleSet" value="0x0118" />
</GuidSymbol>
</Symbols>
</CommandTable>