-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Communicate with OOP process to determine if an AnalyzerReference has analyzers or source generators. #74810
Changes from all commits
d7c8b19
db32141
b563736
fb3c807
a36f423
88a5d34
3e978ea
20e7d2c
841fcbb
838f20c
006ec2d
d012fb4
5bc5d64
f9d7eae
37a1bdb
72f2df3
cb6a128
dc818fa
ca94422
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,18 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable disable | ||
|
||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.Internal.VisualStudio.PlatformUI; | ||
using Microsoft.VisualStudio.Imaging; | ||
using Microsoft.VisualStudio.Imaging.Interop; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer; | ||
|
||
internal partial class AnalyzerItem( | ||
internal sealed partial class AnalyzerItem( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just cleanup. No other changes. |
||
AnalyzersFolderItem analyzersFolder, | ||
AnalyzerReference analyzerReference, | ||
IContextMenuController contextMenuController) : BaseItem(GetNameText(analyzerReference)) | ||
IContextMenuController contextMenuController) | ||
: BaseItem(GetNameText(analyzerReference)) | ||
{ | ||
public AnalyzersFolderItem AnalyzersFolder { get; } = analyzersFolder; | ||
public AnalyzerReference AnalyzerReference { get; } = analyzerReference; | ||
|
@@ -37,14 +36,7 @@ public void Remove() | |
=> this.AnalyzersFolder.RemoveAnalyzer(this.AnalyzerReference.FullPath); | ||
|
||
private static string GetNameText(AnalyzerReference analyzerReference) | ||
{ | ||
if (analyzerReference is UnresolvedAnalyzerReference) | ||
{ | ||
return analyzerReference.FullPath; | ||
} | ||
else | ||
{ | ||
return analyzerReference.Display; | ||
} | ||
} | ||
=> analyzerReference is UnresolvedAnalyzerReference unresolvedAnalyzerReference | ||
? unresolvedAnalyzerReference.FullPath | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this prevents an NRT warning by accessing FullPath through teh derived type. |
||
: analyzerReference.Display; | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,28 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.ComponentModel.Composition; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Microsoft.Internal.VisualStudio.PlatformUI; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer | ||
{ | ||
[Export(typeof(IAttachedCollectionSourceProvider))] | ||
[Name(nameof(AnalyzerItemSourceProvider))] | ||
[Order] | ||
[AppliesToProject("(CSharp | VB) & !CPS")] // in the CPS case, the Analyzers items are created by the project system | ||
internal sealed class AnalyzerItemSourceProvider : AttachedCollectionSourceProvider<AnalyzersFolderItem> | ||
{ | ||
[Import(typeof(AnalyzersCommandHandler))] | ||
private readonly IAnalyzersCommandHandler _commandHandler = null; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public AnalyzerItemSourceProvider() | ||
{ | ||
} | ||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer; | ||
|
||
protected override IAttachedCollectionSource CreateCollectionSource(AnalyzersFolderItem analyzersFolder, string relationshipName) | ||
{ | ||
if (relationshipName == KnownRelationships.Contains) | ||
{ | ||
return new AnalyzerItemSource(analyzersFolder, _commandHandler); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
[Export(typeof(IAttachedCollectionSourceProvider))] | ||
[Name(nameof(AnalyzerItemSourceProvider)), Order] | ||
[AppliesToProject("(CSharp | VB) & !CPS")] // in the CPS case, the Analyzers items are created by the project system | ||
[method: ImportingConstructor] | ||
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
internal sealed class AnalyzerItemSourceProvider( | ||
[Import(typeof(AnalyzersCommandHandler))] IAnalyzersCommandHandler commandHandler, | ||
IAsynchronousOperationListenerProvider listenerProvider) | ||
: AttachedCollectionSourceProvider<AnalyzersFolderItem> | ||
{ | ||
protected override IAttachedCollectionSource? CreateCollectionSource(AnalyzersFolderItem analyzersFolder, string relationshipName) | ||
=> relationshipName == KnownRelationships.Contains | ||
? new AnalyzerItemSource(analyzersFolder, commandHandler, listenerProvider) | ||
: null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just cleanup. No other changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,48 +4,30 @@ | |
|
||
using System.Collections; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer; | ||
|
||
internal sealed class AnalyzersFolderItemSource : IAttachedCollectionSource | ||
internal sealed class AnalyzersFolderItemSource( | ||
IThreadingContext threadingContext, | ||
Workspace workspace, | ||
ProjectId projectId, | ||
IVsHierarchyItem projectHierarchyItem, | ||
IAnalyzersCommandHandler commandHandler) | ||
: IAttachedCollectionSource | ||
{ | ||
private readonly IVsHierarchyItem _projectHierarchyItem; | ||
private readonly Workspace _workspace; | ||
private readonly ProjectId _projectId; | ||
private readonly ObservableCollection<AnalyzersFolderItem> _folderItems; | ||
private readonly IAnalyzersCommandHandler _commandHandler; | ||
|
||
public AnalyzersFolderItemSource(Workspace workspace, ProjectId projectId, IVsHierarchyItem projectHierarchyItem, IAnalyzersCommandHandler commandHandler) | ||
{ | ||
_workspace = workspace; | ||
_projectId = projectId; | ||
_projectHierarchyItem = projectHierarchyItem; | ||
_commandHandler = commandHandler; | ||
|
||
_folderItems = []; | ||
|
||
Update(); | ||
} | ||
private readonly ObservableCollection<AnalyzersFolderItem> _folderItems = [new AnalyzersFolderItem( | ||
threadingContext, | ||
workspace, | ||
projectId, | ||
projectHierarchyItem, | ||
commandHandler.AnalyzerFolderContextMenuController)]; | ||
|
||
public bool HasItems => true; | ||
|
||
public IEnumerable Items => _folderItems; | ||
|
||
public object SourceItem => _projectHierarchyItem; | ||
|
||
internal void Update() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was only called in the constructor. so it could be inlined. once inlined, it meant that almost all state held int his type went away. |
||
{ | ||
// Don't create the item a 2nd time. | ||
if (_folderItems.Any()) | ||
return; | ||
|
||
_folderItems.Add(new AnalyzersFolderItem( | ||
_workspace, | ||
_projectId, | ||
_projectHierarchyItem, | ||
_commandHandler.AnalyzerFolderContextMenuController)); | ||
} | ||
public object SourceItem => projectHierarchyItem; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
using Microsoft.Internal.VisualStudio.PlatformUI; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
|
@@ -21,13 +22,16 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplore | |
[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] | ||
[method: ImportingConstructor] | ||
internal sealed class AnalyzersFolderItemSourceProvider( | ||
IThreadingContext threadingContext, | ||
VisualStudioWorkspace workspace, | ||
[Import(typeof(AnalyzersCommandHandler))] IAnalyzersCommandHandler commandHandler) | ||
: AttachedCollectionSourceProvider<IVsHierarchyItem> | ||
{ | ||
private readonly IThreadingContext _threadingContext = threadingContext; | ||
private readonly Workspace _workspace = workspace; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. passing along IThreadingContext so we update the UI on the UI thread. |
||
private readonly IAnalyzersCommandHandler _commandHandler = commandHandler; | ||
|
||
private IHierarchyItemToProjectIdMap? _projectMap; | ||
private readonly Workspace _workspace = workspace; | ||
|
||
protected override IAttachedCollectionSource? CreateCollectionSource(IVsHierarchyItem item, string relationshipName) | ||
{ | ||
|
@@ -46,7 +50,7 @@ internal sealed class AnalyzersFolderItemSourceProvider( | |
if (hierarchyMapper != null && | ||
hierarchyMapper.TryGetProjectId(item.Parent, targetFrameworkMoniker: null, projectId: out var projectId)) | ||
{ | ||
return new AnalyzersFolderItemSource(_workspace, projectId, item, _commandHandler); | ||
return new AnalyzersFolderItemSource(_threadingContext, _workspace, projectId, item, _commandHandler); | ||
} | ||
|
||
return null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View with whitespace off.