未验证 提交 fd90dd44 编写于 作者: M msftbot[bot] 提交者: GitHub

Merge pull request #41325 from dotnet/merges/master-to-release/dev16.6-preview1

Merge master to release/dev16.6-preview1
...@@ -428,6 +428,11 @@ function TestUsingOptimizedRunner() { ...@@ -428,6 +428,11 @@ function TestUsingOptimizedRunner() {
if ($testIOperation) { if ($testIOperation) {
Remove-Item env:\ROSLYN_TEST_IOPERATION Remove-Item env:\ROSLYN_TEST_IOPERATION
} }
if ($testVsi) {
Write-Host "Copying ServiceHub logs to $LogDir"
Copy-Item -Path (Join-Path $TempDir "servicehub\logs") -Destination (Join-Path $LogDir "servicehub") -Recurse
}
} }
} }
...@@ -622,7 +627,9 @@ try { ...@@ -622,7 +627,9 @@ try {
} }
catch catch
{ {
echo "##vso[task.logissue type=error](NETCORE_ENGINEERING_TELEMETRY=Build) Build failed" if ($ci) {
echo "##vso[task.logissue type=error](NETCORE_ENGINEERING_TELEMETRY=Build) Build failed"
}
throw $_ throw $_
} }
...@@ -642,7 +649,9 @@ try { ...@@ -642,7 +649,9 @@ try {
} }
catch catch
{ {
echo "##vso[task.logissue type=error](NETCORE_ENGINEERING_TELEMETRY=Test) Tests failed" if ($ci) {
echo "##vso[task.logissue type=error](NETCORE_ENGINEERING_TELEMETRY=Test) Tests failed"
}
throw $_ throw $_
} }
......
...@@ -386,7 +386,7 @@ public CompilationOptions WithGeneralDiagnosticOption(ReportDiagnostic value) ...@@ -386,7 +386,7 @@ public CompilationOptions WithGeneralDiagnosticOption(ReportDiagnostic value)
/// <summary> /// <summary>
/// Creates a new options instance with the specified diagnostic-specific options. /// Creates a new options instance with the specified diagnostic-specific options.
/// </summary> /// </summary>
public CompilationOptions WithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> value) public CompilationOptions WithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic>? value)
{ {
return CommonWithSpecificDiagnosticOptions(value); return CommonWithSpecificDiagnosticOptions(value);
} }
...@@ -497,7 +497,7 @@ public CompilationOptions WithCryptoKeyContainer(string? cryptoKeyContainer) ...@@ -497,7 +497,7 @@ public CompilationOptions WithCryptoKeyContainer(string? cryptoKeyContainer)
return CommonWithCryptoKeyContainer(cryptoKeyContainer); return CommonWithCryptoKeyContainer(cryptoKeyContainer);
} }
public CompilationOptions WithCryptoKeyFile(string cryptoKeyFile) public CompilationOptions WithCryptoKeyFile(string? cryptoKeyFile)
{ {
return CommonWithCryptoKeyFile(cryptoKeyFile); return CommonWithCryptoKeyFile(cryptoKeyFile);
} }
...@@ -531,14 +531,14 @@ public CompilationOptions WithOverflowChecks(bool checkOverflow) ...@@ -531,14 +531,14 @@ public CompilationOptions WithOverflowChecks(bool checkOverflow)
protected abstract CompilationOptions CommonWithAssemblyIdentityComparer(AssemblyIdentityComparer comparer); protected abstract CompilationOptions CommonWithAssemblyIdentityComparer(AssemblyIdentityComparer comparer);
protected abstract CompilationOptions CommonWithStrongNameProvider(StrongNameProvider? provider); protected abstract CompilationOptions CommonWithStrongNameProvider(StrongNameProvider? provider);
protected abstract CompilationOptions CommonWithGeneralDiagnosticOption(ReportDiagnostic generalDiagnosticOption); protected abstract CompilationOptions CommonWithGeneralDiagnosticOption(ReportDiagnostic generalDiagnosticOption);
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> specificDiagnosticOptions); protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic>? specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions); protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithReportSuppressedDiagnostics(bool reportSuppressedDiagnostics); protected abstract CompilationOptions CommonWithReportSuppressedDiagnostics(bool reportSuppressedDiagnostics);
protected abstract CompilationOptions CommonWithModuleName(string? moduleName); protected abstract CompilationOptions CommonWithModuleName(string? moduleName);
protected abstract CompilationOptions CommonWithMainTypeName(string? mainTypeName); protected abstract CompilationOptions CommonWithMainTypeName(string? mainTypeName);
protected abstract CompilationOptions CommonWithScriptClassName(string scriptClassName); protected abstract CompilationOptions CommonWithScriptClassName(string scriptClassName);
protected abstract CompilationOptions CommonWithCryptoKeyContainer(string? cryptoKeyContainer); protected abstract CompilationOptions CommonWithCryptoKeyContainer(string? cryptoKeyContainer);
protected abstract CompilationOptions CommonWithCryptoKeyFile(string cryptoKeyFile); protected abstract CompilationOptions CommonWithCryptoKeyFile(string? cryptoKeyFile);
protected abstract CompilationOptions CommonWithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey); protected abstract CompilationOptions CommonWithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey);
protected abstract CompilationOptions CommonWithDelaySign(bool? delaySign); protected abstract CompilationOptions CommonWithDelaySign(bool? delaySign);
protected abstract CompilationOptions CommonWithCheckOverflow(bool checkOverflow); protected abstract CompilationOptions CommonWithCheckOverflow(bool checkOverflow);
......
...@@ -20,6 +20,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr ...@@ -20,6 +20,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr
[UseExportProvider] [UseExportProvider]
public class ExtensionMethodImportCompletionProviderTests : AbstractCSharpCompletionProviderTests public class ExtensionMethodImportCompletionProviderTests : AbstractCSharpCompletionProviderTests
{ {
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public ExtensionMethodImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture) public ExtensionMethodImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{ {
} }
...@@ -36,11 +40,7 @@ protected override OptionSet WithChangedOptions(OptionSet options) ...@@ -36,11 +40,7 @@ protected override OptionSet WithChangedOptions(OptionSet options)
} }
protected override ExportProvider GetExportProvider() protected override ExportProvider GetExportProvider()
{ => s_exportProviderFactory.CreateExportProvider();
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
internal override CompletionProvider CreateCompletionProvider() internal override CompletionProvider CreateCompletionProvider()
{ {
...@@ -76,34 +76,16 @@ private static IEnumerable<List<object>> BuiltInTypes ...@@ -76,34 +76,16 @@ private static IEnumerable<List<object>> BuiltInTypes
{ {
get get
{ {
var predefinedTypes = new List<List<string>> var predefinedTypes = new List<string>() { "string", "String", "System.String" };
{
new List<string>()
{ "int", "Int32", "System.Int32" },
new List<string>()
{ "float", "Single", "System.Single" },
new List<string>()
{ "uint", "UInt32", "System.UInt32" },
new List<string>()
{ "bool", "Boolean", "System.Boolean"},
new List<string>()
{ "string", "String", "System.String"},
new List<string>()
{ "object", "Object", "System.Object"},
};
var arraySuffixes = new[] { "", "[]", "[,]" }; var arraySuffixes = new[] { "", "[]", "[,]" };
foreach (var group in predefinedTypes) foreach (var type1 in predefinedTypes)
{ {
foreach (var type1 in group) foreach (var type2 in predefinedTypes)
{ {
foreach (var type2 in group) foreach (var suffix in arraySuffixes)
{ {
foreach (var suffix in arraySuffixes) yield return new List<object>() { type1 + suffix, type2 + suffix };
{
yield return new List<object>() { type1 + suffix, type2 + suffix };
}
} }
} }
} }
......
...@@ -25,6 +25,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionSe ...@@ -25,6 +25,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionSe
[UseExportProvider] [UseExportProvider]
public partial class SymbolCompletionProviderTests : AbstractCSharpCompletionProviderTests public partial class SymbolCompletionProviderTests : AbstractCSharpCompletionProviderTests
{ {
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public SymbolCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture) public SymbolCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{ {
} }
...@@ -35,11 +39,7 @@ internal override CompletionProvider CreateCompletionProvider() ...@@ -35,11 +39,7 @@ internal override CompletionProvider CreateCompletionProvider()
} }
protected override ExportProvider GetExportProvider() protected override ExportProvider GetExportProvider()
{ => s_exportProviderFactory.CreateExportProvider();
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)] [Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task EmptyFile() public async Task EmptyFile()
......
...@@ -22,6 +22,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr ...@@ -22,6 +22,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr
[UseExportProvider] [UseExportProvider]
public class TypeImportCompletionProviderTests : AbstractCSharpCompletionProviderTests public class TypeImportCompletionProviderTests : AbstractCSharpCompletionProviderTests
{ {
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public TypeImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture) public TypeImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{ {
} }
...@@ -43,11 +47,7 @@ protected override OptionSet WithChangedOptions(OptionSet options) ...@@ -43,11 +47,7 @@ protected override OptionSet WithChangedOptions(OptionSet options)
} }
protected override ExportProvider GetExportProvider() protected override ExportProvider GetExportProvider()
{ => s_exportProviderFactory.CreateExportProvider();
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
#region "Option tests" #region "Option tests"
......
...@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Public Class ExtensionMethodImportCompletionProviderTests Public Class ExtensionMethodImportCompletionProviderTests
Inherits AbstractVisualBasicCompletionProviderTests Inherits AbstractVisualBasicCompletionProviderTests
Private Shared ReadOnly s_exportProviderFactory As IExportProviderFactory =
ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService)))
Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture) Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture)
MyBase.New(workspaceFixture) MyBase.New(workspaceFixture)
End Sub End Sub
...@@ -32,7 +36,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -32,7 +36,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function End Function
Protected Overrides Function GetExportProvider() As ExportProvider Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider() Return s_exportProviderFactory.CreateExportProvider()
End Function End Function
Friend Overrides Function CreateCompletionProvider() As CompletionProvider Friend Overrides Function CreateCompletionProvider() As CompletionProvider
......
...@@ -18,6 +18,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -18,6 +18,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Private Const s_unicodeEllipsis = ChrW(&H2026) Private Const s_unicodeEllipsis = ChrW(&H2026)
Private Shared ReadOnly s_exportProviderFactory As IExportProviderFactory =
ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService)))
Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture) Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture)
MyBase.New(workspaceFixture) MyBase.New(workspaceFixture)
End Sub End Sub
...@@ -27,7 +31,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -27,7 +31,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function End Function
Protected Overrides Function GetExportProvider() As ExportProvider Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider() Return s_exportProviderFactory.CreateExportProvider()
End Function End Function
#Region "StandaloneNamespaceAndTypeSourceTests" #Region "StandaloneNamespaceAndTypeSourceTests"
......
...@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Public Class TypeImportCompletionProviderTests Public Class TypeImportCompletionProviderTests
Inherits AbstractVisualBasicCompletionProviderTests Inherits AbstractVisualBasicCompletionProviderTests
Private Shared ReadOnly s_exportProviderFactory As IExportProviderFactory =
ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService)))
Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture) Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture)
MyBase.New(workspaceFixture) MyBase.New(workspaceFixture)
End Sub End Sub
...@@ -30,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet ...@@ -30,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function End Function
Protected Overrides Function GetExportProvider() As ExportProvider Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider() Return s_exportProviderFactory.CreateExportProvider()
End Function End Function
Friend Overrides Function CreateCompletionProvider() As CompletionProvider Friend Overrides Function CreateCompletionProvider() As CompletionProvider
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem; using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Roslyn.Utilities; using Roslyn.Utilities;
...@@ -37,22 +40,27 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou ...@@ -37,22 +40,27 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou
throw new ArgumentException(nameof(outputFileName), "Must specify an output file name."); throw new ArgumentException(nameof(outputFileName), "Must specify an output file name.");
} }
var project = _workspace.CurrentSolution.GetProject(context.Id); var project = _workspace.CurrentSolution.GetRequiredProject(context.Id);
// Start by fetching the compilation we have already have that will have references correct
var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false);
// Remove all files except the ones we care about // Update to just the syntax trees we need to keep
var documents = project.Documents; var syntaxTrees = new List<SyntaxTree>(capacity: filesToInclude.Count);
foreach (var document in documents) foreach (var document in project.Documents)
{ {
if (!filesToInclude.Contains(document.FilePath)) if (document.FilePath != null && filesToInclude.Contains(document.FilePath))
{ {
project = project.RemoveDocument(document.Id); syntaxTrees.Add(await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
} }
compilation = compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(syntaxTrees);
// We need to inherit most of the projects options, mainly for VB (RootNamespace, GlobalImports etc.), but we need to override about some specific things surrounding the output // We need to inherit most of the projects options, mainly for VB (RootNamespace, GlobalImports etc.), but we need to override about some specific things surrounding the output
var options = project.CompilationOptions compilation = compilation.WithOptions(compilation.Options
// copied from the old TempPE compiler used by legacy, for parity. // copied from the old TempPE compiler used by legacy, for parity.
// See: https://github.com/dotnet/roslyn/blob/fab7134296816fc80019c60b0f5bef7400cf23ea/src/VisualStudio/CSharp/Impl/ProjectSystemShim/TempPECompilerService.cs#L58 // See: https://github.com/dotnet/roslyn/blob/fab7134296816fc80019c60b0f5bef7400cf23ea/src/VisualStudio/CSharp/Impl/ProjectSystemShim/TempPECompilerService.cs#L58
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
...@@ -70,14 +78,10 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou ...@@ -70,14 +78,10 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou
.WithDelaySign(false) .WithDelaySign(false)
.WithCryptoKeyFile(null) .WithCryptoKeyFile(null)
.WithPublicSign(false) .WithPublicSign(false)
.WithStrongNameProvider(null); .WithStrongNameProvider(null));
project = project
.WithCompilationOptions(options)
// AssemblyName should be set to the filename of the output file because multiple TempPE DLLs can be created for the same project
.WithAssemblyName(Path.GetFileName(outputFileName));
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); // AssemblyName should be set to the filename of the output file because multiple TempPE DLLs can be created for the same project
compilation = compilation.WithAssemblyName(Path.GetFileName(outputFileName));
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
......
...@@ -510,21 +510,14 @@ private async Task<Compilation> GetOrBuildDeclarationCompilationAsync(SolutionSt ...@@ -510,21 +510,14 @@ private async Task<Compilation> GetOrBuildDeclarationCompilationAsync(SolutionSt
var compilation = CreateEmptyCompilation(); var compilation = CreateEmptyCompilation();
var trees = ArrayBuilder<SyntaxTree>.GetInstance(ProjectState.DocumentIds.Count); var trees = ArrayBuilder<SyntaxTree>.GetInstance(ProjectState.DocumentIds.Count);
foreach (var document in this.ProjectState.OrderedDocumentStates) foreach (var document in ProjectState.OrderedDocumentStates)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Include the tree even if the content of the document failed to load.
// Do not include syntax trees for documents whose content failed to load. trees.Add(await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
// Analyzers should not run on these (empty) syntax trees.
var loadDiagnostic = await document.GetLoadDiagnosticAsync(cancellationToken).ConfigureAwait(false);
if (loadDiagnostic == null)
{
trees.Add(await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
}
} }
compilation = compilation.AddSyntaxTrees(trees); compilation = compilation.AddSyntaxTrees(trees);
trees.Free(); trees.Free();
WriteState(new FullDeclarationState(compilation), solution); WriteState(new FullDeclarationState(compilation), solution);
......
...@@ -1995,6 +1995,9 @@ public bool TryGetCompilation(ProjectId projectId, [NotNullWhen(returnValue: tru ...@@ -1995,6 +1995,9 @@ public bool TryGetCompilation(ProjectId projectId, [NotNullWhen(returnValue: tru
/// Returns the compilation for the specified <see cref="ProjectId"/>. Can return <see langword="null"/> when the project /// Returns the compilation for the specified <see cref="ProjectId"/>. Can return <see langword="null"/> when the project
/// does not support compilations. /// does not support compilations.
/// </summary> /// </summary>
/// <remarks>
/// The compilation is guaranteed to have a syntax tree for each document of the project.
/// </remarks>
private Task<Compilation?> GetCompilationAsync(ProjectId projectId, CancellationToken cancellationToken) private Task<Compilation?> GetCompilationAsync(ProjectId projectId, CancellationToken cancellationToken)
{ {
// TODO: figure out where this is called and why the nullable suppression is required // TODO: figure out where this is called and why the nullable suppression is required
...@@ -2005,6 +2008,9 @@ public bool TryGetCompilation(ProjectId projectId, [NotNullWhen(returnValue: tru ...@@ -2005,6 +2008,9 @@ public bool TryGetCompilation(ProjectId projectId, [NotNullWhen(returnValue: tru
/// Returns the compilation for the specified <see cref="ProjectState"/>. Can return <see langword="null"/> when the project /// Returns the compilation for the specified <see cref="ProjectState"/>. Can return <see langword="null"/> when the project
/// does not support compilations. /// does not support compilations.
/// </summary> /// </summary>
/// <remarks>
/// The compilation is guaranteed to have a syntax tree for each document of the project.
/// </remarks>
public Task<Compilation?> GetCompilationAsync(ProjectState project, CancellationToken cancellationToken) public Task<Compilation?> GetCompilationAsync(ProjectState project, CancellationToken cancellationToken)
{ {
return project.SupportsCompilation return project.SupportsCompilation
......
...@@ -1273,6 +1273,11 @@ public async Task TestDocumentFileAccessFailureMissingFile() ...@@ -1273,6 +1273,11 @@ public async Task TestDocumentFileAccessFailureMissingFile()
Assert.Equal(@"C:\doesnotexist.cs: (0,0)-(0,0)", diagnostic.Location.GetLineSpan().ToString()); Assert.Equal(@"C:\doesnotexist.cs: (0,0)-(0,0)", diagnostic.Location.GetLineSpan().ToString());
Assert.Equal(WorkspaceDiagnosticKind.Failure, diagnosticFromEvent.Kind); Assert.Equal(WorkspaceDiagnosticKind.Failure, diagnosticFromEvent.Kind);
Assert.Equal("", text.ToString()); Assert.Equal("", text.ToString());
// Verify invariant: The compilation is guaranteed to have a syntax tree for each document of the project (even if the contnet fails to load).
var compilation = await solution.State.GetCompilationAsync(doc.Project.State, CancellationToken.None).ConfigureAwait(false);
var syntaxTree = compilation.SyntaxTrees.Single();
Assert.Equal("", syntaxTree.ToString());
} }
[Fact] [Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册