-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/EditorFeatures/Core/Formatting/IndentationManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
|
||
namespace Microsoft.CodeAnalysis.Formatting | ||
{ | ||
internal static class IndentationManagerExtensions | ||
{ | ||
public static async Task<SyntaxFormattingOptions> GetInferredFormattingOptionsAsync(this IIndentationManagerService indentationManager, Document document, bool explicitFormat, CancellationToken cancellationToken) | ||
{ | ||
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); | ||
var snapshot = text.FindCorrespondingEditorTextSnapshot(); | ||
|
||
var options = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); | ||
if (snapshot == null) | ||
{ | ||
return options; | ||
} | ||
|
||
indentationManager.GetIndentation(snapshot.TextBuffer, explicitFormat, out var convertTabsToSpaces, out var tabSize, out var indentSize); | ||
|
||
return options.With( | ||
useTabs: !convertTabsToSpaces, | ||
indentationSize: indentSize, | ||
tabSize: tabSize); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Tools/ExternalAccess/Razor/RazorAutoFormattingOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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 Microsoft.CodeAnalysis.Formatting; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor | ||
{ | ||
internal readonly struct RazorAutoFormattingOptions | ||
{ | ||
internal readonly AutoFormattingOptions UnderlyingObject; | ||
|
||
public RazorAutoFormattingOptions(AutoFormattingOptions underlyingObject) | ||
=> UnderlyingObject = underlyingObject; | ||
|
||
public RazorAutoFormattingOptions( | ||
FormattingOptions.IndentStyle indentStyle, | ||
bool formatOnReturn, | ||
bool formatOnTyping, | ||
bool formatOnSemicolon, | ||
bool formatOnCloseBrace) | ||
: this(new AutoFormattingOptions( | ||
indentStyle, | ||
FormatOnReturn: formatOnReturn, | ||
FormatOnTyping: formatOnTyping, | ||
FormatOnSemicolon: formatOnSemicolon, | ||
FormatOnCloseBrace: formatOnCloseBrace)) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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; | ||
using System.Composition; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Formatting; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor | ||
{ | ||
[Export(typeof(RazorGlobalOptions)), Shared] | ||
internal sealed class RazorGlobalOptions | ||
{ | ||
private readonly IGlobalOptionService _globalOptions; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public RazorGlobalOptions(IGlobalOptionService globalOptions) | ||
{ | ||
_globalOptions = globalOptions; | ||
} | ||
|
||
public RazorAutoFormattingOptions GetAutoFormattingOptions() | ||
=> new(_globalOptions.GetAutoFormattingOptions(LanguageNames.CSharp)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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. | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor | ||
{ | ||
internal readonly record struct RazorIndentationOptions( | ||
bool UseTabs, | ||
int TabSize, | ||
int IndentationSize); | ||
} |