From 2e7212a6975f875a172fecb160601e99a3359ea0 Mon Sep 17 00:00:00 2001 From: HeeJae Chang Date: Mon, 24 Jun 2019 17:54:21 -0700 Subject: [PATCH] make sure we only create OB when VS is running in IDE mode. all command line mode (and all its variations) we don't need to create OB --- src/VisualStudio/CSharp/Impl/CSharpPackage.cs | 16 ++-------- .../LanguageService/AbstractPackage`2.cs | 31 ++++++++++++++++--- .../IntegrationTests/CSharp/CSharpBuild.cs | 2 +- .../LanguageService/VisualBasicPackage.vb | 14 ++------- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/VisualStudio/CSharp/Impl/CSharpPackage.cs b/src/VisualStudio/CSharp/Impl/CSharpPackage.cs index d33bf18fa4c60..5f2555eeb5d51 100644 --- a/src/VisualStudio/CSharp/Impl/CSharpPackage.cs +++ b/src/VisualStudio/CSharp/Impl/CSharpPackage.cs @@ -85,8 +85,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke await JoinableTaskFactory.SwitchToMainThreadAsync(ct); return new TempPECompilerService(this.Workspace.Services.GetService()); }); - - await RegisterObjectBrowserLibraryManagerAsync(cancellationToken).ConfigureAwait(true); } catch (Exception e) when (FatalError.ReportUnlessCanceled(e)) { @@ -98,17 +96,7 @@ protected override VisualStudioWorkspaceImpl CreateWorkspace() return this.ComponentModel.GetService(); } - protected override void Dispose(bool disposing) - { - if (disposing) - { - JoinableTaskFactory.Run(() => UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None)); - } - - base.Dispose(disposing); - } - - private async Task RegisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) + protected override async Task RegisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); @@ -123,7 +111,7 @@ private async Task RegisterObjectBrowserLibraryManagerAsync(CancellationToken ca } } - private async Task UnregisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) + protected override async Task UnregisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); diff --git a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs index 9004e7b9990ed..9b0b0ca1cfd37 100644 --- a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs +++ b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs @@ -90,6 +90,10 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke // start remote host EnableRemoteHostClientService(); + + // not every derived package support object browser and for those languages + // this is a no op + await RegisterObjectBrowserLibraryManagerAsync(cancellationToken).ConfigureAwait(true); } LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget(); @@ -147,12 +151,17 @@ protected override void Dispose(bool disposing) _miscellaneousFilesWorkspace.StopSolutionCrawler(); } - if (ThreadHelper.JoinableTaskFactory.Run(() => IsInIdeModeAsync(this.Workspace, CancellationToken.None))) + ThreadHelper.JoinableTaskFactory.Run(async () => { - this.Workspace.StopSolutionCrawler(); + if (await IsInIdeModeAsync(this.Workspace, CancellationToken.None).ConfigureAwait(true)) + { + this.Workspace.StopSolutionCrawler(); - DisableRemoteHostClientService(); - } + DisableRemoteHostClientService(); + + await UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None).ConfigureAwait(true); + } + }); // If we've created the language service then tell it it's time to clean itself up now. if (_languageService != null) @@ -167,6 +176,20 @@ protected override void Dispose(bool disposing) protected abstract string RoslynLanguageName { get; } + protected virtual Task RegisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) + { + // it is virtual rather than abstract to not break other languages which derived from our + // base package implementations + return Task.CompletedTask; + } + + protected virtual Task UnregisterObjectBrowserLibraryManagerAsync(CancellationToken cancellationToken) + { + // it is virtual rather than abstract to not break other languages which derived from our + // base package implementations + return Task.CompletedTask; + } + private async Task IsInIdeModeAsync(Workspace workspace, CancellationToken cancellationToken) { return workspace != null && !await IsInCommandLineModeAsync(cancellationToken).ConfigureAwait(true); diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpBuild.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpBuild.cs index fe13eb2b2c611..84f4f80e046ad 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpBuild.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpBuild.cs @@ -46,7 +46,7 @@ static void Main(string[] args) // TODO: Validate build works as expected } - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/18204"), Trait(Traits.Feature, Traits.Features.Build)] + [WpfFact, Trait(Traits.Feature, Traits.Features.Build)] public void BuildWithCommandLine() { VisualStudio.SolutionExplorer.SaveAll(); diff --git a/src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.vb b/src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.vb index 97b68159bba56..cc06aad00b010 100644 --- a/src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.vb +++ b/src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.vb @@ -97,21 +97,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic Await JoinableTaskFactory.SwitchToMainThreadAsync(ct) Return New TempPECompilerFactory(workspace) End Function) - - Await RegisterObjectBrowserLibraryManagerAsync(cancellationToken).ConfigureAwait(True) Catch ex As Exception When FatalError.ReportUnlessCanceled(ex) End Try End Function - Protected Overrides Sub Dispose(disposing As Boolean) - If disposing Then - JoinableTaskFactory.Run(Function() UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None)) - End If - - MyBase.Dispose(disposing) - End Sub - - Private Async Function RegisterObjectBrowserLibraryManagerAsync(cancellationToken As CancellationToken) As Task + Protected Overrides Async Function RegisterObjectBrowserLibraryManagerAsync(cancellationToken As CancellationToken) As Task Await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken) Dim objectManager = TryCast(Await GetServiceAsync(GetType(SVsObjectManager)).ConfigureAwait(True), IVsObjectManager2) @@ -124,7 +114,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic End If End Function - Private Async Function UnregisterObjectBrowserLibraryManagerAsync(cancellationToken As CancellationToken) As Task + Protected Overrides Async Function UnregisterObjectBrowserLibraryManagerAsync(cancellationToken As CancellationToken) As Task Await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken) If _libraryManagerCookie <> 0 Then