Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
c1bc775
Merge branch 'updateVersions2' into autoApplyFixes
CyrusNajmabadi Jun 12, 2025
4fa5aa2
Merge branch 'speculativeEdits' into autoApplyFixes
CyrusNajmabadi Jun 12, 2025
f8b927e
Merge branch 'speculativeEdits' into autoApplyFixes
CyrusNajmabadi Jun 12, 2025
d3bc8a8
Merge branch 'speculativeEdits' into autoApplyFixes
CyrusNajmabadi Jun 12, 2025
29335ba
In progress
CyrusNajmabadi Jun 12, 2025
94680d8
Helper utility
CyrusNajmabadi Jun 12, 2025
4529f2c
in progress
CyrusNajmabadi Jun 13, 2025
e0d0e7b
MOre changes
CyrusNajmabadi Jun 13, 2025
1eb7768
Add service
CyrusNajmabadi Jun 13, 2025
6471bb8
Proposal adjustment
CyrusNajmabadi Jun 13, 2025
1cc2127
Fallback to the original set
CyrusNajmabadi Jun 13, 2025
daee2c6
Use helper
CyrusNajmabadi Jun 13, 2025
cf24809
Merge remote-tracking branch 'upstream/main' into autoApplyFixes
CyrusNajmabadi Jun 13, 2025
6ab76b2
Fix
CyrusNajmabadi Jun 13, 2025
6987ce6
Fix
CyrusNajmabadi Jun 13, 2025
df2bd2b
Merge branch 'main' into autoApplyFixes
CyrusNajmabadi Jun 13, 2025
1f25cd3
Share code
CyrusNajmabadi Jun 13, 2025
724f431
Share code
CyrusNajmabadi Jun 13, 2025
242d586
fix remote side
CyrusNajmabadi Jun 13, 2025
0906d40
Add tests
CyrusNajmabadi Jun 13, 2025
c06d131
Add tets
CyrusNajmabadi Jun 13, 2025
dc80262
Add vb tests
CyrusNajmabadi Jun 13, 2025
fdbdba5
Document cleaning
CyrusNajmabadi Jun 13, 2025
483bc78
Downstream
CyrusNajmabadi Jun 13, 2025
f05e09b
Always do syntax
CyrusNajmabadi Jun 13, 2025
f89f9c2
Always do syntax after
CyrusNajmabadi Jun 13, 2025
39dd692
Adjust before and after
CyrusNajmabadi Jun 13, 2025
95ec949
Add telemetry
CyrusNajmabadi Jun 13, 2025
092b807
Merge branch 'speculativeEdits' into autoApplyFixes
CyrusNajmabadi Jun 13, 2025
6485f02
Add speculative edits api
CyrusNajmabadi Jun 2, 2025
b5bc4cc
in progress
CyrusNajmabadi Jun 2, 2025
fd9fce5
Complete implemetnation
CyrusNajmabadi Jun 2, 2025
006f684
Comment
CyrusNajmabadi Jun 2, 2025
644412d
Add threading constraints
CyrusNajmabadi Jun 2, 2025
ea3e7c6
Separate
CyrusNajmabadi Jun 2, 2025
8ed74b8
Remove UI dep
CyrusNajmabadi Jun 2, 2025
ed224ca
Call into base
CyrusNajmabadi Jun 2, 2025
cd20aab
update versions
CyrusNajmabadi Jun 12, 2025
fefcc9e
Simplify
CyrusNajmabadi Jun 12, 2025
3f08874
update versions
CyrusNajmabadi Jun 12, 2025
ffecfcb
Simplify
CyrusNajmabadi Jun 12, 2025
e3ca928
Simplify
CyrusNajmabadi Jun 12, 2025
6c24a94
In progress
CyrusNajmabadi Jun 12, 2025
8a96a21
Helper utility
CyrusNajmabadi Jun 12, 2025
ce27d9e
in progress
CyrusNajmabadi Jun 13, 2025
c70648c
MOre changes
CyrusNajmabadi Jun 13, 2025
289fc9c
Add service
CyrusNajmabadi Jun 13, 2025
9d2c913
Proposal adjustment
CyrusNajmabadi Jun 13, 2025
9818611
Fallback to the original set
CyrusNajmabadi Jun 13, 2025
d5f9490
Use helper
CyrusNajmabadi Jun 13, 2025
5daa687
Fix
CyrusNajmabadi Jun 13, 2025
2822fc9
Fix
CyrusNajmabadi Jun 13, 2025
f47f132
Share code
CyrusNajmabadi Jun 13, 2025
385ed4a
Share code
CyrusNajmabadi Jun 13, 2025
8b212c6
fix remote side
CyrusNajmabadi Jun 13, 2025
6680585
Add tests
CyrusNajmabadi Jun 13, 2025
10402e7
Add tets
CyrusNajmabadi Jun 13, 2025
9e7d073
Add vb tests
CyrusNajmabadi Jun 13, 2025
24fcf8b
Document cleaning
CyrusNajmabadi Jun 13, 2025
2515934
Downstream
CyrusNajmabadi Jun 13, 2025
8e88735
Always do syntax
CyrusNajmabadi Jun 13, 2025
4d5d88e
Always do syntax after
CyrusNajmabadi Jun 13, 2025
6b1f61b
Adjust before and after
CyrusNajmabadi Jun 13, 2025
bbbb52d
Add telemetry
CyrusNajmabadi Jun 13, 2025
f8f6082
Merge branch 'autoApplyFixes' of https://github.com/CyrusNajmabadi/ro…
CyrusNajmabadi Jun 17, 2025
3339942
Merge branch 'speculativeEdits' into autoApplyFixes
CyrusNajmabadi Jun 17, 2025
2e60831
Merge branch 'main-vs-deps' into autoApplyFixes
CyrusNajmabadi Jun 18, 2025
ca44ecf
Merge branch 'main-vs-deps' into autoApplyFixes
CyrusNajmabadi Jun 19, 2025
dad809b
Update src/EditorFeatures/Core/Copilot/CopilotEditorUtilities.cs
CyrusNajmabadi Jun 19, 2025
1dd148e
Update src/EditorFeatures/Core/Copilot/CopilotEditorUtilities.cs
CyrusNajmabadi Jun 19, 2025
f50d4dc
Revert
CyrusNajmabadi Jun 19, 2025
f9b0723
Revert
CyrusNajmabadi Jun 19, 2025
4163d96
Revert
CyrusNajmabadi Jun 19, 2025
507e54d
Update src/Workspaces/Remote/Core/ServiceDescriptors.cs
CyrusNajmabadi Jun 19, 2025
ebf1b1b
Move
CyrusNajmabadi Jun 19, 2025
6e7683f
Add back
CyrusNajmabadi Jun 19, 2025
8eeaa75
Add docs
CyrusNajmabadi Jun 19, 2025
389de64
Docs
CyrusNajmabadi Jun 19, 2025
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
62 changes: 62 additions & 0 deletions src/EditorFeatures/Core/Copilot/CopilotEditorUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.

