未验证 提交 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() {
if ($testIOperation) {
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 {
}
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 $_
}
......@@ -642,7 +649,9 @@ try {
}
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 $_
}
......
......@@ -386,7 +386,7 @@ public CompilationOptions WithGeneralDiagnosticOption(ReportDiagnostic value)
/// <summary>
/// Creates a new options instance with the specified diagnostic-specific options.
/// </summary>
public CompilationOptions WithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> value)
public CompilationOptions WithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic>? value)
{
return CommonWithSpecificDiagnosticOptions(value);
}
......@@ -497,7 +497,7 @@ public CompilationOptions WithCryptoKeyContainer(string? cryptoKeyContainer)
return CommonWithCryptoKeyContainer(cryptoKeyContainer);
}
public CompilationOptions WithCryptoKeyFile(string cryptoKeyFile)
public CompilationOptions WithCryptoKeyFile(string? cryptoKeyFile)
{
return CommonWithCryptoKeyFile(cryptoKeyFile);
}
......@@ -531,14 +531,14 @@ public CompilationOptions WithOverflowChecks(bool checkOverflow)
protected abstract CompilationOptions CommonWithAssemblyIdentityComparer(AssemblyIdentityComparer comparer);
protected abstract CompilationOptions CommonWithStrongNameProvider(StrongNameProvider? provider);
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 CommonWithReportSuppressedDiagnostics(bool reportSuppressedDiagnostics);
protected abstract CompilationOptions CommonWithModuleName(string? moduleName);
protected abstract CompilationOptions CommonWithMainTypeName(string? mainTypeName);
protected abstract CompilationOptions CommonWithScriptClassName(string scriptClassName);
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 CommonWithDelaySign(bool? delaySign);
protected abstract CompilationOptions CommonWithCheckOverflow(bool checkOverflow);
......
......@@ -20,6 +20,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr
[UseExportProvider]
public class ExtensionMethodImportCompletionProviderTests : AbstractCSharpCompletionProviderTests
{
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public ExtensionMethodImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{
}
......@@ -36,11 +40,7 @@ protected override OptionSet WithChangedOptions(OptionSet options)
}
protected override ExportProvider GetExportProvider()
{
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
=> s_exportProviderFactory.CreateExportProvider();
internal override CompletionProvider CreateCompletionProvider()
{
......@@ -76,34 +76,16 @@ private static IEnumerable<List<object>> BuiltInTypes
{
get
{
var predefinedTypes = new List<List<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 predefinedTypes = new List<string>() { "string", "String", "System.String" };
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
[UseExportProvider]
public partial class SymbolCompletionProviderTests : AbstractCSharpCompletionProviderTests
{
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public SymbolCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{
}
......@@ -35,11 +39,7 @@ internal override CompletionProvider CreateCompletionProvider()
}
protected override ExportProvider GetExportProvider()
{
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
=> s_exportProviderFactory.CreateExportProvider();
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task EmptyFile()
......
......@@ -22,6 +22,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr
[UseExportProvider]
public class TypeImportCompletionProviderTests : AbstractCSharpCompletionProviderTests
{
private static readonly IExportProviderFactory s_exportProviderFactory
= ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)));
public TypeImportCompletionProviderTests(CSharpTestWorkspaceFixture workspaceFixture) : base(workspaceFixture)
{
}
......@@ -43,11 +47,7 @@ protected override OptionSet WithChangedOptions(OptionSet options)
}
protected override ExportProvider GetExportProvider()
{
return ExportProviderCache
.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(typeof(TestExperimentationService)))
.CreateExportProvider();
}
=> s_exportProviderFactory.CreateExportProvider();
#region "Option tests"
......
......@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Public Class ExtensionMethodImportCompletionProviderTests
Inherits AbstractVisualBasicCompletionProviderTests
Private Shared ReadOnly s_exportProviderFactory As IExportProviderFactory =
ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService)))
Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture)
MyBase.New(workspaceFixture)
End Sub
......@@ -32,7 +36,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function
Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider()
Return s_exportProviderFactory.CreateExportProvider()
End Function
Friend Overrides Function CreateCompletionProvider() As CompletionProvider
......
......@@ -18,6 +18,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
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)
MyBase.New(workspaceFixture)
End Sub
......@@ -27,7 +31,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function
Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider()
Return s_exportProviderFactory.CreateExportProvider()
End Function
#Region "StandaloneNamespaceAndTypeSourceTests"
......
......@@ -15,6 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Public Class TypeImportCompletionProviderTests
Inherits AbstractVisualBasicCompletionProviderTests
Private Shared ReadOnly s_exportProviderFactory As IExportProviderFactory =
ExportProviderCache.GetOrCreateExportProviderFactory(
TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService)))
Public Sub New(workspaceFixture As VisualBasicTestWorkspaceFixture)
MyBase.New(workspaceFixture)
End Sub
......@@ -30,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
End Function
Protected Overrides Function GetExportProvider() As ExportProvider
Return ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithPart(GetType(TestExperimentationService))).CreateExportProvider()
Return s_exportProviderFactory.CreateExportProvider()
End Function
Friend Overrides Function CreateCompletionProvider() As CompletionProvider
......
......@@ -2,14 +2,17 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Roslyn.Utilities;
......@@ -37,22 +40,27 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou
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
var documents = project.Documents;
foreach (var document in documents)
// Update to just the syntax trees we need to keep
var syntaxTrees = new List<SyntaxTree>(capacity: filesToInclude.Count);
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();
}
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
var options = project.CompilationOptions
compilation = compilation.WithOptions(compilation.Options
// 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
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
......@@ -70,14 +78,10 @@ public async Task<bool> CompileAsync(IWorkspaceProjectContext context, string ou
.WithDelaySign(false)
.WithCryptoKeyFile(null)
.WithPublicSign(false)
.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));
.WithStrongNameProvider(null));
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();
......
......@@ -510,21 +510,14 @@ private async Task<Compilation> GetOrBuildDeclarationCompilationAsync(SolutionSt
var compilation = CreateEmptyCompilation();
var trees = ArrayBuilder<SyntaxTree>.GetInstance(ProjectState.DocumentIds.Count);
foreach (var document in this.ProjectState.OrderedDocumentStates)
foreach (var document in ProjectState.OrderedDocumentStates)
{
cancellationToken.ThrowIfCancellationRequested();
// Do not include syntax trees for documents whose content failed to load.
// 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));
}
// Include the tree even if the content of the document failed to load.
trees.Add(await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
}
compilation = compilation.AddSyntaxTrees(trees);
trees.Free();
WriteState(new FullDeclarationState(compilation), solution);
......
......@@ -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
/// does not support compilations.
/// </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)
{
// 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
/// Returns the compilation for the specified <see cref="ProjectState"/>. Can return <see langword="null"/> when the project
/// does not support compilations.
/// </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)
{
return project.SupportsCompilation
......
......@@ -1273,6 +1273,11 @@ public async Task TestDocumentFileAccessFailureMissingFile()
Assert.Equal(@"C:\doesnotexist.cs: (0,0)-(0,0)", diagnostic.Location.GetLineSpan().ToString());
Assert.Equal(WorkspaceDiagnosticKind.Failure, diagnosticFromEvent.Kind);
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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册