Skip to content
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

Expose async entrypoint for IWorkspaceProjectContextFactory #51138

Merged
merged 34 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
29bb62b
Expose async entrypoint for IWorkspaceProjectContextFactory
CyrusNajmabadi Feb 10, 2021
2171687
Update tesst
CyrusNajmabadi Feb 11, 2021
88a6598
Merge remote-tracking branch 'upstream/master' into asyncProjectFactory
CyrusNajmabadi Feb 11, 2021
cdf3f83
More JTF
CyrusNajmabadi Feb 11, 2021
fe8ca83
Cancellation
CyrusNajmabadi Feb 11, 2021
5b7bea8
Fix tests
CyrusNajmabadi Feb 12, 2021
539dded
Merge remote-tracking branch 'upstream/master' into asyncProjectFactory
CyrusNajmabadi Feb 13, 2021
392393a
Switch to async loading.
CyrusNajmabadi Feb 13, 2021
d46ea35
Add comment
CyrusNajmabadi Feb 13, 2021
82409be
More async
CyrusNajmabadi Feb 13, 2021
20670a5
pull solution code up
CyrusNajmabadi Feb 13, 2021
fb0c5dd
Inline
CyrusNajmabadi Feb 13, 2021
fd039ca
Updatecomment
CyrusNajmabadi Feb 13, 2021
7cd7d84
Update comment
CyrusNajmabadi Feb 13, 2021
7179d1a
Add comment
CyrusNajmabadi Feb 13, 2021
d3f9833
Remove methods
CyrusNajmabadi Feb 13, 2021
173f96f
more async
CyrusNajmabadi Feb 13, 2021
04fa8d3
null check
CyrusNajmabadi Feb 14, 2021
c31c935
reentrancy'
CyrusNajmabadi Feb 14, 2021
07d2183
Switch to ValueTask
CyrusNajmabadi Feb 14, 2021
d043723
Use CT.None
CyrusNajmabadi Feb 14, 2021
766fab9
Use CT.None
CyrusNajmabadi Feb 14, 2021
52039d9
Async service provider.
CyrusNajmabadi Feb 14, 2021
a2c5ca4
Async service provider.
CyrusNajmabadi Feb 14, 2021
ce53c66
Switch back to the UI thread.
CyrusNajmabadi Feb 14, 2021
56a0fc9
Switch back to UIthread
CyrusNajmabadi Feb 18, 2021
5f3c213
reorder
CyrusNajmabadi Feb 18, 2021
c73e66b
Update src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualS…
CyrusNajmabadi Feb 18, 2021
c701b66
rename
CyrusNajmabadi Feb 18, 2021
c7d4372
Move comment
CyrusNajmabadi Feb 18, 2021
6285480
Tweak
CyrusNajmabadi Feb 18, 2021
4bc6c1c
Docs
CyrusNajmabadi Feb 18, 2021
b1e2a6b
Revert
CyrusNajmabadi Feb 18, 2021
a5f1b03
REvise
CyrusNajmabadi Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio;
Expand All @@ -22,10 +23,10 @@ public class AdditionalPropertiesTests
{
[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void SetProperty_RootNamespace_CPS()
public async Task SetProperty_RootNamespace_CPS()
{
using (var environment = new TestEnvironment())
using (var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
using (var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test"))
{
Assert.Null(DefaultNamespaceOfSingleProject(environment));

Expand All @@ -47,12 +48,12 @@ static string DefaultNamespaceOfSingleProject(TestEnvironment environment)
[InlineData(LanguageVersion.LatestMajor)]
[InlineData(LanguageVersion.Preview)]
[InlineData(null)]
public void SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion? maxSupportedLangVersion)
public async Task SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion? maxSupportedLangVersion)
{
const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;

using (var environment = new TestEnvironment(typeof(CSharpParseOptionsChangingService)))
using (var cpsProject = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
using (var cpsProject = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test"))
{
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
Expand All @@ -76,12 +77,12 @@ public void SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion? maxSupporte
}

[WpfFact]
public void SetProperty_MaxSupportedLangVersion_CPS_NotSet()
public async Task SetProperty_MaxSupportedLangVersion_CPS_NotSet()
{
const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;

using (var environment = new TestEnvironment(typeof(CSharpParseOptionsChangingService)))
using (var cpsProject = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
using (var cpsProject = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test"))
{
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
Expand Down Expand Up @@ -119,16 +120,16 @@ public void SetProperty_MaxSupportedLangVersion_CPS_NotSet()
[InlineData("FALSE", "", false)]
// Invalid values ignored
[InlineData("Invalid", "INVALID", true)]
public void SetProperty_RunAnalyzersAndRunAnalyzersDuringLiveAnalysis(string runAnalyzers, string runAnalyzersDuringLiveAnalysis, bool expectedRunAnalyzers)
public async Task SetProperty_RunAnalyzersAndRunAnalyzersDuringLiveAnalysis(string runAnalyzers, string runAnalyzersDuringLiveAnalysis, bool expectedRunAnalyzers)
{
TestCPSProject();
await TestCPSProject();
TestLegacyProject();
return;

void TestCPSProject()
async Task TestCPSProject()
{
using var environment = new TestEnvironment();
using var cpsProject = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using var cpsProject = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");

cpsProject.SetProperty(AdditionalPropertyNames.RunAnalyzers, runAnalyzers);
cpsProject.SetProperty(AdditionalPropertyNames.RunAnalyzersDuringLiveAnalysis, runAnalyzersDuringLiveAnalysis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand All @@ -20,7 +21,7 @@ public class AnalyzersTests : TestBase
{
[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void RuleSet_GeneralOption_CPS()
public async Task RuleSet_GeneralOption_CPS()
{
var ruleSetFile = Temp.CreateFile().WriteAllText(
@"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -29,7 +30,7 @@ public void RuleSet_GeneralOption_CPS()
</RuleSet>
");
using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;

Expand All @@ -45,7 +46,7 @@ public void RuleSet_GeneralOption_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void RuleSet_SpecificOptions_CPS()
public async Task RuleSet_SpecificOptions_CPS()
{
var ruleSetFile = Temp.CreateFile().WriteAllText(
@"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -58,7 +59,7 @@ public void RuleSet_SpecificOptions_CPS()
");

using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");
// Verify SetRuleSetFile updates the ruleset.
project.SetOptions(ImmutableArray.Create($"/ruleset:{ruleSetFile.Path}"));

Expand All @@ -70,13 +71,13 @@ public void RuleSet_SpecificOptions_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void RuleSet_PathCanBeFound()
public async Task RuleSet_PathCanBeFound()
{
var ruleSetFile = Temp.CreateFile();
using var environment = new TestEnvironment();
ProjectId projectId;

using (var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
using (var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test"))
{
project.SetOptions(ImmutableArray.Create($"/ruleset:{ruleSetFile.Path}"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
Expand All @@ -23,30 +24,30 @@ public class CSharpCompilerOptionsTests : TestBase
{
[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void DocumentationModeSetToDiagnoseIfProducingDocFile_CPS()
public async Task DocumentationModeSetToDiagnoseIfProducingDocFile_CPS()
{
using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", commandLineArguments: @"/doc:DocFile.xml");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", commandLineArguments: @"/doc:DocFile.xml");
var parseOptions = environment.Workspace.CurrentSolution.Projects.Single().ParseOptions;
Assert.Equal(DocumentationMode.Diagnose, parseOptions.DocumentationMode);
}

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void DocumentationModeSetToParseIfNotProducingDocFile_CPS()
public async Task DocumentationModeSetToParseIfNotProducingDocFile_CPS()
{
using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", commandLineArguments: @"/doc:");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", commandLineArguments: @"/doc:");
var parseOptions = environment.Workspace.CurrentSolution.Projects.Single().ParseOptions;
Assert.Equal(DocumentationMode.Parse, parseOptions.DocumentationMode);
}

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectSettingsOptionAddAndRemove_CPS()
public async Task ProjectSettingsOptionAddAndRemove_CPS()
{
using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", commandLineArguments: @"/warnaserror:CS1111");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", commandLineArguments: @"/warnaserror:CS1111");
var options = environment.GetUpdatedCompilationOptionOfSingleProject();
Assert.Equal(expected: ReportDiagnostic.Error, actual: options.SpecificDiagnosticOptions["CS1111"]);

Expand All @@ -57,13 +58,13 @@ public void ProjectSettingsOptionAddAndRemove_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectOutputBinPathChange_CPS()
public async Task ProjectOutputBinPathChange_CPS()
{
var initialObjPath = @"C:\test.dll";
var initialBinPath = initialObjPath;

using var environment = new TestEnvironment();
using var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", commandLineArguments: $"/out:{initialObjPath}");
using var project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", commandLineArguments: $"/out:{initialObjPath}");
Assert.Equal(initialObjPath, project.CompilationOutputAssemblyFilePath);
Assert.Equal(initialBinPath, project.BinOutputPath);

Expand Down Expand Up @@ -101,42 +102,42 @@ public void ProjectOutputBinPathChange_CPS()

[WpfFact, WorkItem(14520, "https://github.com/dotnet/roslyn/issues/14520")]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void InvalidProjectOutputBinPaths_CPS1()
public async Task InvalidProjectOutputBinPaths_CPS1()
{
using var environment = new TestEnvironment();
using var project1 = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", binOutputPath: null);
using var project1 = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", binOutputPath: null);
// Null output path is allowed.
Assert.Null(project1.BinOutputPath);
}

[WpfFact, WorkItem(14520, "https://github.com/dotnet/roslyn/issues/14520")]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void InvalidProjectOutputBinPaths_CPS2()
public async Task InvalidProjectOutputBinPaths_CPS2()
{
using var environment = new TestEnvironment();
using var project2 = CSharpHelpers.CreateCSharpCPSProject(environment, "Test2", binOutputPath: String.Empty);
using var project2 = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test2", binOutputPath: String.Empty);
// Empty output path is not allowed, it gets reset to null.
Assert.Null(project2.BinOutputPath);
}

[WpfFact, WorkItem(14520, "https://github.com/dotnet/roslyn/issues/14520")]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void InvalidProjectOutputBinPaths_CPS3()
public async Task InvalidProjectOutputBinPaths_CPS3()
{
using var environment = new TestEnvironment();
using var project3 = CSharpHelpers.CreateCSharpCPSProject(environment, "Test3", binOutputPath: "Test.dll");
using var project3 = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test3", binOutputPath: "Test.dll");
// Non-rooted output path is not allowed, it gets reset to a temp rooted path.
Assert.Equal(Path.Combine(Path.GetTempPath(), "Test.dll"), project3.BinOutputPath);
}

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectGuidSetter_CPS()
public async Task ProjectGuidSetter_CPS()
{
var initialGuid = Guid.NewGuid();

using var environment = new TestEnvironment();
using IWorkspaceProjectContext projectContext = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", initialGuid);
using IWorkspaceProjectContext projectContext = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test", initialGuid);
Assert.Equal(initialGuid, projectContext.Guid);

var newGuid = Guid.NewGuid();
Expand All @@ -146,10 +147,10 @@ public void ProjectGuidSetter_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectLastDesignTimeBuildSucceededSetter_CPS()
public async Task ProjectLastDesignTimeBuildSucceededSetter_CPS()
{
using var environment = new TestEnvironment();
using IWorkspaceProjectContext projectContext = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using IWorkspaceProjectContext projectContext = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");
Assert.True(projectContext.LastDesignTimeBuildSucceeded);

projectContext.LastDesignTimeBuildSucceeded = false;
Expand All @@ -158,10 +159,10 @@ public void ProjectLastDesignTimeBuildSucceededSetter_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectDisplayNameSetter_CPS()
public async Task ProjectDisplayNameSetter_CPS()
{
using var environment = new TestEnvironment();
using IWorkspaceProjectContext project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using IWorkspaceProjectContext project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");
Assert.Equal("Test", project.DisplayName);
var initialProjectFilePath = project.ProjectFilePath;

Expand All @@ -174,10 +175,10 @@ public void ProjectDisplayNameSetter_CPS()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void ProjectFilePathSetter_CPS()
public async Task ProjectFilePathSetter_CPS()
{
using var environment = new TestEnvironment();
using IWorkspaceProjectContext project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
using IWorkspaceProjectContext project = await CSharpHelpers.CreateCSharpCPSProjectAsync(environment, "Test");
var initialProjectDisplayName = project.DisplayName;
var initialProjectFilePath = project.ProjectFilePath;
var newFilePath = Temp.CreateFile().Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand All @@ -24,13 +25,13 @@ public class CSharpReferenceTests
{
[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void AddRemoveProjectAndMetadataReference_CPS()
public async Task AddRemoveProjectAndMetadataReference_CPS()
{
using var environment = new TestEnvironment();
var project1 = CreateCSharpCPSProject(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = CreateCSharpCPSProject(environment, "project2", commandLineArguments: @"/out:c:\project2.dll");
var project3 = CreateCSharpCPSProject(environment, "project3", commandLineArguments: @"/out:c:\project3.dll");
var project4 = CreateCSharpCPSProject(environment, "project4");
var project1 = await CreateCSharpCPSProjectAsync(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = await CreateCSharpCPSProjectAsync(environment, "project2", commandLineArguments: @"/out:c:\project2.dll");
var project3 = await CreateCSharpCPSProjectAsync(environment, "project3", commandLineArguments: @"/out:c:\project3.dll");
var project4 = await CreateCSharpCPSProjectAsync(environment, "project4");

// Add project reference
project3.AddProjectReference(project1, new MetadataReferenceProperties());
Expand Down Expand Up @@ -90,11 +91,11 @@ IEnumerable<PortableExecutableReference> GetProject3MetadataReferences()

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void RemoveProjectConvertsProjectReferencesBack()
public async Task RemoveProjectConvertsProjectReferencesBack()
{
using var environment = new TestEnvironment();
var project1 = CreateCSharpCPSProject(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = CreateCSharpCPSProject(environment, "project2");
var project1 = await CreateCSharpCPSProjectAsync(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = await CreateCSharpCPSProjectAsync(environment, "project2");

// Add project reference as metadata reference: since this is known to be the output path of project1, the metadata reference is converted to a project reference
project2.AddMetadataReference(@"c:\project1.dll", new MetadataReferenceProperties());
Expand All @@ -112,11 +113,11 @@ public void RemoveProjectConvertsProjectReferencesBack()
[WorkItem(461967, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/461967")]
[WorkItem(727173, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/727173")]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void AddingMetadataReferenceToProjectThatCannotCompileInTheIdeKeepsMetadataReference()
public async Task AddingMetadataReferenceToProjectThatCannotCompileInTheIdeKeepsMetadataReference()
{
using var environment = new TestEnvironment(typeof(NoCompilationLanguageServiceFactory));
var project1 = CreateCSharpCPSProject(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = CreateNonCompilableProject(environment, "project2", @"C:\project2.fsproj");
var project1 = await CreateCSharpCPSProjectAsync(environment, "project1", commandLineArguments: @"/out:c:\project1.dll");
var project2 = await CreateNonCompilableProjectAsync(environment, "project2", @"C:\project2.fsproj");
project2.BinOutputPath = "c:\\project2.dll";

project1.AddMetadataReference(project2.BinOutputPath, MetadataReferenceProperties.Assembly);
Expand All @@ -130,10 +131,10 @@ public void AddingMetadataReferenceToProjectThatCannotCompileInTheIdeKeepsMetada

[WpfFact]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void AddRemoveAnalyzerReference_CPS()
public async Task AddRemoveAnalyzerReference_CPS()
{
using var environment = new TestEnvironment();
using var project = CreateCSharpCPSProject(environment, "project1");
using var project = await CreateCSharpCPSProjectAsync(environment, "project1");
// Add analyzer reference
var analyzerAssemblyFullPath = @"c:\someAssembly.dll";

Expand Down
Loading