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

Run final fix-all code-cleanup phase out of process. #73357

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b18d8e3
Initial work
CyrusNajmabadi May 6, 2024
bc0d554
Perform fix-all code cleanup in oop instead of locally
CyrusNajmabadi May 6, 2024
e5f7172
Merge remote-tracking branch 'upstream/main' into codeCleanupOop
CyrusNajmabadi May 7, 2024
5915357
Fix
CyrusNajmabadi May 7, 2024
8c4c916
Merge branch 'sortServices' into codeCleanupOop
CyrusNajmabadi May 7, 2024
7b8034f
Fix test
CyrusNajmabadi May 7, 2024
4684c58
Merge branch 'runOopByDefault' into codeCleanupOop
CyrusNajmabadi May 7, 2024
09f7852
in progress
CyrusNajmabadi May 7, 2024
38f6bec
REvert
CyrusNajmabadi May 7, 2024
b086dad
in progress
CyrusNajmabadi May 7, 2024
000e0c9
in progress
CyrusNajmabadi May 7, 2024
15370f7
in progress
CyrusNajmabadi May 7, 2024
6f2b8aa
in progress
CyrusNajmabadi May 7, 2024
33155df
Merge branch 'runOopByDefault' into codeCleanupOop
CyrusNajmabadi May 7, 2024
1087b27
Merge branch 'main' into codeCleanupOop
CyrusNajmabadi May 8, 2024
3e976eb
do syntax locally
CyrusNajmabadi May 8, 2024
1ecdf6f
fix formatting
CyrusNajmabadi May 8, 2024
659c1a7
Merge branch 'cleanupSyntax' into codeCleanupOop
CyrusNajmabadi May 8, 2024
4f2236d
Merge branch 'cleanupSyntax' into codeCleanupOop
CyrusNajmabadi May 8, 2024
47537c2
Merge branch 'cleanupSyntax' into codeCleanupOop
CyrusNajmabadi May 8, 2024
fe9c849
spans
CyrusNajmabadi May 8, 2024
0bff033
fix parentheses removal
CyrusNajmabadi May 8, 2024
5b0a201
Merge branch 'main' into codeCleanupOop
CyrusNajmabadi May 8, 2024
dcb2bc4
Merge branch 'usePatternFix' into codeCleanupOop
CyrusNajmabadi May 8, 2024
7227822
in progress
CyrusNajmabadi May 8, 2024
9844268
Merge branch 'main' into codeCleanupOop
CyrusNajmabadi May 13, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract partial class CodeAction
static (document, options, cancellationToken) => CleanupSyntaxAsync(document, options, cancellationToken),
];

private static async Task<Document> CleanupSyntaxAsync(Document document, CodeCleanupOptions options, CancellationToken cancellationToken)
internal static async Task<Document> CleanupSyntaxAsync(Document document, CodeCleanupOptions options, CancellationToken cancellationToken)
{
Contract.ThrowIfFalse(document.SupportsSyntaxTree);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixesAndRefactorings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public partial class FixAllContext : IFixAllContext
public IProgress<CodeAnalysisProgress> Progress { get; }

#region IFixAllContext implementation

IFixAllState IFixAllContext.State => this.State;

IFixAllProvider IFixAllContext.FixAllProvider => this.FixAllProvider;
Expand All @@ -88,6 +89,7 @@ IFixAllContext IFixAllContext.With(
Optional<string?> codeActionEquivalenceKey,
Optional<CancellationToken> cancellationToken)
=> this.With(documentAndProject, scope, codeActionEquivalenceKey, cancellationToken);

#endregion

/// <summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

using System;
using System.Threading;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.CodeFixesAndRefactorings;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.CodeFixesAndRefactorings;

internal interface IRemoteFixAllProviderService
{
ValueTask<string> PerformSemanticCleanupAsync(
Checksum solutionChecksum, DocumentId documentId, CodeCleanupOptions codeCleanupOptions,
Dictionary<TextSpan, List<string>> nodeAnnotations, Dictionary<TextSpan, List<string>> tokenAnnotations,
CancellationToken cancellationToken);
}
2 changes: 1 addition & 1 deletion src/Workspaces/Core/Portable/Formatting/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Formatter
/// <summary>
/// The annotation used to mark portions of a syntax tree to be formatted.
/// </summary>
public static SyntaxAnnotation Annotation { get; } = new SyntaxAnnotation();
public static SyntaxAnnotation Annotation { get; } = new();

/// <summary>
/// Gets the formatting rules that would be applied if left unspecified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,11 @@ public static async Task<RemoteKeepAliveSession> CreateAsync(
var client = await RemoteHostClient.TryGetClientAsync(compilationState.Services, cancellationToken).ConfigureAwait(false);
return new RemoteKeepAliveSession(compilationState, client);
}

/// <inheritdoc cref="CreateAsync(Solution, CancellationToken)"/>
public static RemoteKeepAliveSession Create(
SolutionCompilationState compilationState, RemoteHostClient? client)
{
return new RemoteKeepAliveSession(compilationState, client);
}
}
6 changes: 3 additions & 3 deletions src/Workspaces/Core/Portable/Simplification/Simplifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public static partial class Simplifier
/// The annotation the reducer uses to identify sub trees to be reduced.
/// The Expand operations add this annotation to nodes so that the Reduce operations later find them.
/// </summary>
public static SyntaxAnnotation Annotation { get; } = new SyntaxAnnotation();
public static SyntaxAnnotation Annotation { get; } = new();

