Skip to content

Commit

Permalink
Fix broken analyzer child nodes in Solution Explorer
Browse files Browse the repository at this point in the history
In 17.2, CPS made a change to how paths are used for non-file items in the tree. These changes improve the performance of searching the dependency tree by path, as the pseudo-id used for items not having paths allows a fast lookup.

That change broke the ability for Roslyn to determine the correct file path for analyzer nodes (via CanonicalName), which then broke the ability to attach child nodes to the analyzer in Solution Explorer (for example, to show source generators and the files they create).

In this commit, we add the FileSystemEntity flag to analyzer nodes. This causes CPS to preserve the full path provided on the IProjectTree, which restores the CanonicalName for Roslyn.
  • Loading branch information
drewnoakes committed Apr 7, 2022
1 parent 5452635 commit 740ad1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Models
{
internal class AnalyzerDependencyModel : DependencyModel
{
// NOTE we include ProjectTreeFlags.FileSystemEntity here so that Roslyn can
// correctly identify the analyzer's path in order to attach child nodes to
// these dependency items in Solution Explorer. Without this flag, CPS will
// remove whatever file path we pass during tree construction (for performance
// reasons).

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.AnalyzerDependency + DependencyTreeFlags.SupportsBrowse,
unresolved: DependencyTreeFlags.AnalyzerDependency + DependencyTreeFlags.SupportsBrowse);
resolved: DependencyTreeFlags.AnalyzerDependency + DependencyTreeFlags.SupportsBrowse + ProjectTreeFlags.FileSystemEntity,
unresolved: DependencyTreeFlags.AnalyzerDependency + DependencyTreeFlags.SupportsBrowse + ProjectTreeFlags.FileSystemEntity);

private static readonly DependencyIconSet s_iconSet = new(
icon: KnownMonikers.CodeInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void Resolved()
Assert.Equal(
DependencyTreeFlags.AnalyzerDependency +
DependencyTreeFlags.SupportsBrowse +
DependencyTreeFlags.ResolvedDependencyFlags,
DependencyTreeFlags.ResolvedDependencyFlags +
ProjectTreeFlags.FileSystemEntity,
model.Flags);
}

Expand Down Expand Up @@ -69,7 +70,8 @@ public void Unresolved()
Assert.Equal(
DependencyTreeFlags.AnalyzerDependency +
DependencyTreeFlags.SupportsBrowse +
DependencyTreeFlags.UnresolvedDependencyFlags,
DependencyTreeFlags.UnresolvedDependencyFlags +
ProjectTreeFlags.FileSystemEntity,
model.Flags);
}

Expand Down Expand Up @@ -102,7 +104,8 @@ public void Implicit()
DependencyTreeFlags.AnalyzerDependency +
DependencyTreeFlags.SupportsBrowse +
DependencyTreeFlags.ResolvedDependencyFlags -
DependencyTreeFlags.SupportsRemove,
DependencyTreeFlags.SupportsRemove +
ProjectTreeFlags.FileSystemEntity,
model.Flags);
}
}
Expand Down

0 comments on commit 740ad1a

Please sign in to comment.