未验证 提交 551071c0 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #44270 from CyrusNajmabadi/primaryProjUpdate

Only report designer attributes for the primary project of a multi-project config.
......@@ -176,7 +176,7 @@ private void AddFilteredInfos(ImmutableArray<DesignerAttributeData> data, ArrayB
var cpsUpdateService = await GetUpdateServiceIfCpsProjectAsync(projectId, cancellationToken).ConfigureAwait(false);
var task = cpsUpdateService == null
? NotifyLegacyProjectSystemAsync(projectId, data, cancellationToken)
: NotifyCpsProjectSystemAsync(cpsUpdateService, data, cancellationToken);
: NotifyCpsProjectSystemAsync(projectId, cpsUpdateService, data, cancellationToken);
await task.ConfigureAwait(false);
}
......@@ -242,12 +242,19 @@ private void AddFilteredInfos(ImmutableArray<DesignerAttributeData> data, ArrayB
}
private async Task NotifyCpsProjectSystemAsync(
ProjectId projectId,
IProjectItemDesignerTypeUpdateService updateService,
IEnumerable<DesignerAttributeData> data,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
// We may have updates for many different configurations of the same logical project system project.
// However, the project system only associates designer attributes with one of those projects. So just drop
// the notifications for any sibling configurations.
if (!_workspace.IsPrimaryProject(projectId))
return;
// Broadcast all the information about all the documents in parallel to CPS.
using var _ = ArrayBuilder<Task>.GetInstance(out var tasks);
......
......@@ -20,6 +20,14 @@ internal interface IWorkspaceProjectContext : IDisposable
bool LastDesignTimeBuildSucceeded { get; set; }
string BinOutputPath { get; set; }
/// <summary>
/// When this project is one of a multi-targeting group of projects, this value indicates whether or not this
/// particular project is the primary one. The primary project is responsible for certain things when reporting
/// data from Roslyn's individual projects back to the project system itself. For example, designer attributes
/// are only associated with the primary project, and should be skipped for other projects.
/// </summary>
bool IsPrimary { get; set; }
ProjectId Id { get; }
// Options.
......
......@@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Debugger.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Microsoft.VisualStudio.PlatformUI;
using Roslyn.Utilities;
......@@ -68,6 +69,13 @@ internal sealed class VisualStudioProject
private string? _outputRefFilePath;
private string? _defaultNamespace;
/// <summary>
/// If this project is the 'primary' project the project system cares about for a group of Roslyn projects that
/// correspond to different configurations of a single project system project. <see langword="true"/> by
/// default.
/// </summary>
internal bool IsPrimary { get; set; } = true;
// Actual property values for 'RunAnalyzers' and 'RunAnalyzersDuringLiveAnalysis' properties from the project file.
// Both these properties can be used to configure running analyzers, with RunAnalyzers overriding RunAnalyzersDuringLiveAnalysis.
private bool? _runAnalyzersPropertyValue;
......
......@@ -406,6 +406,23 @@ internal bool IsCPSProject(ProjectId projectId)
return false;
}
internal bool IsPrimaryProject(ProjectId projectId)
{
lock (_gate)
{
foreach (var (_, projects) in this._projectSystemNameToProjectsMap)
{
foreach (var project in projects)
{
if (project.Id == projectId)
return project.IsPrimary;
}
}
}
return true;
}
protected override bool CanApplyCompilationOptionChange(CompilationOptions oldOptions, CompilationOptions newOptions, CodeAnalysis.Project project)
=> project.LanguageServices.GetRequiredService<ICompilationOptionsChangingService>().CanApplyChange(oldOptions, newOptions);
......
......@@ -14,8 +14,6 @@
using Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS
......@@ -46,6 +44,12 @@ public string DisplayName
set => _visualStudioProject.FilePath = value;
}
public bool IsPrimary
{
get => _visualStudioProject.IsPrimary;
set => _visualStudioProject.IsPrimary = value;
}
public Guid Guid
{
get;
......
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework
Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim
<[UseExportProvider]>
Public Class PrimaryProjectTests
<WpfFact>
Public Sub ProjectIsPrimaryByDefault()
Using environment = New TestEnvironment(GetType(TestDynamicFileInfoProviderThatProducesNoFiles))
Dim project = environment.ProjectFactory.CreateAndAddToWorkspace(
"project",
LanguageNames.CSharp)
Assert.True(project.IsPrimary)
End Using
End Sub
<WpfFact>
Public Sub ChangeProjectIsPrimary()
Using environment = New TestEnvironment(GetType(TestDynamicFileInfoProviderThatProducesNoFiles))
Dim project = environment.ProjectFactory.CreateAndAddToWorkspace(
"project",
LanguageNames.CSharp)
project.IsPrimary = False
Assert.False(project.IsPrimary)
End Using
End Sub
<WpfFact>
Public Sub ChangeProjectIsPrimaryBack()
Using environment = New TestEnvironment(GetType(TestDynamicFileInfoProviderThatProducesNoFiles))
Dim project = environment.ProjectFactory.CreateAndAddToWorkspace(
"project",
LanguageNames.CSharp)
project.IsPrimary = False
project.IsPrimary = True
Assert.True(project.IsPrimary)
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册