/// <summary>
/// This is the annotation used by the simplifier and expander to identify Predefined type and preserving
/// them from over simplification
/// </summary>
public static SyntaxAnnotation SpecialTypeAnnotation { get; } = new SyntaxAnnotation();
public static SyntaxAnnotation SpecialTypeAnnotation { get; } = new();

/// <summary>
/// The annotation <see cref="CodeAction.CleanupDocumentAsync"/> used to identify sub trees to look for symbol annotations on.
/// It will then add import directives for these symbol annotations.
/// </summary>
public static SyntaxAnnotation AddImportsAnnotation { get; } = new SyntaxAnnotation();
public static SyntaxAnnotation AddImportsAnnotation { get; } = new();

/// <summary>
/// Expand qualifying parts of the specified subtree, annotating the parts using the <see cref="Annotation" /> annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public InProcRemoteServices(SolutionServices workspaceServices, TraceListener? t
RegisterRemoteBrokeredService(new RemoteEncapsulateFieldService.Factory());
RegisterRemoteBrokeredService(new RemoteExtensionMethodImportCompletionService.Factory());
RegisterRemoteBrokeredService(new RemoteFindUsagesService.Factory());
RegisterRemoteBrokeredService(new RemoteFixAllProviderService.Factory());
RegisterRemoteBrokeredService(new RemoteFullyQualifyService.Factory());
RegisterRemoteBrokeredService(new RemoteGlobalNotificationDeliveryService.Factory());
RegisterRemoteBrokeredService(new RemoteInheritanceMarginService.Factory());
Expand Down
3 changes: 3 additions & 0 deletions src/Workspaces/Remote/Core/RemoteWorkspacesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,7 @@
<data name="FeatureName_SemanticSearch" xml:space="preserve">
<value>Semantic search</value>
</data>
<data name="FeatureName_FixAllProvider" xml:space="preserve">
<value>Fix all provider</value>
</data>
</root>
2 changes: 2 additions & 0 deletions src/Workspaces/Remote/Core/ServiceDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.AddImport;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.CodeFixes.FullyQualify;
using Microsoft.CodeAnalysis.CodeFixesAndRefactorings;
using Microsoft.CodeAnalysis.CodeLens;
using Microsoft.CodeAnalysis.Completion.Providers;
using Microsoft.CodeAnalysis.ConvertTupleToStruct;
Expand Down Expand Up @@ -66,6 +67,7 @@ internal sealed class ServiceDescriptors
(typeof(IRemoteEncapsulateFieldService), typeof(IRemoteEncapsulateFieldService.ICallback)),
(typeof(IRemoteExtensionMethodImportCompletionService), null),
(typeof(IRemoteFindUsagesService), typeof(IRemoteFindUsagesService.ICallback)),
(typeof(IRemoteFixAllProviderService), null),
(typeof(IRemoteFullyQualifyService), null),
(typeof(IRemoteGlobalNotificationDeliveryService), null),
(typeof(IRemoteInheritanceMarginService), null),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.CodeFixesAndRefactorings;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Remote;

internal sealed partial class RemoteFixAllProviderService(in BrokeredServiceBase.ServiceConstructionArguments arguments)
: BrokeredServiceBase(arguments), IRemoteFixAllProviderService
{
internal sealed class Factory : FactoryBase<IRemoteFixAllProviderService>
{
protected override IRemoteFixAllProviderService CreateService(in ServiceConstructionArguments arguments)
=> new RemoteFixAllProviderService(arguments);
}

public ValueTask<string> PerformSemanticCleanupAsync(
Checksum solutionChecksum, DocumentId documentId, CodeCleanupOptions codeCleanupOptions,
Dictionary<TextSpan, List<string>> nodeAnnotations, Dictionary<TextSpan, List<string>> tokenAnnotations,
CancellationToken cancellationToken)
{
return RunServiceAsync(solutionChecksum, async solution =>
{
var document = solution.GetRequiredDocument(documentId);
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

// Add the annotations into our local document.
var updatedRoot = DocumentBasedFixAllProviderHelpers.WithAnnotations(root, nodeAnnotations, tokenAnnotations);
var updatedDocument = document.WithSyntaxRoot(updatedRoot);

var sourceText = await DocumentBasedFixAllProviderHelpers.PerformSemanticCleanupInCurrentProcessAsync(
updatedDocument, codeCleanupOptions, cancellationToken).ConfigureAwait(false);
return sourceText.ToString();
}, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Remote.Diagnostics;
using Microsoft.CodeAnalysis.Shared.Collections;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Telemetry;
using Roslyn.Utilities;
using RoslynLogger = Microsoft.CodeAnalysis.Internal.Log.Logger;

namespace Microsoft.CodeAnalysis.Remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ public static bool CanRemoveParentheses(
if (expression.IsKind(SyntaxKind.ThisExpression))
return true;

// (typeof(int)) -> typeof(int)
// (default(int)) -> default(int)
// (checked(1)) -> checked(1)
// (unchecked(1)) -> unchecked(1)
// (sizeof(int)) -> sizeof(int)
if (expression is TypeOfExpressionSyntax or DefaultExpressionSyntax or CheckedExpressionSyntax or SizeOfExpressionSyntax)
return true;

// x ?? (throw ...) -> x ?? throw ...
if (expression.IsKind(SyntaxKind.ThrowExpression) &&
nodeParent is BinaryExpressionSyntax(SyntaxKind.CoalesceExpression) binary &&
Expand Down
Loading
Loading