@ -53,28 +53,24 @@ namespace ILSpy.Analyzers
public bool IsVisible ( TextViewContext context )
public bool IsVisible ( TextViewContext context )
{
{
if ( context . SelectedTreeNodes is not { Length : > 0 } nodes )
if ( context . SelectedTreeNodes is { Length : > 0 } nodes )
return false ;
return nodes . All ( n = > n is IMemberTreeNode ) ;
return nodes . All ( n = > n is IMemberTreeNode ) ;
// Right-clicking a resolved symbol in the decompiled code: the reference carries the entity.
return context . Reference ? . Reference is IEntity ;
}
}
public bool IsEnabled ( TextViewContext context )
public bool IsEnabled ( TextViewContext context )
{
{
if ( context . SelectedTreeNodes is not { Length : > 0 } nodes )
if ( context . SelectedTreeNodes is { Length : > 0 } nodes )
return false ;
return nodes . OfType < IMemberTreeNode > ( ) . All ( n = > IsAnalysable ( n . Member ) ) ;
return nodes . OfType < IMemberTreeNode > ( ) . All ( n = > IsAnalysable ( n . Member ) ) ;
return context . Reference ? . Reference is IEntity entity & & IsAnalysable ( entity ) ;
}
}
public void Execute ( TextViewContext context )
public void Execute ( TextViewContext context )
{
{
if ( context . SelectedTreeNodes is not { Length : > 0 } nodes )
var analysable = MembersToAnalyse ( context ) ;
return ;
var analysable = nodes . OfType < IMemberTreeNode > ( )
. Select ( n = > n . Member )
. Where ( IsAnalysable )
. ToList ( ) ;
foreach ( var member in analysable )
foreach ( var member in analysable )
analyzerTreeViewModel . Analyze ( member ! ) ;
analyzerTreeViewModel . Analyze ( member ) ;
// Bring the analyzer pane to the front so the user can see the entity they just
// Bring the analyzer pane to the front so the user can see the entity they just
// added. AnalyzerTreeViewModel.Analyze deliberately leaves dock-activation to its
// added. AnalyzerTreeViewModel.Analyze deliberately leaves dock-activation to its
// caller — that's this entry's job.
// caller — that's this entry's job.
@ -82,6 +78,23 @@ namespace ILSpy.Analyzers
dockWorkspace . ShowToolPane ( AnalyzerTreeViewModel . PaneContentId ) ;
dockWorkspace . ShowToolPane ( AnalyzerTreeViewModel . PaneContentId ) ;
}
}
// The analysable entities for this invocation: a tree-node selection (assembly/analyzer tree),
// or the single resolved entity under a right-clicked code reference (decompiler text view).
static System . Collections . Generic . List < IEntity > MembersToAnalyse ( TextViewContext context )
{
if ( context . SelectedTreeNodes is { Length : > 0 } nodes )
{
return nodes . OfType < IMemberTreeNode > ( )
. Select ( n = > n . Member )
. Where ( IsAnalysable )
. Select ( m = > m ! )
. ToList ( ) ;
}
if ( context . Reference ? . Reference is IEntity entity & & IsAnalysable ( entity ) )
return new System . Collections . Generic . List < IEntity > { entity } ;
return new System . Collections . Generic . List < IEntity > ( ) ;
}
/// <summary>
/// <summary>
/// Const fields are textual literals at every use-site rather than entities the
/// Const fields are textual literals at every use-site rather than entities the
/// analyser can match against — exclude them so the entry stays disabled.
/// analyser can match against — exclude them so the entry stays disabled.