Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jan 13, 2022
1 parent 8aad1d7 commit 11fed4f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;

#if CODE_STYLE
using Formatter = Microsoft.CodeAnalysis.Formatting.FormatterHelper;
#else
using Formatter = Microsoft.CodeAnalysis.Formatting.Formatter;
#endif

namespace Microsoft.CodeAnalysis.RemoveUnusedParametersAndValues
{
/// <summary>
Expand Down Expand Up @@ -843,10 +837,11 @@ private async Task<SyntaxNode> AdjustLocalDeclarationsAsync(
// Run formatter prior to invoking IMoveDeclarationNearReferenceService.
#if CODE_STYLE
var provider = GetSyntaxFormattingService();
rootWithTrackedNodes = FormatterHelper.Format(rootWithTrackedNodes, originalDeclStatementsToMoveOrRemove.Select(s => s.Span), provider, options, rules: null, cancellationToken);
#else
var provider = document.Project.Solution.Workspace.Services;
#endif
rootWithTrackedNodes = Formatter.Format(rootWithTrackedNodes, originalDeclStatementsToMoveOrRemove.Select(s => s.Span), provider, options, rules: null, cancellationToken);
#endif

document = document.WithSyntaxRoot(rootWithTrackedNodes);
await OnDocumentUpdatedAsync().ConfigureAwait(false);
Expand Down
8 changes: 0 additions & 8 deletions src/CodeStyle/Core/Analyzers/Formatting/FormatterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// 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;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Utilities;
using static Microsoft.CodeAnalysis.Formatting.FormattingExtensions;

Expand All @@ -19,11 +16,6 @@ namespace Microsoft.CodeAnalysis.Formatting
/// </summary>
internal static class FormatterHelper
{
/// <summary>
/// The annotation used to mark portions of a syntax tree to be formatted.
/// </summary>
public static SyntaxAnnotation Annotation { get; } = new SyntaxAnnotation();

/// <summary>
/// Gets the formatting rules that would be applied if left unspecified.
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions src/Workspaces/Core/Portable/Formatting/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,12 @@ internal static async Task<Document> FormatAsync(Document document, SyntaxAnnota
/// <param name="options">An optional set of formatting options. If these options are not supplied the current set of options from the workspace will be used.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The formatted tree's root node.</returns>
[Obsolete]
public static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
=> Format(node, annotation, workspace, options, rules: null, cancellationToken);

internal static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, HostWorkspaceServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken)
=> Format(node, annotation, services, options, rules: null, cancellationToken);

[Obsolete]
private static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, Workspace workspace, OptionSet? options, IEnumerable<AbstractFormattingRule>? rules, CancellationToken cancellationToken)
{
if (workspace == null)
Expand Down Expand Up @@ -172,7 +170,6 @@ internal static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation,
/// <param name="options">An optional set of formatting options. If these options are not supplied the current set of options from the workspace will be used.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The formatted tree's root node.</returns>
[Obsolete]
public static SyntaxNode Format(SyntaxNode node, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
=> Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), workspace, options, rules: null, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ public IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable<TextSp
rules ??= GetDefaultFormattingRules();

// check what kind of formatting strategy to use
if (AllowDisjointSpanMerging(spansToFormat, options.ShouldUseFormattingSpanCollapse))
{
return FormatMergedSpan(node, options.Options, rules, spansToFormat, cancellationToken);
}
var result = AllowDisjointSpanMerging(spansToFormat, options.ShouldUseFormattingSpanCollapse) ?
FormatMergedSpan(node, options.Options, rules, spansToFormat, cancellationToken) :
FormatIndividually(node, options.Options, rules, spansToFormat, cancellationToken);

return FormatIndividually(node, options.Options, rules, spansToFormat, cancellationToken);
return result;
}

private IFormattingResult FormatMergedSpan(
Expand Down

0 comments on commit 11fed4f

Please sign in to comment.