未验证 提交 36d71efb 编写于 作者: G Gen Lu 提交者: GitHub

Merge pull request #35194 from genlu/ImportCompletionENC

Using FQN instead of adding import during ENC session
......@@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddImports;
using Microsoft.CodeAnalysis.Debugging;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Formatting;
......@@ -179,7 +180,14 @@ internal override async Task<CompletionChange> GetChangeAsync(Document document,
var containingNamespace = TypeImportCompletionItem.GetContainingNamespace(completionItem);
Debug.Assert(containingNamespace != null);
if (document.Project.Solution.Workspace.CanApplyChange(ApplyChangesKind.ChangeDocument))
if (ShouldCompleteWithFullyQualifyTypeName(document))
{
var fullyQualifiedName = $"{containingNamespace}.{completionItem.DisplayText}";
var change = new TextChange(completionListSpan, fullyQualifiedName);
return CompletionChange.Create(change);
}
else
{
// Find context node so we can use it to decide where to insert using/imports.
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
......@@ -223,14 +231,25 @@ internal override async Task<CompletionChange> GetChangeAsync(Document document,
return CompletionChange.Create(Utilities.Collapse(newText, builder.ToImmutableAndFree()));
}
else
static bool ShouldCompleteWithFullyQualifyTypeName(Document document)
{
// For workspace that doesn't support document change, e.g. DebuggerIntellisense
// we complete the type name in its fully qualified form instead.
var fullyQualifiedName = $"{containingNamespace}.{completionItem.DisplayText}";
var change = new TextChange(completionListSpan, fullyQualifiedName);
var workspace = document.Project.Solution.Workspace;
return CompletionChange.Create(change);
// Certain types of workspace don't support document change, e.g. DebuggerIntellisense
if (!workspace.CanApplyChange(ApplyChangesKind.ChangeDocument))
{
return true;
}
// During an EnC session, adding import is not supported.
var encService = workspace.Services.GetService<IDebuggingWorkspaceService>()?.EditAndContinueServiceOpt;
if (encService?.EditSession != null)
{
return true;
}
return false;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册