未验证 提交 231ccac5 编写于 作者: H Heejae Chang 提交者: GitHub

share solution info creation code. (#35715)

上级 345ee8ef
......@@ -86,7 +86,7 @@ private async Task<Solution> LoadAsync(CancellationToken cancellationToken)
}
// get new solution info
var solutionInfo = await solutionCreator.CreateSolutionInfoAsync(solutionChecksum).ConfigureAwait(false);
var solutionInfo = await SolutionInfoCreator.CreateSolutionInfoAsync(assetService, solutionChecksum, cancellationToken).ConfigureAwait(false);
// otherwise, just return new solution
return adhocWorkspace.AddSolution(solutionInfo);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Serialization;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
......@@ -44,5 +49,73 @@ public static WellKnownSynchronizationKind GetWellKnownSynchronizationKind(this
throw ExceptionUtilities.UnexpectedValue(value);
}
public static CompilationOptions FixUpCompilationOptions(this ProjectInfo.ProjectAttributes info, CompilationOptions compilationOptions)
{
return compilationOptions.WithXmlReferenceResolver(GetXmlResolver(info.FilePath))
.WithStrongNameProvider(new DesktopStrongNameProvider(GetStrongNameKeyPaths(info)));
}
private static XmlFileResolver GetXmlResolver(string filePath)
{
// Given filePath can be any arbitary string project is created with.
// for primary solution in host such as VSWorkspace, ETA or MSBuildWorkspace
// filePath will point to actual file on disk, but in memory solultion, or
// one from AdhocWorkspace and etc, FilePath can be a random string.
// Make sure we return only if given filePath is in right form.
if (!PathUtilities.IsAbsolute(filePath))
{
// xmlFileResolver can only deal with absolute path
// return Default
return XmlFileResolver.Default;
}
return new XmlFileResolver(PathUtilities.GetDirectoryName(filePath));
}
private static ImmutableArray<string> GetStrongNameKeyPaths(ProjectInfo.ProjectAttributes info)
{
// Given FilePath/OutputFilePath can be any arbitary strings project is created with.
// for primary solution in host such as VSWorkspace, ETA or MSBuildWorkspace
// filePath will point to actual file on disk, but in memory solultion, or
// one from AdhocWorkspace and etc, FilePath/OutputFilePath can be a random string.
// Make sure we return only if given filePath is in right form.
if (info.FilePath == null && info.OutputFilePath == null)
{
// return empty since that is what IDE does for this case
// see AbstractProject.GetStrongNameKeyPaths
return ImmutableArray<string>.Empty;
}
var builder = ArrayBuilder<string>.GetInstance();
if (info.FilePath != null && PathUtilities.IsAbsolute(info.FilePath))
{
// desktop strong name provider only knows how to deal with absolute path
builder.Add(PathUtilities.GetDirectoryName(info.FilePath));
}
if (info.OutputFilePath != null && PathUtilities.IsAbsolute(info.OutputFilePath))
{
// desktop strong name provider only knows how to deal with absolute path
builder.Add(PathUtilities.GetDirectoryName(info.OutputFilePath));
}
return builder.ToImmutableAndFree();
}
public static async Task<List<T>> CreateCollectionAsync<T>(this IAssetProvider assetProvider, ChecksumCollection collections, CancellationToken cancellationToken)
{
var assets = new List<T>();
foreach (var checksum in collections)
{
cancellationToken.ThrowIfCancellationRequested();
var asset = await assetProvider.GetAssetAsync<T>(checksum, cancellationToken).ConfigureAwait(false);
assets.Add(asset);
}
return assets;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Serialization;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Execution
{
/// <summary>
/// Provides corresponding data of the given checksum
/// </summary>
internal interface IAssetProvider
{
/// <summary>
/// return data of type T whose checksum is the given checksum
/// </summary>
Task<T> GetAssetAsync<T>(Checksum checksum, CancellationToken cancellationToken);
}
internal static class SolutionInfoCreator
{
public static async Task<SolutionInfo> CreateSolutionInfoAsync(IAssetProvider assetProvider, Checksum solutionChecksum, CancellationToken cancellationToken)
{
var solutionChecksumObject = await assetProvider.GetAssetAsync<SolutionStateChecksums>(solutionChecksum, cancellationToken).ConfigureAwait(false);
var solutionInfo = await assetProvider.GetAssetAsync<SolutionInfo.SolutionAttributes>(solutionChecksumObject.Info, cancellationToken).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectChecksum in solutionChecksumObject.Projects)
{
var projectInfo = await CreateProjectInfoAsync(assetProvider, projectChecksum, cancellationToken).ConfigureAwait(false);
if (projectInfo != null)
{
projects.Add(projectInfo);
}
}
return SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects);
}
public static async Task<ProjectInfo> CreateProjectInfoAsync(IAssetProvider assetProvider, Checksum projectChecksum, CancellationToken cancellationToken)
{
var projectSnapshot = await assetProvider.GetAssetAsync<ProjectStateChecksums>(projectChecksum, cancellationToken).ConfigureAwait(false);
var projectInfo = await assetProvider.GetAssetAsync<ProjectInfo.ProjectAttributes>(projectSnapshot.Info, cancellationToken).ConfigureAwait(false);
if (!RemoteSupportedLanguages.IsSupported(projectInfo.Language))
{
// only add project our workspace supports.
// workspace doesn't allow creating project with unknown languages
return null;
}
var compilationOptions = projectInfo.FixUpCompilationOptions(
await assetProvider.GetAssetAsync<CompilationOptions>(projectSnapshot.CompilationOptions, cancellationToken).ConfigureAwait(false));
var parseOptions = await assetProvider.GetAssetAsync<ParseOptions>(projectSnapshot.ParseOptions, cancellationToken).ConfigureAwait(false);
var p2p = await assetProvider.CreateCollectionAsync<ProjectReference>(projectSnapshot.ProjectReferences, cancellationToken).ConfigureAwait(false);
var metadata = await assetProvider.CreateCollectionAsync<MetadataReference>(projectSnapshot.MetadataReferences, cancellationToken).ConfigureAwait(false);
var analyzers = await assetProvider.CreateCollectionAsync<AnalyzerReference>(projectSnapshot.AnalyzerReferences, cancellationToken).ConfigureAwait(false);
var documentInfos = await CreateDocumentInfosAsync(assetProvider, projectSnapshot.Documents, cancellationToken).ConfigureAwait(false);
var additionalDocumentInfos = await CreateDocumentInfosAsync(assetProvider, projectSnapshot.AdditionalDocuments, cancellationToken).ConfigureAwait(false);
var analyzerConfigDocumentInfos = await CreateDocumentInfosAsync(assetProvider, projectSnapshot.AnalyzerConfigDocuments, cancellationToken).ConfigureAwait(false);
return ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documentInfos, p2p, metadata, analyzers, additionalDocumentInfos, projectInfo.IsSubmission)
.WithOutputRefFilePath(projectInfo.OutputRefFilePath)
.WithHasAllInformation(projectInfo.HasAllInformation)
.WithDefaultNamespace(projectInfo.DefaultNamespace)
.WithAnalyzerConfigDocuments(analyzerConfigDocumentInfos);
}
public static async Task<DocumentInfo> CreateDocumentInfoAsync(IAssetProvider assetProvider, Checksum documentChecksum, CancellationToken cancellationToken)
{
var documentSnapshot = await assetProvider.GetAssetAsync<DocumentStateChecksums>(documentChecksum, cancellationToken).ConfigureAwait(false);
var documentInfo = await assetProvider.GetAssetAsync<DocumentInfo.DocumentAttributes>(documentSnapshot.Info, cancellationToken).ConfigureAwait(false);
var textLoader = TextLoader.From(
TextAndVersion.Create(
await assetProvider.GetAssetAsync<SourceText>(documentSnapshot.Text, cancellationToken).ConfigureAwait(false),
VersionStamp.Create(),
documentInfo.FilePath));
// TODO: do we need version?
return DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
textLoader,
documentInfo.FilePath,
documentInfo.IsGenerated);
}
private static async Task<IEnumerable<DocumentInfo>> CreateDocumentInfosAsync(IAssetProvider assetProvider, ChecksumCollection documentChecksums, CancellationToken cancellationToken)
{
var documentInfos = new List<DocumentInfo>();
foreach (var documentChecksum in documentChecksums)
{
cancellationToken.ThrowIfCancellationRequested();
documentInfos.Add(await CreateDocumentInfoAsync(assetProvider, documentChecksum, cancellationToken).ConfigureAwait(false));
}
return documentInfos;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.IO;
......@@ -718,83 +717,10 @@ private static async Task VerifyOptionSetsAsync(Workspace workspace, string lang
private async Task<Solution> GetSolutionAsync(IRemotableDataService service, PinnedRemotableDataScope syncScope)
{
var workspace = new AdhocWorkspace();
var solutionObject = await service.GetValueAsync<SolutionStateChecksums>(syncScope.SolutionChecksum);
var solutionInfo = await service.GetValueAsync<SolutionInfo.SolutionAttributes>(solutionObject.Info).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectObject in solutionObject.Projects.ToProjectObjects(service))
{
var projectInfo = await service.GetValueAsync<ProjectInfo.ProjectAttributes>(projectObject.Info).ConfigureAwait(false);
if (!workspace.Services.IsSupported(projectInfo.Language))
{
continue;
}
async Task<List<DocumentInfo>> CreateDocumentInfosAsync(ChecksumObjectCollection<DocumentStateChecksums> checksums)
{
List<DocumentInfo> infos = new List<DocumentInfo>();
foreach (var documentStateChecksums in checksums)
{
var documentInfo = await service.GetValueAsync<DocumentInfo.DocumentAttributes>(documentStateChecksums.Info).ConfigureAwait(false);
var text = await service.GetValueAsync<SourceText>(documentStateChecksums.Text).ConfigureAwait(false);
// TODO: do we need version?
infos.Add(
DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())),
documentInfo.FilePath,
documentInfo.IsGenerated));
}
return infos;
}
var documents = await CreateDocumentInfosAsync(projectObject.Documents.ToDocumentObjects(service));
var solutionInfo = await SolutionInfoCreator.CreateSolutionInfoAsync(new AssetProvider(service), syncScope.SolutionChecksum, CancellationToken.None).ConfigureAwait(false);
var p2p = new List<ProjectReference>();
foreach (var checksum in projectObject.ProjectReferences)
{
var reference = await service.GetValueAsync<ProjectReference>(checksum).ConfigureAwait(false);
p2p.Add(reference);
}
var metadata = new List<MetadataReference>();
foreach (var checksum in projectObject.MetadataReferences)
{
var reference = await service.GetValueAsync<MetadataReference>(checksum).ConfigureAwait(false);
metadata.Add(reference);
}
var analyzers = new List<AnalyzerReference>();
foreach (var checksum in projectObject.AnalyzerReferences)
{
var reference = await service.GetValueAsync<AnalyzerReference>(checksum).ConfigureAwait(false);
analyzers.Add(reference);
}
var additionalDocuments = await CreateDocumentInfosAsync(projectObject.AdditionalDocuments.ToDocumentObjects(service));
var analyzerConfigDocuments = await CreateDocumentInfosAsync(projectObject.AnalyzerConfigDocuments.ToDocumentObjects(service));
var compilationOptions = await service.GetValueAsync<CompilationOptions>(projectObject.CompilationOptions).ConfigureAwait(false);
var parseOptions = await service.GetValueAsync<ParseOptions>(projectObject.ParseOptions).ConfigureAwait(false);
projects.Add(
ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documents, p2p, metadata, analyzers, additionalDocuments, projectInfo.IsSubmission)
.WithAnalyzerConfigDocuments(analyzerConfigDocuments));
}
return workspace.AddSolution(SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects));
var workspace = new AdhocWorkspace();
return workspace.AddSolution(solutionInfo);
}
private static async Task<RemotableData> CloneAssetAsync(ISerializerService serializer, RemotableData asset)
......
......@@ -85,4 +85,20 @@ public override Task WriteObjectToAsync(ObjectWriter writer, CancellationToken c
throw new NotImplementedException("should not be called");
}
}
internal sealed class AssetProvider : IAssetProvider
{
private readonly IRemotableDataService _service;
public AssetProvider(IRemotableDataService service)
{
_service = service;
}
public Task<T> GetAssetAsync<T>(Checksum checksum, CancellationToken cancellationToken)
{
return _service.GetValueAsync<T>(checksum);
}
}
}
......@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Execution;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Serialization;
using Roslyn.Utilities;
......@@ -15,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Remote
///
/// TODO: change this service to workspace service
/// </summary>
internal class AssetService
internal class AssetService : IAssetProvider
{
private readonly ISerializerService _serializerService;
private readonly int _scopeId;
......
......@@ -3,19 +3,16 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Remote.DebugUtil;
using Microsoft.CodeAnalysis.Remote.Shared;
using Microsoft.CodeAnalysis.Serialization;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using System.Diagnostics;
using System;
using Microsoft.CodeAnalysis.Execution;
namespace Microsoft.CodeAnalysis.Remote
{
......@@ -46,24 +43,6 @@ public async Task<bool> IsIncrementalUpdateAsync(Checksum newSolutionChecksum)
return _baseSolution.Id == newSolutionInfo.Id && _baseSolution.FilePath == newSolutionInfo.FilePath;
}
public async Task<SolutionInfo> CreateSolutionInfoAsync(Checksum solutionChecksum)
{
var solutionChecksumObject = await _assetService.GetAssetAsync<SolutionStateChecksums>(solutionChecksum, _cancellationToken).ConfigureAwait(false);
var solutionInfo = await _assetService.GetAssetAsync<SolutionInfo.SolutionAttributes>(solutionChecksumObject.Info, _cancellationToken).ConfigureAwait(false);
var projects = new List<ProjectInfo>();
foreach (var projectChecksum in solutionChecksumObject.Projects)
{
var projectInfo = await CreateProjectInfoAsync(projectChecksum).ConfigureAwait(false);
if (projectInfo != null)
{
projects.Add(projectInfo);
}
}
return SolutionInfo.Create(solutionInfo.Id, solutionInfo.Version, solutionInfo.FilePath, projects);
}
public async Task<Solution> CreateSolutionAsync(Checksum newSolutionChecksum)
{
var solution = _baseSolution;
......@@ -119,7 +98,7 @@ private async Task<Solution> UpdateProjectsAsync(Solution solution, HashSet<Chec
{
if (!oldMap.ContainsKey(kv.Key))
{
var projectInfo = await CreateProjectInfoAsync(kv.Value.Checksum).ConfigureAwait(false);
var projectInfo = await SolutionInfoCreator.CreateProjectInfoAsync(_assetService, kv.Value.Checksum, _cancellationToken).ConfigureAwait(false);
if (projectInfo == null)
{
// this project is not supported in OOP
......@@ -189,8 +168,7 @@ private async Task<Solution> UpdateProjectAsync(Project project, ProjectStateChe
if (oldProjectChecksums.CompilationOptions != newProjectChecksums.CompilationOptions)
{
project = project.WithCompilationOptions(
FixUpCompilationOptions(
project.State.ProjectInfo.Attributes,
project.State.ProjectInfo.Attributes.FixUpCompilationOptions(
await _assetService.GetAssetAsync<CompilationOptions>(
newProjectChecksums.CompilationOptions, _cancellationToken).ConfigureAwait(false)));
}
......@@ -204,19 +182,22 @@ private async Task<Solution> UpdateProjectAsync(Project project, ProjectStateChe
// changed project references
if (oldProjectChecksums.ProjectReferences.Checksum != newProjectChecksums.ProjectReferences.Checksum)
{
project = project.WithProjectReferences(await CreateCollectionAsync<ProjectReference>(newProjectChecksums.ProjectReferences).ConfigureAwait(false));
project = project.WithProjectReferences(await _assetService.CreateCollectionAsync<ProjectReference>(
newProjectChecksums.ProjectReferences, _cancellationToken).ConfigureAwait(false));
}
// changed metadata references
if (oldProjectChecksums.MetadataReferences.Checksum != newProjectChecksums.MetadataReferences.Checksum)
{
project = project.WithMetadataReferences(await CreateCollectionAsync<MetadataReference>(newProjectChecksums.MetadataReferences).ConfigureAwait(false));
project = project.WithMetadataReferences(await _assetService.CreateCollectionAsync<MetadataReference>(
newProjectChecksums.MetadataReferences, _cancellationToken).ConfigureAwait(false));
}
// changed analyzer references
if (oldProjectChecksums.AnalyzerReferences.Checksum != newProjectChecksums.AnalyzerReferences.Checksum)
{
project = project.WithAnalyzerReferences(await CreateCollectionAsync<AnalyzerReference>(newProjectChecksums.AnalyzerReferences).ConfigureAwait(false));
project = project.WithAnalyzerReferences(await _assetService.CreateCollectionAsync<AnalyzerReference>(
newProjectChecksums.AnalyzerReferences, _cancellationToken).ConfigureAwait(false));
}
// changed analyzer references
......@@ -335,7 +316,7 @@ private async Task<Project> UpdateProjectInfoAsync(Project project, Checksum inf
documentsToAdd = documentsToAdd ?? ImmutableArray.CreateBuilder<DocumentInfo>();
// we have new document added
var documentInfo = await CreateDocumentInfoAsync(kv.Value.Checksum).ConfigureAwait(false);
var documentInfo = await SolutionInfoCreator.CreateDocumentInfoAsync(_assetService, kv.Value.Checksum, _cancellationToken).ConfigureAwait(false);
documentsToAdd.Add(documentInfo);
}
}
......@@ -496,96 +477,6 @@ private async Task<TextDocument> UpdateDocumentInfoAsync(TextDocument document,
return map;
}
private async Task<ProjectInfo> CreateProjectInfoAsync(Checksum projectChecksum)
{
var projectSnapshot = await _assetService.GetAssetAsync<ProjectStateChecksums>(projectChecksum, _cancellationToken).ConfigureAwait(false);
var projectInfo = await _assetService.GetAssetAsync<ProjectInfo.ProjectAttributes>(projectSnapshot.Info, _cancellationToken).ConfigureAwait(false);
if (!RemoteSupportedLanguages.IsSupported(projectInfo.Language))
{
// only add project our workspace supports.
// workspace doesn't allow creating project with unknown languages
return null;
}
Contract.ThrowIfFalse(_baseSolution.Workspace.Services.IsSupported(projectInfo.Language));
var compilationOptions = FixUpCompilationOptions(
projectInfo,
await _assetService.GetAssetAsync<CompilationOptions>(
projectSnapshot.CompilationOptions, _cancellationToken).ConfigureAwait(false));
var parseOptions = await _assetService.GetAssetAsync<ParseOptions>(projectSnapshot.ParseOptions, _cancellationToken).ConfigureAwait(false);
var p2p = await CreateCollectionAsync<ProjectReference>(projectSnapshot.ProjectReferences).ConfigureAwait(false);
var metadata = await CreateCollectionAsync<MetadataReference>(projectSnapshot.MetadataReferences).ConfigureAwait(false);
var analyzers = await CreateCollectionAsync<AnalyzerReference>(projectSnapshot.AnalyzerReferences).ConfigureAwait(false);
var documentInfos = await CreateDocumentInfosAsync(projectSnapshot.Documents).ConfigureAwait(false);
var additionalDocumentInfos = await CreateDocumentInfosAsync(projectSnapshot.AdditionalDocuments).ConfigureAwait(false);
var analyzerConfigDocumentInfos = await CreateDocumentInfosAsync(projectSnapshot.AnalyzerConfigDocuments).ConfigureAwait(false);
return ProjectInfo.Create(
projectInfo.Id, projectInfo.Version, projectInfo.Name, projectInfo.AssemblyName,
projectInfo.Language, projectInfo.FilePath, projectInfo.OutputFilePath,
compilationOptions, parseOptions,
documentInfos, p2p, metadata, analyzers, additionalDocumentInfos, projectInfo.IsSubmission)
.WithOutputRefFilePath(projectInfo.OutputRefFilePath)
.WithHasAllInformation(projectInfo.HasAllInformation)
.WithDefaultNamespace(projectInfo.DefaultNamespace)
.WithAnalyzerConfigDocuments(analyzerConfigDocumentInfos);
}
private async Task<List<T>> CreateCollectionAsync<T>(ChecksumCollection collections)
{
var assets = new List<T>();
foreach (var checksum in collections)
{
_cancellationToken.ThrowIfCancellationRequested();
var asset = await _assetService.GetAssetAsync<T>(checksum, _cancellationToken).ConfigureAwait(false);
assets.Add(asset);
}
return assets;
}
private async Task<IEnumerable<DocumentInfo>> CreateDocumentInfosAsync(ChecksumCollection documentChecksums)
{
var documentInfos = new List<DocumentInfo>();
foreach (var documentChecksum in documentChecksums)
{
_cancellationToken.ThrowIfCancellationRequested();
documentInfos.Add(await CreateDocumentInfoAsync(documentChecksum).ConfigureAwait(false));
}
return documentInfos;
}
private async Task<DocumentInfo> CreateDocumentInfoAsync(Checksum documentChecksum)
{
var documentSnapshot = await _assetService.GetAssetAsync<DocumentStateChecksums>(documentChecksum, _cancellationToken).ConfigureAwait(false);
var documentInfo = await _assetService.GetAssetAsync<DocumentInfo.DocumentAttributes>(documentSnapshot.Info, _cancellationToken).ConfigureAwait(false);
var textLoader = TextLoader.From(
TextAndVersion.Create(
await _assetService.GetAssetAsync<SourceText>(documentSnapshot.Text, _cancellationToken).ConfigureAwait(false),
VersionStamp.Create(),
documentInfo.FilePath));
// TODO: do we need version?
return DocumentInfo.Create(
documentInfo.Id,
documentInfo.Name,
documentInfo.Folders,
documentInfo.SourceCodeKind,
textLoader,
documentInfo.FilePath,
documentInfo.IsGenerated);
}
private Project AddDocument(Project project, DocumentInfo documentInfo, bool additionalText)
{
if (additionalText)
......@@ -596,59 +487,6 @@ private Project AddDocument(Project project, DocumentInfo documentInfo, bool add
return project.Solution.AddDocument(documentInfo).GetProject(project.Id);
}
private CompilationOptions FixUpCompilationOptions(ProjectInfo.ProjectAttributes info, CompilationOptions compilationOptions)
{
return compilationOptions.WithXmlReferenceResolver(GetXmlResolver(info.FilePath))
.WithStrongNameProvider(new DesktopStrongNameProvider(GetStrongNameKeyPaths(info)));
}
private static XmlFileResolver GetXmlResolver(string filePath)
{
// Given filePath can be any arbitary string project is created with.
// for primary solution in host such as VSWorkspace, ETA or MSBuildWorkspace
// filePath will point to actual file on disk, but in memory solultion, or
// one from AdhocWorkspace and etc, FilePath can be a random string.
// Make sure we return only if given filePath is in right form.
if (!PathUtilities.IsAbsolute(filePath))
{
// xmlFileResolver can only deal with absolute path
// return Default
return XmlFileResolver.Default;
}
return new XmlFileResolver(PathUtilities.GetDirectoryName(filePath));
}
private ImmutableArray<string> GetStrongNameKeyPaths(ProjectInfo.ProjectAttributes info)
{
// Given FilePath/OutputFilePath can be any arbitary strings project is created with.
// for primary solution in host such as VSWorkspace, ETA or MSBuildWorkspace
// filePath will point to actual file on disk, but in memory solultion, or
// one from AdhocWorkspace and etc, FilePath/OutputFilePath can be a random string.
// Make sure we return only if given filePath is in right form.
if (info.FilePath == null && info.OutputFilePath == null)
{
// return empty since that is what IDE does for this case
// see AbstractProject.GetStrongNameKeyPaths
return ImmutableArray<string>.Empty;
}
var builder = ArrayBuilder<string>.GetInstance();
if (info.FilePath != null && PathUtilities.IsAbsolute(info.FilePath))
{
// desktop strong name provider only knows how to deal with absolute path
builder.Add(PathUtilities.GetDirectoryName(info.FilePath));
}
if (info.OutputFilePath != null && PathUtilities.IsAbsolute(info.OutputFilePath))
{
// desktop strong name provider only knows how to deal with absolute path
builder.Add(PathUtilities.GetDirectoryName(info.OutputFilePath));
}
return builder.ToImmutableAndFree();
}
private async Task ValidateChecksumAsync(Checksum checksumFromRequest, Solution incrementalSolutionBuilt)
{
#if DEBUG
......@@ -664,7 +502,7 @@ private async Task ValidateChecksumAsync(Checksum checksumFromRequest, Solution
async Task<Solution> CreateSolutionFromScratchAsync(Checksum checksum)
{
var solutionInfo = await CreateSolutionInfoAsync(checksum).ConfigureAwait(false);
var solutionInfo = await SolutionInfoCreator.CreateSolutionInfoAsync(_assetService, checksum, _cancellationToken).ConfigureAwait(false);
var workspace = new TemporaryWorkspace(solutionInfo);
return workspace.CurrentSolution;
......
......@@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Execution;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Utilities;
......@@ -125,7 +126,7 @@ private async Task<Solution> CreateSolution_NoLockAsync(Checksum solutionChecksu
await _assetService.SynchronizeSolutionAssetsAsync(solutionChecksum, cancellationToken).ConfigureAwait(false);
// get new solution info
var solutionInfo = await updater.CreateSolutionInfoAsync(solutionChecksum).ConfigureAwait(false);
var solutionInfo = await SolutionInfoCreator.CreateSolutionInfoAsync(_assetService, solutionChecksum, cancellationToken).ConfigureAwait(false);
if (fromPrimaryBranch)
{
......@@ -137,7 +138,7 @@ private async Task<Solution> CreateSolution_NoLockAsync(Checksum solutionChecksu
}
// otherwise, just return new solution
var workspace = new TemporaryWorkspace(await updater.CreateSolutionInfoAsync(solutionChecksum).ConfigureAwait(false));
var workspace = new TemporaryWorkspace(await SolutionInfoCreator.CreateSolutionInfoAsync(_assetService, solutionChecksum, cancellationToken).ConfigureAwait(false));
return workspace.CurrentSolution;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册