From 5c9bcea570a9861120f7835c931bdfb939fa3505 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Fri, 21 May 2021 11:29:38 -0700 Subject: [PATCH 1/3] Null annotate IWorkspaceProjectContextFactory --- .../CPS/IWorkspaceProjectContextFactory.cs | 6 ++---- .../Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs | 10 ++++------ .../CPS/CPSProject_IWorkspaceProjectContext.cs | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs index 240a399223658..35fcc226499a4 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs @@ -2,8 +2,6 @@ // 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.Threading; using System.Threading.Tasks; @@ -17,7 +15,7 @@ internal interface IWorkspaceProjectContextFactory { /// [Obsolete("Use CreateProjectContextAsync instead")] - IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath); + IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath); /// /// Creates and initializes a new Workspace project and returns a Project guid. /// Obsolete. The argument is ignored. /// Initial project binary output path. - Task CreateProjectContextAsync(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath, CancellationToken cancellationToken); + Task CreateProjectContextAsync(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, CancellationToken cancellationToken); } } diff --git a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs index 35bc6f8fa07c5..4e4907f0c6e06 100644 --- a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs +++ b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs @@ -2,8 +2,6 @@ // 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 System.Threading; @@ -43,7 +41,7 @@ public CPSProjectFactory( _serviceProvider = (Shell.IAsyncServiceProvider)serviceProvider; } - IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath) + IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath) { return _threadingContext.JoinableTaskFactory.Run(() => this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, CancellationToken.None)); @@ -52,10 +50,10 @@ IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(st public async Task CreateProjectContextAsync( string languageName, string projectUniqueName, - string projectFilePath, + string? projectFilePath, Guid projectGuid, - object hierarchy, - string binOutputPath, + object? hierarchy, + string? binOutputPath, CancellationToken cancellationToken) { await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); diff --git a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs index 945de21385027..2baadb03afb48 100644 --- a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs +++ b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProject_IWorkspaceProjectContext.cs @@ -61,7 +61,7 @@ public bool LastDesignTimeBuildSucceeded set => _visualStudioProject.HasAllInformation = value; } - public CPSProject(VisualStudioProject visualStudioProject, VisualStudioWorkspaceImpl visualStudioWorkspace, IProjectCodeModelFactory projectCodeModelFactory, Guid projectGuid, string binOutputPath) + public CPSProject(VisualStudioProject visualStudioProject, VisualStudioWorkspaceImpl visualStudioWorkspace, IProjectCodeModelFactory projectCodeModelFactory, Guid projectGuid, string? binOutputPath) { _visualStudioProject = visualStudioProject; _visualStudioWorkspace = visualStudioWorkspace; From bb7f6155742d511600e097fde8b4f482ed9488b6 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Fri, 21 May 2021 11:41:49 -0700 Subject: [PATCH 2/3] Add a property to pass through the initial assembly name Right now we don't get the command line string for options until the full design time build has completed; however the project system can still give us the evaluated string which is likely to be close enough. This allows features that want to get symbol names for source to have a better chance of having something that they can use and look up in caches or in the cloud. --- .../CSharp/Test/ProjectSystemShim/CSharpHelpers.cs | 2 ++ .../CPS/IWorkspaceProjectContextFactory.cs | 14 +++++++++++++- .../Impl/ProjectSystem/CPS/CPSProjectFactory.cs | 10 +++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CSharpHelpers.cs b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CSharpHelpers.cs index 41bc80f793c64..6bfdd9c096465 100644 --- a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CSharpHelpers.cs +++ b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CSharpHelpers.cs @@ -86,6 +86,7 @@ public static async Task CreateCSharpCPSProjectAsync(TestEnvironment projectGuid, hierarchy, binOutputPath, + assemblyName: null, CancellationToken.None); cpsProject.SetOptions(ImmutableArray.Create(commandLineArguments)); @@ -105,6 +106,7 @@ public static async Task CreateNonCompilableProjectAsync(TestEnviron Guid.NewGuid(), hierarchy, binOutputPath: null, + assemblyName: null, CancellationToken.None); } diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs index 35fcc226499a4..df0c894e5967f 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs @@ -17,6 +17,10 @@ internal interface IWorkspaceProjectContextFactory [Obsolete("Use CreateProjectContextAsync instead")] IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath); + /// + [Obsolete("Use CreateProjectContextAsync instead")] + IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, string? assemblyName); + /// /// Creates and initializes a new Workspace project and returns a to lazily initialize the properties and items for the @@ -29,6 +33,14 @@ internal interface IWorkspaceProjectContextFactory /// Project guid. /// Obsolete. The argument is ignored. /// Initial project binary output path. - Task CreateProjectContextAsync(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, CancellationToken cancellationToken); + Task CreateProjectContextAsync( + string languageName, + string projectUniqueName, + string projectFilePath, + Guid projectGuid, + object? hierarchy, + string? binOutputPath, + string? assemblyName, + CancellationToken cancellationToken); } } diff --git a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs index 4e4907f0c6e06..302171e13e329 100644 --- a/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs +++ b/src/VisualStudio/Core/Impl/ProjectSystem/CPS/CPSProjectFactory.cs @@ -44,7 +44,13 @@ public CPSProjectFactory( IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath) { return _threadingContext.JoinableTaskFactory.Run(() => - this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, CancellationToken.None)); + this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, assemblyName: null, CancellationToken.None)); + } + + IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, string? assemblyName) + { + return _threadingContext.JoinableTaskFactory.Run(() => + this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, assemblyName, CancellationToken.None)); } public async Task CreateProjectContextAsync( @@ -54,12 +60,14 @@ public async Task CreateProjectContextAsync( Guid projectGuid, object? hierarchy, string? binOutputPath, + string? assemblyName, CancellationToken cancellationToken) { await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var creationInfo = new VisualStudioProjectCreationInfo { + AssemblyName = assemblyName, FilePath = projectFilePath, Hierarchy = hierarchy as IVsHierarchy, ProjectGuid = projectGuid, From c2388e73b4af2edc147f97c85dee75e5ffdd1627 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Fri, 21 May 2021 11:42:36 -0700 Subject: [PATCH 3/3] Fix comment that says we aren't using a parameter that's critical --- .../ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs index df0c894e5967f..bae5d127b04f7 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/CPS/IWorkspaceProjectContextFactory.cs @@ -31,7 +31,7 @@ internal interface IWorkspaceProjectContextFactory /// Unique name for the project. /// Full path to the project file for the project. /// Project guid. - /// Obsolete. The argument is ignored. + /// The IVsHierarchy for the project; this is used to track linked files across multiple projects when determining contexts. /// Initial project binary output path. Task CreateProjectContextAsync( string languageName,