提交 b55b6793 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #20287 from CyrusNajmabadi/formattingService

Support all roslyn languages in Formatter.FormatAsync(Document)
Fixes #20285
......@@ -60,6 +60,8 @@ private static Type[] GetNeutralAndCSharpAndVisualBasicTypes()
typeof(CodeAnalysis.VisualBasic.FindSymbols.VisualBasicDeclaredSymbolInfoFactoryService),
typeof(CodeAnalysis.CSharp.CSharpSymbolDeclarationService),
typeof(CodeAnalysis.VisualBasic.VisualBasicSymbolDeclarationService),
typeof(CodeAnalysis.CSharp.Formatting.CSharpFormattingService),
typeof(CodeAnalysis.VisualBasic.Formatting.VisualBasicFormattingService),
typeof(CSharp.LanguageServices.CSharpSymbolDisplayServiceFactory),
typeof(CSharp.Interactive.CSharpInteractiveEvaluator),
typeof(VisualBasic.LanguageServices.VisualBasicSymbolDisplayServiceFactory),
......
......@@ -98,6 +98,7 @@
<Compile Include="CodeStyle\TypeStyle\TypeStyleHelper.cs" />
<Compile Include="Composition\CSharpWorkspaceFeatures.cs" />
<Compile Include="Extensions\BaseMethodDeclarationSyntaxExtensions.cs" />
<Compile Include="Formatting\CSharpFormattingService.cs" />
<Compile Include="FindSymbols\CSharpDeclaredSymbolInfoFactoryService.cs" />
<Compile Include="Simplification\Reducers\CSharpDefaultExpressionReducer.Rewriter.cs" />
<Compile Include="Diagnostics\CSharpDiagnosticPropertiesService.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.CSharp.Formatting
{
[ExportLanguageService(typeof(IFormattingService), LanguageNames.CSharp), Shared]
internal class CSharpFormattingService : AbstractFormattingService
{
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Formatting
{
/// <summary>
/// Base implementation of C# and VB formatting services.
/// </summary>
internal abstract class AbstractFormattingService : IFormattingService
{
public Task<Document> FormatAsync(Document document, IEnumerable<TextSpan> spans, OptionSet options, CancellationToken cancellationToken)
=> Formatter.FormatAsync(document, spans, options, rules: null, cancellationToken: cancellationToken);
}
}
\ No newline at end of file
......@@ -15,4 +15,4 @@ internal interface IFormattingResult
IList<TextChange> GetTextChanges(CancellationToken cancellationToken = default(CancellationToken));
SyntaxNode GetFormattedRoot(CancellationToken cancellationToken = default(CancellationToken));
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Formatting
{
internal interface IFormattingService : ILanguageService
{
/// <summary>
/// Formats the whitespace in areas of a document corresponding to multiple non-overlapping spans.
/// </summary>
/// <param name="document">The document to format.</param>
/// <param name="spans">The spans of the document's text to format. If null, the entire document should be formatted.</param>
/// <param name="options">An optional set of formatting options. If these options are not supplied the current set of options from the document's workspace will be used.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The formatted document.</returns>
Task<Document> FormatAsync(Document document, IEnumerable<TextSpan> spans, OptionSet options, CancellationToken cancellationToken);
}
}
\ No newline at end of file
......@@ -208,6 +208,8 @@
<Compile Include="Classification\AbstractClassificationService.cs" />
<Compile Include="Classification\IClassificationService.cs" />
<Compile Include="ExtensionManager\IInfoBarService.cs" />
<Compile Include="Formatting\AbstractFormattingService.cs" />
<Compile Include="Formatting\IFormattingService.cs" />
<Compile Include="Remote\RemoteHostSessionHelpers.cs" />
<Compile Include="Remote\RemoteFeatureOptions.cs" />
</ItemGroup>
......
......@@ -163,6 +163,7 @@
<Compile Include="Formatting\Rules\ElasticTriviaFormattingRule.vb" />
<Compile Include="Formatting\Rules\NodeBasedFormattingRule.vb" />
<Compile Include="Formatting\Rules\StructuredTriviaFormattingRule.vb" />
<Compile Include="Formatting\VisualBasicFormattingService.vb" />
<Compile Include="Formatting\VisualBasicSyntaxFormattingService.vb" />
<Compile Include="LanguageServices\VisualBasicCompilationFactoryService.vb" />
<Compile Include="LanguageServices\VisualBasicCommandLineParserService.vb" />
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Host.Mef
Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
<ExportLanguageService(GetType(IFormattingService), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicFormattingService
Inherits AbstractFormattingService
End Class
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册