Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using FQN instead of adding import during ENC session #35194

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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