using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Language.Proposals;
using Microsoft.VisualStudio.Text;

namespace Microsoft.CodeAnalysis.Copilot;

internal static class CopilotEditorUtilities
{
/// <summary>
/// Returns the single roslyn solution snapshot that is affected by the edits in the proposal.
/// </summary>
/// <remarks>
/// Will fail in the event that the edits touch multiple workspaces, or if the edits touch
/// multiple versions of a solution in a workspace (for example, edits to different versions of
/// the same <see cref="ITextSnapshot"/>. Will also fail if this edits non-roslyn files, or files
/// we cannot process semantics for (like non C#/VB files).
/// </remarks>
public static Solution? TryGetAffectedSolution(ProposalBase proposal)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensures the edit is touching only files we can properly analyze within a single roslyn solution snapshot.

{
Solution? solution = null;
foreach (var edit in proposal.Edits)
{
var document = edit.Span.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

// Edit touches a file roslyn doesn't know about. Don't touch this.
if (document is null)
return null;

// Only bother for languages we can actually process semantics for.
if (document.SupportsSemanticModel)
return null;

var currentSolution = document.Project.Solution;

// Edit touches multiple solutions. Don't bother with this for now for simplicity's sake.
if (solution != null && solution != currentSolution)
return null;

solution = currentSolution;
}

return solution;
}

/// <inheritdoc cref="CopilotUtilities.TryNormalizeCopilotTextChanges"/>
public static ImmutableArray<TextChange> TryGetNormalizedTextChanges(IEnumerable<ProposedEdit> edits)
{
using var _ = ArrayBuilder<TextChange>.GetInstance(out var textChanges);
foreach (var edit in edits)
textChanges.Add(new TextChange(edit.Span.Span.ToTextSpan(), edit.ReplacementText));

return CopilotUtilities.TryNormalizeCopilotTextChanges(textChanges);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Threading;
Expand Down Expand Up @@ -106,6 +107,14 @@ private static async ValueTask ProcessCompletionEventAsync(
const string featureId = "Completion";
var proposalId = proposal.ProposalId;

var solution = CopilotEditorUtilities.TryGetAffectedSolution(proposal);
if (solution is null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard helper to make sure this is even a proposal we can consider fixing. will be used by new feature as well.

return;

// We're about to potentially make multiple calls to oop here. So keep a session alive to avoid
// resyncing any data unnecessary.
using var _1 = await RemoteKeepAliveSession.CreateAsync(solution, cancellationToken).ConfigureAwait(false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somethign i noticed while doing work here. can help perf if copilot is suggesting changes to multiple documents.


foreach (var editGroup in proposal.Edits.GroupBy(e => e.Span.Snapshot))
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -116,12 +125,10 @@ private static async ValueTask ProcessCompletionEventAsync(
if (document is null)
continue;

using var _ = PooledObjects.ArrayBuilder<TextChange>.GetInstance(out var textChanges);
foreach (var edit in editGroup)
textChanges.Add(new TextChange(edit.Span.Span.ToTextSpan(), edit.ReplacementText));
var normalizedEdits = CopilotEditorUtilities.TryGetNormalizedTextChanges(editGroup);

await CopilotChangeAnalysisUtilities.AnalyzeCopilotChangeAsync(
document, accepted, featureId, proposalId, textChanges, cancellationToken).ConfigureAwait(false);
document, accepted, featureId, proposalId, normalizedEdits, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,29 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTestGenerator.Api;

[Export]
[Shared]
#pragma warning disable CA1822 // Mark members as static. Existing binary api with UnitTestGenerator.

[Export, Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class UnitTestGeneratorAddMissingImportsFeatureServiceAccessor()
{
#pragma warning disable CA1822 // Mark members as static
internal async Task<Document> AddMissingImportsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();

// Unfortunately, the unit testing system doesn't have a way to report progress.
return await service.AddMissingImportsAsync(document, textSpan, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
}

#pragma warning disable CA1822 // Mark members as static
internal async Task<WrappedMissingImportsAnalysisResult> AnalyzeAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();
var result = await service.AnalyzeAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
var result = await service.AnalyzeAsync(document, textSpan, cleanupDocument: true, cancellationToken).ConfigureAwait(false);
return new WrappedMissingImportsAnalysisResult(result.SelectAsArray(data => new WrappedAddImportFixData(data)));
}

#pragma warning disable CA1822 // Mark members as static
internal async Task<Document> AddMissingImportsAsync(Document document, WrappedMissingImportsAnalysisResult analysisResult, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();
var unwrappedResult = analysisResult.AddImportFixDatas.SelectAsArray(result => result.Underlying);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
searchOptions = searchOptions with { SearchNuGetPackages = false };
}

var addImportOptions = await document.GetAddImportOptionsAsync(searchOptions, cancellationToken).ConfigureAwait(false);
var addImportOptions = await document.GetAddImportOptionsAsync(
searchOptions, cleanupDocument: true, cancellationToken).ConfigureAwait(false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a flag as copilot-fixup wants to add imports without that making other undesired changes to other parts of the document. (specifically, case correcting things in VB).


var fixesForDiagnostic = await addImportService.GetFixesForDiagnosticsAsync(
document, span, diagnostics, MaxResults, symbolSearchService, addImportOptions, packageSources, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private async Task<ImmutableArray<AddImportFixData>> GetFixesInCurrentProcessAsy
{
cancellationToken.ThrowIfCancellationRequested();

var fixData = await reference.TryGetFixDataAsync(document, node, options.CleanupOptions, cancellationToken).ConfigureAwait(false);
var fixData = await reference.TryGetFixDataAsync(
document, node, options.CleanupDocument, options.CleanupOptions, cancellationToken).ConfigureAwait(false);
result.AddIfNotNull(fixData);

if (result.Count > maxResults)
Expand Down
22 changes: 17 additions & 5 deletions src/Features/Core/Portable/AddImport/AddImportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@ namespace Microsoft.CodeAnalysis.AddImport;
internal readonly record struct AddImportOptions(
[property: DataMember(Order = 0)] SymbolSearchOptions SearchOptions,
[property: DataMember(Order = 1)] CodeCleanupOptions CleanupOptions,
[property: DataMember(Order = 2)] MemberDisplayOptions MemberDisplayOptions);
[property: DataMember(Order = 2)] MemberDisplayOptions MemberDisplayOptions,
[property: DataMember(Order = 3)] bool CleanupDocument);

internal static class AddImportOptionsProviders
{
public static AddImportOptions GetAddImportOptions(this IOptionsReader options, LanguageServices languageServices, SymbolSearchOptions searchOptions, bool allowImportsInHiddenRegions)
public static AddImportOptions GetAddImportOptions(
this IOptionsReader options,
LanguageServices languageServices,
SymbolSearchOptions searchOptions,
bool allowImportsInHiddenRegions,
bool cleanupDocument)
=> new()
{
SearchOptions = searchOptions,
CleanupOptions = options.GetCodeCleanupOptions(languageServices, allowImportsInHiddenRegions),
MemberDisplayOptions = options.GetMemberDisplayOptions(languageServices.Language)
MemberDisplayOptions = options.GetMemberDisplayOptions(languageServices.Language),
CleanupDocument = cleanupDocument,
};

public static async ValueTask<AddImportOptions> GetAddImportOptionsAsync(this Document document, SymbolSearchOptions searchOptions, CancellationToken cancellationToken)
public static async ValueTask<AddImportOptions> GetAddImportOptionsAsync(
this Document document,
SymbolSearchOptions searchOptions,
bool cleanupDocument,
CancellationToken cancellationToken)
{
var configOptions = await document.GetHostAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false);
return configOptions.GetAddImportOptions(document.Project.Services, searchOptions, document.AllowImportsInHiddenRegions());
return configOptions.GetAddImportOptions(
document.Project.Services, searchOptions, document.AllowImportsInHiddenRegions(), cleanupDocument);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ private sealed partial class AssemblyReference(
private readonly ReferenceAssemblyResult _referenceAssemblyWithType = referenceAssemblyWithType;

public override async Task<AddImportFixData> TryGetFixDataAsync(
Document document, SyntaxNode node, CodeCleanupOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode node, bool cleanDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
{
var textChanges = await GetTextChangesAsync(document, node, options, cancellationToken).ConfigureAwait(false);
var textChanges = await GetTextChangesAsync(document, node, cleanDocument, options, cancellationToken).ConfigureAwait(false);

var title = $"{provider.GetDescription(SearchResult.NameParts)} ({string.Format(FeaturesResources.from_0, _referenceAssemblyWithType.AssemblyName)})";
var fullyQualifiedTypeName = string.Join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ private sealed partial class PackageReference(
private readonly string _versionOpt = versionOpt;

public override async Task<AddImportFixData> TryGetFixDataAsync(
Document document, SyntaxNode node, CodeCleanupOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode node, bool cleanupDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
{
var textChanges = await GetTextChangesAsync(
document, node, options, cancellationToken).ConfigureAwait(false);
document, node, cleanupDocument, options, cancellationToken).ConfigureAwait(false);

return AddImportFixData.CreateForPackageSymbol(
textChanges, _source, _packageName, _versionOpt);
Expand Down
16 changes: 12 additions & 4 deletions src/Features/Core/Portable/AddImport/References/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public override int GetHashCode()
}

public abstract Task<AddImportFixData> TryGetFixDataAsync(
Document document, SyntaxNode node, CodeCleanupOptions options, CancellationToken cancellationToken);
Document document, SyntaxNode node, bool cleanupDocument, CodeCleanupOptions options, CancellationToken cancellationToken);

protected async Task<ImmutableArray<TextChange>> GetTextChangesAsync(
Document document, SyntaxNode node, CodeCleanupOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode node, bool cleanupDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
{
// Within an import, we're only adding a package/nuget reference (and we're not going to add another
// using/import as we're already in one). So no need for text changes.
Expand All @@ -116,13 +116,21 @@ protected async Task<ImmutableArray<TextChange>> GetTextChangesAsync(
var newDocument = await provider.AddImportAsync(
node, SearchResult.NameParts, document, options.AddImportOptions, cancellationToken).ConfigureAwait(false);

var cleanedDocument = await CodeAction.CleanupDocumentAsync(
newDocument, options, cancellationToken).ConfigureAwait(false);
var cleanedDocument = await CleanDocumentAsync(newDocument, cleanupDocument, options, cancellationToken).ConfigureAwait(false);

var textChanges = await cleanedDocument.GetTextChangesAsync(
originalDocument, cancellationToken).ConfigureAwait(false);

return [.. textChanges];
}

protected static async Task<Document> CleanDocumentAsync(Document newDocument, bool cleanupDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
{
// We always need to at least cleanup syntax (this ensures spacing of elastic trivia on the new import).
// Optionally cleanup the rest of the document if that is requested.
return cleanupDocument
? await CodeAction.CleanupDocumentAsync(newDocument, options, cancellationToken).ConfigureAwait(false)
: await CodeAction.CleanupSyntaxAsync(newDocument, options, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override int GetHashCode()

private async Task<ImmutableArray<TextChange>> GetTextChangesAsync(
Document document, SyntaxNode contextNode,
CodeCleanupOptions options, bool hasExistingImport,
bool cleanupDocument, CodeCleanupOptions options, bool hasExistingImport,
CancellationToken cancellationToken)
{
// Defer to the language to add the actual import/using.
Expand All @@ -63,8 +63,8 @@ private async Task<ImmutableArray<TextChange>> GetTextChangesAsync(
newContextNode, SymbolResult.Symbol, newDocument,
options.AddImportOptions, cancellationToken).ConfigureAwait(false);

var cleanedDocument = await CodeAction.CleanupDocumentAsync(
updatedDocument, options, cancellationToken).ConfigureAwait(false);
var cleanedDocument = await CleanDocumentAsync(
updatedDocument, cleanupDocument, options, cancellationToken).ConfigureAwait(false);

var textChanges = await cleanedDocument.GetTextChangesAsync(
document, cancellationToken).ConfigureAwait(false);
Expand All @@ -73,8 +73,7 @@ private async Task<ImmutableArray<TextChange>> GetTextChangesAsync(
}

public sealed override async Task<AddImportFixData> TryGetFixDataAsync(
Document document, SyntaxNode node,
CodeCleanupOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode node, bool cleanupDocument, CodeCleanupOptions options, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var (description, hasExistingImport) = GetDescription(document, options, node, semanticModel, cancellationToken);
Expand Down Expand Up @@ -108,7 +107,7 @@ public sealed override async Task<AddImportFixData> TryGetFixDataAsync(
}

var textChanges = await GetTextChangesAsync(
document, node, options, hasExistingImport, cancellationToken).ConfigureAwait(false);
document, node, cleanupDocument, options, hasExistingImport, cancellationToken).ConfigureAwait(false);

return GetFixData(
document, textChanges, description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal abstract class AbstractAddMissingImportsFeatureService : IAddMissingImp
protected abstract ImmutableArray<AbstractFormattingRule> GetFormatRules(SourceText text);

public async Task<ImmutableArray<AddImportFixData>> AnalyzeAsync(
Document document, TextSpan textSpan, CancellationToken cancellationToken)
Document document, TextSpan textSpan, bool cleanDocument, CancellationToken cancellationToken)
{
// Get the diagnostics that indicate a missing import.
var addImportFeatureService = document.GetRequiredLanguageService<IAddImportFeatureService>();
Expand All @@ -53,6 +53,7 @@ public async Task<ImmutableArray<AddImportFixData>> AnalyzeAsync(
SearchReferenceAssemblies = false,
SearchNuGetPackages = false,
},
cleanDocument,
cancellationToken).ConfigureAwait(false);

var unambiguousFixes = await addImportFeatureService.GetUniqueFixesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
// Currently this refactoring requires the SourceTextContainer to have a pasted text span.
var sourceText = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
if (!pasteTrackingService.TryGetPastedTextSpan(sourceText.Container, out var textSpan))
{
return;
}

// Check pasted text span for missing imports
var addMissingImportsService = document.GetRequiredLanguageService<IAddMissingImportsFeatureService>();

var fixData = await addMissingImportsService.AnalyzeAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
var fixData = await addMissingImportsService.AnalyzeAsync(
document, textSpan, cleanupDocument: true, cancellationToken).ConfigureAwait(false);
if (fixData.IsDefaultOrEmpty)
return;

Expand Down
Loading
Loading