Skip to content

Commit

Permalink
Using FQN instead of adding import during ENC session
Browse files Browse the repository at this point in the history
  • Loading branch information
genlu committed Apr 23, 2019
1 parent 88a9c2e commit 612ae1e
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,7 +175,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);
Expand Down Expand Up @@ -218,14 +226,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;
}
}

Expand Down

0 comments on commit 612ae1e

Please sign in to comment.