未验证 提交 bccf2a17 编写于 作者: D David 提交者: GitHub

Merge pull request #45305 from dibarbet/disable_local_completion

Add workspace service for determining if in cloud context
......@@ -5,6 +5,7 @@
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -51,7 +52,8 @@ public bool ExecuteCommand(GoToDefinitionCommandArgs args, CommandExecutionConte
// In Live Share, typescript exports a gotodefinition service that returns no results and prevents the LSP client
// from handling the request. So prevent the local service from handling goto def commands in the remote workspace.
// This can be removed once typescript implements LSP support for goto def.
if (service != null && document.Project.Solution.Workspace.Kind != WorkspaceKind.AnyCodeRoslynWorkspace)
var workspaceContextService = document.Project.Solution.Workspace.Services.GetRequiredService<IWorkspaceContextService>();
if (service != null && !workspaceContextService.IsCloudEnvironmentClient())
{
var caretPos = args.TextView.GetCaretPoint(subjectBuffer);
if (caretPos.HasValue && TryExecuteCommand(document, caretPos.Value, service, context))
......
......@@ -4,6 +4,8 @@
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Text.Editor;
......@@ -23,6 +25,21 @@ internal class ItemManagerProvider : IAsyncCompletionItemManagerProvider
public ItemManagerProvider(RecentItemsManager recentItemsManager)
=> _instance = new ItemManager(recentItemsManager);
public IAsyncCompletionItemManager GetOrCreate(ITextView textView) => _instance;
public IAsyncCompletionItemManager GetOrCreate(ITextView textView)
{
if (textView.TextBuffer.TryGetWorkspace(out var workspace))
{
var workspaceContextService = workspace.Services.GetRequiredService<IWorkspaceContextService>();
// If we're in a cloud environment context, we want to avoid returning a completion item manager.
// Otherwise, we'll interfere with the LSP client manager and disrupt filtering.
if (workspaceContextService.IsCloudEnvironmentClient())
{
return null;
}
}
return _instance;
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.Editor.Shared.Utilities
{
internal interface IWorkspaceContextService : IWorkspaceService
{
/// <summary>
/// Used to determine if running as a client in a cloud connected environment.
/// </summary>
bool IsCloudEnvironmentClient();
}
[ExportWorkspaceService(typeof(IWorkspaceContextService), ServiceLayer.Default), Shared]
internal sealed class DefaultWorkspaceContextService : IWorkspaceContextService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DefaultWorkspaceContextService()
{
}
public bool IsCloudEnvironmentClient() => false;
}
[ExportWorkspaceService(typeof(IWorkspaceContextService), WorkspaceKind.CloudEnvironmentClientWorkspace), Shared]
internal sealed class CloudEnvironmentWorkspaceContextService : IWorkspaceContextService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CloudEnvironmentWorkspaceContextService()
{
}
public bool IsCloudEnvironmentClient() => true;
}
}
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics
{
[ExportIncrementalAnalyzerProvider(
highPriorityForActiveFile: true, name: WellKnownSolutionCrawlerAnalyzers.Diagnostic,
workspaceKinds: new string[] { WorkspaceKind.Host, WorkspaceKind.Interactive, WorkspaceKind.AnyCodeRoslynWorkspace })]
workspaceKinds: new string[] { WorkspaceKind.Host, WorkspaceKind.Interactive, WorkspaceKind.CloudEnvironmentClientWorkspace })]
internal partial class DiagnosticAnalyzerService : IIncrementalAnalyzerProvider
{
public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace)
......
......@@ -85,7 +85,7 @@ internal sealed class RemoteLanguageServiceWorkspace : CodeAnalysis.Workspace, I
IDiagnosticService diagnosticService,
ITableManagerProvider tableManagerProvider,
IThreadingContext threadingContext)
: base(VisualStudioMefHostServices.Create(exportProvider), WorkspaceKind.AnyCodeRoslynWorkspace)
: base(VisualStudioMefHostServices.Create(exportProvider), WorkspaceKind.CloudEnvironmentClientWorkspace)
{
_serviceProvider = serviceProvider;
......
......@@ -23,7 +23,7 @@ public static class WorkspaceKind
internal const string Custom = "Custom";
internal const string Test = nameof(Test);
internal const string AnyCodeRoslynWorkspace = nameof(AnyCodeRoslynWorkspace);
internal const string CloudEnvironmentClientWorkspace = nameof(CloudEnvironmentClientWorkspace);
internal const string RemoteWorkspace = nameof(RemoteWorkspace);
internal const string RemoteTemporaryWorkspace = nameof(RemoteTemporaryWorkspace);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册