Skip to content

Commit

Permalink
Merge pull request #37060 from dotnet/merges/release/dev16.2-to-relea…
Browse files Browse the repository at this point in the history
…se/dev16.2-vs-deps

Merge release/dev16.2 to release/dev16.2-vs-deps
  • Loading branch information
dotnet-automerge-bot authored Jul 9, 2019
2 parents 82fffbc + 45ab845 commit 15b43b3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public VisualStudioProject CreateAndAddToWorkspace(string projectSystemName, str
// HACK: Fetch this service to ensure it's still created on the UI thread; once this is moved off we'll need to fix up it's constructor to be free-threaded.
_visualStudioWorkspaceImpl.Services.GetRequiredService<VisualStudioMetadataReferenceManager>();

// HACK: since we're on the UI thread, ensure we initialize our options provider which depends on a UI-affinitized experimentation service
_visualStudioWorkspaceImpl.EnsureDocumentOptionProvidersInitialized();

var id = ProjectId.CreateNewId(projectSystemName);
var directoryNameOpt = creationInfo.FilePath != null ? Path.GetDirectoryName(creationInfo.FilePath) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
Expand Down Expand Up @@ -91,18 +92,20 @@ internal abstract partial class VisualStudioWorkspaceImpl : VisualStudioWorkspac
internal FileWatchedPortableExecutableReferenceFactory FileWatchedReferenceFactory { get; }

private readonly Lazy<IProjectCodeModelFactory> _projectCodeModelFactory;

private readonly IEnumerable<IDocumentOptionsProviderFactory> _documentOptionsProviderFactories;
private bool _documentOptionsProvidersInitialized = false;
private readonly Dictionary<ProjectId, CompilationOutputs> _projectCompilationOutputs = new Dictionary<ProjectId, CompilationOutputs>();
private readonly object _projectCompilationOutputsGuard = new object();

public VisualStudioWorkspaceImpl(ExportProvider exportProvider, IAsyncServiceProvider asyncServiceProvider)
public VisualStudioWorkspaceImpl(ExportProvider exportProvider, IAsyncServiceProvider asyncServiceProvider, IEnumerable<CodeAnalysis.Options.IDocumentOptionsProviderFactory> documentOptionsProviderFactories)
: base(VisualStudioMefHostServices.Create(exportProvider))
{
_threadingContext = exportProvider.GetExportedValue<IThreadingContext>();
_textBufferCloneService = exportProvider.GetExportedValue<ITextBufferCloneService>();
_textBufferFactoryService = exportProvider.GetExportedValue<ITextBufferFactoryService>();
_projectionBufferFactoryService = exportProvider.GetExportedValue<IProjectionBufferFactoryService>();
_projectCodeModelFactory = exportProvider.GetExport<IProjectCodeModelFactory>();
_documentOptionsProviderFactories = documentOptionsProviderFactories;

// We fetch this lazily because VisualStudioProjectFactory depends on VisualStudioWorkspaceImpl -- we have a circularity. Since this
// exists right now as a compat shim, we'll just do this.
Expand Down Expand Up @@ -1885,5 +1888,27 @@ internal CompilationOutputs GetCompilationOutputs(ProjectId projectId)
return _projectCompilationOutputs.TryGetValue(projectId, out var outputs) ? outputs : CompilationOutputFiles.None;
}
}

internal void EnsureDocumentOptionProvidersInitialized()
{
_foregroundObject.AssertIsForeground();

if (_documentOptionsProvidersInitialized)
{
return;
}

_documentOptionsProvidersInitialized = true;

foreach (var providerFactory in _documentOptionsProviderFactories)
{
var optionsProvider = providerFactory.TryCreate(this);

if (optionsProvider != null)
{
Services.GetRequiredService<IOptionService>().RegisterDocumentOptionsProvider(optionsProvider);
}
}
}
}
}
12 changes: 1 addition & 11 deletions src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,9 @@ public RoslynVisualStudioWorkspace(
[ImportMany] IEnumerable<Lazy<IStreamingFindUsagesPresenter>> streamingPresenters,
[ImportMany] IEnumerable<IDocumentOptionsProviderFactory> documentOptionsProviderFactories,
[Import(typeof(SVsServiceProvider))] IAsyncServiceProvider asyncServiceProvider)
: base(exportProvider, asyncServiceProvider)
: base(exportProvider, asyncServiceProvider, documentOptionsProviderFactories)
{
_streamingPresenters = streamingPresenters;

foreach (var providerFactory in documentOptionsProviderFactories)
{
var optionsProvider = providerFactory.TryCreate(this);

if (optionsProvider != null)
{
Services.GetRequiredService<IOptionService>().RegisterDocumentOptionsProvider(optionsProvider);
}
}
}

internal override IInvisibleEditor OpenInvisibleEditor(DocumentId documentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports Microsoft.VisualStudio.Shell.Interop
Imports Moq
Imports Microsoft.VisualStudio.LanguageServices.Implementation.TaskList
Imports Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel
Imports Microsoft.CodeAnalysis.Options

Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework

Expand Down Expand Up @@ -78,7 +79,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr

<ImportingConstructor>
Public Sub New(exportProvider As Composition.ExportProvider)
MyBase.New(exportProvider, exportProvider.GetExportedValue(Of MockServiceProvider))
MyBase.New(exportProvider,
exportProvider.GetExportedValue(Of MockServiceProvider),
exportProvider.GetExportedValues(Of IDocumentOptionsProviderFactory))
End Sub

Public Overrides Sub DisplayReferencedSymbols(solution As Microsoft.CodeAnalysis.Solution, referencedSymbols As IEnumerable(Of ReferencedSymbol))
Expand Down

0 comments on commit 15b43b3

Please sign in to comment.