Skip to content

Commit 4c6e1a9

Browse files
authored
Merge pull request #44533 from dotnet/merges/master-to-master-vs-deps
Merge master to master-vs-deps
2 parents f0a9bba + ab680e7 commit 4c6e1a9

File tree

39 files changed

+337
-770
lines changed

39 files changed

+337
-770
lines changed

docs/Language Feature Status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ efforts behind them.
2525
| [Covariant](https://github.com/dotnet/csharplang/issues/49) [Returns](https://github.com/dotnet/csharplang/issues/2844) | [features/covariant-returns](https://github.com/dotnet/roslyn/tree/features/covariant-returns) | [In Progress](https://github.com/dotnet/roslyn/issues/43188) | [gafter](https://github.com/gafter) | [AlekseyTs](https://github.com/AlekseyTs), [agocke](https://github.com/agocke) | [gafter](https://github.com/gafter) |
2626
| [Extension GetEnumerator](https://github.com/dotnet/csharplang/issues/3194) | [features/extension-foreach](https://github.com/dotnet/roslyn/tree/features/extension-foreach) | [In Progress](https://github.com/dotnet/roslyn/issues/43184) | [YairHalberstadt](https://github.com/YairHalberstadt) | [333fred](https://github.com/333fred) | [333fred](https://github.com/333fred) |
2727
| [Module initializers](https://github.com/dotnet/csharplang/blob/master/proposals/module-initializers.md) | [features/module-initializers](https://github.com/dotnet/roslyn/tree/features/module-initializers) | [In progress / design](https://github.com/dotnet/roslyn/issues/40500) | [RikkiGibson](https://github.com/RikkiGibson) [jnm2](https://github.com/jnm2)| [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) |
28-
| [Extending Partial](https://github.com/jaredpar/csharplang/blob/partial/proposals/extending-partial-methods.md) | [features/partial-methods](https://github.com/dotnet/roslyn/tree/features/partial-methods) | [In-Progress](https://github.com/dotnet/roslyn/issues/43795) | [RikkiGibson](https://github.com/RikkiGibson) | [chsienki](https://github.com/chsienki) | [jaredpar](https://github.com/jaredpar) |
28+
| [Extending Partial](https://github.com/jaredpar/csharplang/blob/partial/proposals/extending-partial-methods.md) | [features/partial-methods](https://github.com/dotnet/roslyn/tree/features/partial-methods) | [Merged into 16.7p2](https://github.com/dotnet/roslyn/issues/43795) | [RikkiGibson](https://github.com/RikkiGibson) | [chsienki](https://github.com/chsienki) | [jaredpar](https://github.com/jaredpar) |
2929
| [Top-level statements](https://github.com/dotnet/csharplang/blob/master/proposals/top-level-statements.md) | [features/SimplePrograms](https://github.com/dotnet/roslyn/tree/features/SimplePrograms) | [In-Progress](https://github.com/dotnet/roslyn/issues/43563) | [AlekseyTs](https://github.com/AlekseyTs) | [cston](https://github.com/cston), [RikkiGibson](https://github.com/RikkiGibson) | [MadsTorgersen](https://github.com/MadsTorgersen) |
3030

3131
# C# Next

src/EditorFeatures/TestUtilities/InProcRemoteHostClientFactory.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#nullable enable
6+
7+
using System;
8+
using System.Collections.Immutable;
9+
using System.Composition;
10+
using System.Threading;
11+
using System.Threading.Tasks;
12+
using Microsoft.CodeAnalysis.Execution;
13+
using Microsoft.CodeAnalysis.Host;
14+
using Microsoft.CodeAnalysis.Host.Mef;
15+
using Microsoft.CodeAnalysis.Options;
16+
using Microsoft.CodeAnalysis.Options.Providers;
17+
using Microsoft.CodeAnalysis.Remote;
18+
using Roslyn.Test.Utilities.Remote;
19+
using Roslyn.Utilities;
20+
21+
namespace Microsoft.CodeAnalysis.Test.Utilities.RemoteHost
22+
{
23+
internal static class RemoteHostOptions
24+
{
25+
public static readonly Option2<bool> RemoteHostTest = new Option2<bool>(
26+
nameof(RemoteHostOptions), nameof(RemoteHostTest), defaultValue: false);
27+
}
28+
29+
[ExportOptionProvider, Shared]
30+
internal sealed class RemoteHostOptionsProvider : IOptionProvider
31+
{
32+
[ImportingConstructor]
33+
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
34+
public RemoteHostOptionsProvider()
35+
{
36+
}
37+
38+
public ImmutableArray<IOption> Options { get; } = ImmutableArray.Create<IOption>(
39+
RemoteHostOptions.RemoteHostTest);
40+
}
41+
42+
internal sealed class InProcRemoteHostClientProvider : IRemoteHostClientProvider
43+
{
44+
[ExportWorkspaceServiceFactory(typeof(IRemoteHostClientProvider)), Shared]
45+
internal sealed class Factory : IWorkspaceServiceFactory
46+
{
47+
[ImportingConstructor]
48+
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
49+
public Factory()
50+
{
51+
}
52+
53+
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
54+
=> new InProcRemoteHostClientProvider(workspaceServices);
55+
}
56+
57+
private readonly HostWorkspaceServices _services;
58+
private readonly AsyncLazy<RemoteHostClient?> _lazyClient;
59+
60+
public InProcRemoteHostClientProvider(HostWorkspaceServices services)
61+
{
62+
_services = services;
63+
64+
_lazyClient = new AsyncLazy<RemoteHostClient?>(cancellationToken =>
65+
{
66+
var optionService = _services.GetRequiredService<IOptionService>();
67+
if (optionService.GetOption(RemoteHostOptions.RemoteHostTest))
68+
{
69+
return InProcRemoteHostClient.CreateAsync(_services, runCacheCleanup: false).AsNullable();
70+
}
71+
72+
return SpecializedTasks.Null<RemoteHostClient>();
73+
}, cacheResult: true);
74+
}
75+
76+
public Task<RemoteHostClient?> TryGetRemoteHostClientAsync(CancellationToken cancellationToken)
77+
=> _lazyClient.GetValueAsync(cancellationToken);
78+
}
79+
}

src/EditorFeatures/TestUtilities/Remote/InProcRemostHostClient.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,19 @@ public static async Task<RemoteHostClient> CreateAsync(HostWorkspaceServices ser
3434

3535
var remoteHostStream = await inprocServices.RequestServiceAsync(WellKnownServiceHubService.RemoteHost).ConfigureAwait(false);
3636

37-
var current = CreateClientId(Process.GetCurrentProcess().Id.ToString());
38-
var instance = new InProcRemoteHostClient(current, services, inprocServices, remoteHostStream);
37+
var clientId = CreateClientId(Process.GetCurrentProcess().Id.ToString());
38+
var instance = new InProcRemoteHostClient(clientId, services, inprocServices, remoteHostStream);
3939

4040
// make sure connection is done right
4141
string? telemetrySession = null;
4242
var uiCultureLCIDE = 0;
4343
var cultureLCID = 0;
4444

45-
var host = await instance._endPoint.InvokeAsync<string>(
46-
nameof(IRemoteHostService.Connect),
47-
new object?[] { current, uiCultureLCIDE, cultureLCID, telemetrySession },
45+
await instance._endPoint.InvokeAsync(
46+
nameof(IRemoteHostService.InitializeGlobalState),
47+
new object?[] { clientId, uiCultureLCIDE, cultureLCID, telemetrySession },
4848
CancellationToken.None).ConfigureAwait(false);
4949

50-
// TODO: change this to non fatal watson and make VS to use inproc implementation
51-
Contract.ThrowIfFalse(host == current.ToString());
52-
5350
instance.Started();
5451

5552
// return instance

src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnal
3939
Contract.ThrowIfFalse(compilation.Analyzers.Length != 0);
4040

4141
var workspace = project.Solution.Workspace;
42-
var service = workspace.Services.GetService<IRemoteHostClientService>();
42+
var service = workspace.Services.GetService<IRemoteHostClientProvider>();
4343
if (service == null)
4444
{
4545
// host doesn't support RemoteHostService such as under unit test

src/Tools/ExternalAccess/Razor/RazorRemoteHostClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal RazorRemoteHostClient(RemoteHostClient client)
2222

2323
public static async Task<RazorRemoteHostClient?> CreateAsync(Workspace workspace, CancellationToken cancellationToken = default)
2424
{
25-
var clientFactory = workspace.Services.GetRequiredService<IRemoteHostClientService>();
25+
var clientFactory = workspace.Services.GetRequiredService<IRemoteHostClientProvider>();
2626
var client = await clientFactory.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
2727
return client == null ? null : new RazorRemoteHostClient(client);
2828
}

src/VisualStudio/Core/Def/Implementation/LanguageClient/LanguageServerClient.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ public async Task OnLoadedAsync()
111111
// initialize things on UI thread
112112
await InitializeOnUIAsync().ConfigureAwait(false);
113113

114-
// this might get called before solution is fully loaded and before file is opened.
115-
// we delay our OOP start until then, but user might do vsstart before that. so we make sure we start OOP if
116-
// it is not running yet. multiple start is no-op
117-
((RemoteHostClientServiceFactory.RemoteHostClientService)_services.GetService<IRemoteHostClientService>()).Enable();
118-
119114
// wait until remote host is available before let platform know that they can activate our LSP
120115
var client = await RemoteHostClient.TryGetClientAsync(_services, CancellationToken.None).ConfigureAwait(false);
121116
if (client == null)

src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
using System.Threading.Tasks;
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.Packaging;
11-
using Microsoft.CodeAnalysis.Remote;
1211
using Microsoft.CodeAnalysis.SymbolSearch;
1312
using Microsoft.VisualStudio.ComponentModelHost;
1413
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
14+
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
1515
using Microsoft.VisualStudio.LanguageServices.Packaging;
16-
using Microsoft.VisualStudio.LanguageServices.Remote;
1716
using Microsoft.VisualStudio.LanguageServices.SymbolSearch;
1817
using Microsoft.VisualStudio.Shell;
1918
using Microsoft.VisualStudio.Shell.Interop;
@@ -76,11 +75,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
7675
RegisterMiscellaneousFilesWorkspaceInformation(miscellaneousFilesWorkspace);
7776

7877
this.Workspace = this.CreateWorkspace();
79-
if (await IsInIdeModeAsync(this.Workspace).ConfigureAwait(true))
78+
if (IsInIdeMode(this.Workspace))
8079
{
81-
// start remote host
82-
EnableRemoteHostClientService();
83-
8480
// not every derived package support object browser and for those languages
8581
// this is a no op
8682
await RegisterObjectBrowserLibraryManagerAsync(cancellationToken).ConfigureAwait(true);
@@ -132,15 +128,10 @@ protected override void Dispose(bool disposing)
132128
{
133129
if (disposing)
134130
{
135-
ThreadHelper.JoinableTaskFactory.Run(async () =>
131+
if (IsInIdeMode(Workspace))
136132
{
137-
if (await IsInIdeModeAsync(this.Workspace).ConfigureAwait(true))
138-
{
139-
DisableRemoteHostClientService();
140-
141-
await UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None).ConfigureAwait(true);
142-
}
143-
});
133+
ThreadHelper.JoinableTaskFactory.Run(async () => await UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None).ConfigureAwait(true));
134+
}
144135

145136
// If we've created the language service then tell it it's time to clean itself up now.
146137
if (_languageService != null)
@@ -169,27 +160,7 @@ protected virtual Task UnregisterObjectBrowserLibraryManagerAsync(CancellationTo
169160
return Task.CompletedTask;
170161
}
171162

172-
private async Task<bool> IsInIdeModeAsync(Workspace workspace)
173-
=> workspace != null && !await IsInCommandLineModeAsync().ConfigureAwait(true);
174-
175-
private async Task<bool> IsInCommandLineModeAsync()
176-
{
177-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
178-
179-
var shell = (IVsShell)await GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true);
180-
181-
if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out var result)))
182-
{
183-
return (bool)result;
184-
}
185-
186-
return false;
187-
}
188-
189-
private void EnableRemoteHostClientService()
190-
=> ((RemoteHostClientServiceFactory.RemoteHostClientService)this.Workspace.Services.GetService<IRemoteHostClientService>()).Enable();
191-
192-
private void DisableRemoteHostClientService()
193-
=> ((RemoteHostClientServiceFactory.RemoteHostClientService)this.Workspace.Services.GetService<IRemoteHostClientService>()).Disable();
163+
private static bool IsInIdeMode(Workspace workspace)
164+
=> workspace != null && !IVsShellExtensions.IsInCommandLineMode;
194165
}
195166
}

src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostClientFactory.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)