提交 ca29d5f1 编写于 作者: C CyrusNajmabadi

Add options to allow us to turn OOP on/off on a per-feature basis.

上级 5ab15397
......@@ -103,6 +103,7 @@
<Compile Include="NavigateTo\AbstractNavigateToSearchService.cs" />
<Compile Include="NavigateTo\INavigateToSearchResult.cs" />
<Compile Include="NavigateTo\INavigateToSearchService.cs" />
<Compile Include="NavigateTo\NavigateToOptions.cs" />
<Compile Include="Navigation\INavigableItem.cs" />
<Compile Include="Navigation\NavigableItemFactory.cs" />
<Compile Include="Navigation\NavigableItemFactory.DeclaredSymbolNavigableItem.cs" />
......
......@@ -44,7 +44,15 @@ internal abstract partial class AbstractNavigateToSearchService
}
}
private static Task<RemoteHostClient> GetRemoteHostClientAsync(Project project, CancellationToken cancellationToken)
=> project.Solution.Workspace.GetRemoteHostClientAsync(cancellationToken);
private static async Task<RemoteHostClient> GetRemoteHostClientAsync(Project project, CancellationToken cancellationToken)
{
var outOfProcessAllowed = project.Solution.Workspace.Options.GetOption(NavigateToOptions.OutOfProcessAllowed);
if (!outOfProcessAllowed)
{
return null;
}
return await project.Solution.Workspace.GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
}
}
}
\ No newline at end of file
// 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 Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.NavigateTo
{
internal static class NavigateToOptions
{
private const string LocalRegistryPath = @"Roslyn\Features\NavigateTo\";
public static readonly Option<bool> OutOfProcessAllowed = new Option<bool>(nameof(NavigateToOptions), nameof(OutOfProcessAllowed), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(OutOfProcessAllowed)));
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Remote
internal static class RemoteHostOptions
{
[ExportOption]
public static readonly Option<bool> RemoteHost = new Option<bool>(nameof(InternalFeatureOnOffOptions), nameof(RemoteHost), defaultValue: true,
public static readonly Option<bool> RemoteHost = new Option<bool>(nameof(InternalFeatureOnOffOptions), nameof(RemoteHost), defaultValue: false,
storageLocations: new LocalUserProfileStorageLocation(InternalFeatureOnOffOptions.LocalRegistryPath + nameof(RemoteHost)));
[ExportOption]
......
......@@ -18,25 +18,30 @@ internal static class SymbolSearchUpdateEngineFactory
public static async Task<ISymbolSearchUpdateEngine> CreateEngineAsync(
Workspace workspace, ISymbolSearchLogService logService, CancellationToken cancellationToken)
{
var client = await workspace.GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
if (client == null)
var outOfProcessAllowed = workspace.Options.GetOption(SymbolSearchOptions.OutOfProcessAllowed);
if (outOfProcessAllowed)
{
return new SymbolSearchUpdateEngine(logService);
}
var client = await workspace.GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
if (client != null)
{
var emptySolution = workspace.CreateSolution(workspace.CurrentSolution.Id);
var emptySolution = workspace.CreateSolution(workspace.CurrentSolution.Id);
// We create a single session and use it for the entire lifetime of this process.
// That single session will be used to do all communication with the remote process.
// This is because each session will cause a new instance of the RemoteSymbolSearchUpdateEngine
// to be created on the remote side. We only want one instance of that type. The
// alternative is to make that type static variable on the remote side. But that's
// much less clean and would make some of the state management much more complex.
var session = await client.CreateServiceSessionAsync(
WellKnownServiceHubServices.RemoteSymbolSearchUpdateEngine,
emptySolution, logService, cancellationToken).ConfigureAwait(false);
// We create a single session and use it for the entire lifetime of this process.
// That single session will be used to do all communication with the remote process.
// This is because each session will cause a new instance of the RemoteSymbolSearchUpdateEngine
// to be created on the remote side. We only want one instance of that type. The
// alternative is to make that type static variable on the remote side. But that's
// much less clean and would make some of the state management much more complex.
var session = await client.CreateServiceSessionAsync(
WellKnownServiceHubServices.RemoteSymbolSearchUpdateEngine,
emptySolution, logService, cancellationToken).ConfigureAwait(false);
return new RemoteUpdateEngine(session);
}
}
return new RemoteUpdateEngine(session);
// Couldn't go out of proc. Just do everything inside the current process.
return new SymbolSearchUpdateEngine(logService);
}
private class RemoteUpdateEngine : ISymbolSearchUpdateEngine
......
// 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 Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.FindSymbols
{
internal static class SymbolFinderOptions
{
private const string LocalRegistryPath = @"Roslyn\Features\SymbolFinder\";
public static readonly Option<bool> OutOfProcessAllowed = new Option<bool>(nameof(SymbolFinderOptions), nameof(OutOfProcessAllowed), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(OutOfProcessAllowed)));
}
}
\ No newline at end of file
......@@ -17,11 +17,12 @@ public static partial class SymbolFinder
Solution solution,
IStreamingFindReferencesProgress progress,
IImmutableSet<Document> documents,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
{
if (symbolAndProjectId.ProjectId == null)
var outOfProcessAllowed = solution.Workspace.Options.GetOption(SymbolFinderOptions.OutOfProcessAllowed);
if (symbolAndProjectId.ProjectId == null || !outOfProcessAllowed)
{
// This is a call through our old public API. We don't have the necessary
// data to effectively run the call out of proc.
......
......@@ -6,7 +6,15 @@ namespace Microsoft.CodeAnalysis.SymbolSearch
{
internal static class SymbolSearchOptions
{
public static readonly Option<bool> Enabled = new Option<bool>(nameof(SymbolSearchOptions), nameof(Enabled), defaultValue: true);
private const string LocalRegistryPath = @"Roslyn\Features\SymbolSearch\";
public static readonly Option<bool> Enabled = new Option<bool>(
nameof(SymbolSearchOptions), nameof(Enabled), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(Enabled)));
public static readonly Option<bool> OutOfProcessAllowed = new Option<bool>(
nameof(SymbolSearchOptions), nameof(OutOfProcessAllowed), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(OutOfProcessAllowed)));
public static PerLanguageOption<bool> SuggestForTypesInReferenceAssemblies =
new PerLanguageOption<bool>(nameof(SymbolSearchOptions), nameof(SuggestForTypesInReferenceAssemblies), defaultValue: false,
......
......@@ -386,6 +386,7 @@
<Compile Include="FindSymbols\FindReferences\StreamingFindReferencesProgress.cs" />
<Compile Include="FindSymbols\IStreamingFindReferencesProgress.cs" />
<Compile Include="FindSymbols\SymbolAndProjectId.cs" />
<Compile Include="FindSymbols\SymbolFinderOptions.cs" />
<Compile Include="FindSymbols\SymbolFinder_Remote.cs" />
<Compile Include="FindSymbols\SymbolTree\SymbolTreeInfo.FirstEntityHandleProvider.cs" />
<Compile Include="FindSymbols\SyntaxTree\IDeclarationInfo.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册