提交 38f644f8 编写于 作者: C Cyrus Najmabadi

Move IndentationService down to Feature layer.

上级 18d4c934
......@@ -131,7 +131,7 @@ private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document
public async Task<IList<TextChange>> GetFormattingChangesOnReturnAsync(Document document, int caretPosition, CancellationToken cancellationToken)
{
var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
if (!options.GetOption(FeatureOnOffOptions.AutoFormattingOnReturn))
if (!options.GetOption(FormattingOptions.AutoFormattingOnReturn))
{
return null;
}
......
......@@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Indentation;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation;
using Microsoft.CodeAnalysis.Formatting;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
{
internal static class WhitespaceExtensions
{
#if false
public static bool IsFirstTokenOnLine(this SyntaxToken token, ITextSnapshot snapshot)
{
return token.IsFirstTokenOnLine(snapshot);
}
#endif
}
}
using System;
using System.Linq;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
......@@ -150,7 +149,7 @@ private string GetIndentString(SyntaxNode newRoot)
{
var newDocument = Document.WithSyntaxRoot(newRoot);
var indentationService = (IBlankLineIndentationService)newDocument.GetLanguageService<ISynchronousIndentationService>();
var indentationService = newDocument.GetLanguageService<Indentation.IIndentationService>();
var originalLineNumber = SourceText.Lines.GetLineFromPosition(CursorPosition).LineNumber;
var desiredIndentation = indentationService.GetBlankLineIndentation(
......
......@@ -2,7 +2,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation;
using Microsoft.CodeAnalysis.CSharp.Indentation;
using Microsoft.CodeAnalysis.Editor.Wrapping.BinaryExpression;
namespace Microsoft.CodeAnalysis.Editor.CSharp.Wrapping.BinaryExpression
......
// 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 Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation;
using Microsoft.CodeAnalysis.CSharp.Indentation;
using Microsoft.CodeAnalysis.Editor.Wrapping.SeparatedSyntaxList;
namespace Microsoft.CodeAnalysis.CSharp.Editor.Wrapping.SeparatedSyntaxList
......
......@@ -3,8 +3,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Indentation;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Test.Utilities;
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Indentation;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -139,7 +140,7 @@ internal void ExecuteCommandWorker(ReturnKeyCommandArgs args, CancellationToken
return;
}
var indentationService = document.GetLanguageService<ISynchronousIndentationService>();
var indentationService = document.GetLanguageService<CodeAnalysis.Indentation.IIndentationService>();
var indentation = indentationService.GetDesiredIndentation(document,
currentPosition.GetContainingLine().LineNumber, cancellationToken);
......
// 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.Threading;
using Microsoft.CodeAnalysis.Formatting;
namespace Microsoft.CodeAnalysis.Editor
{
internal interface IBlankLineIndentationService
{
/// <summary>
/// Determines indentation for a blank line (i.e. after hitting enter at the end of a line,
/// or after moving to a blank line).
///
/// Specifically, this function operates as if the line specified by <paramref name="lineNumber"/>
/// is blank. The actual contents of the line do not matter. All indentation information is
/// determined from the previous lines in the document.
///
/// This function will always succeed.
/// </summary>
IndentationResult GetBlankLineIndentation(
Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken);
}
}
// 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;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
......@@ -18,6 +19,7 @@ namespace Microsoft.CodeAnalysis.Editor
/// current line. With this tuple, both forms can be expressed, and the implementor does not
/// have to convert from one to the other.
/// </summary>
[Obsolete("Use Microsoft.CodeAnalysis.Indentation.IndentationResult instead.")]
internal struct IndentationResult
{
/// <summary>
......@@ -36,13 +38,18 @@ public IndentationResult(int basePosition, int offset) : this()
this.BasePosition = basePosition;
this.Offset = offset;
}
public static implicit operator Indentation.IndentationResult(IndentationResult result)
=> new Indentation.IndentationResult(result.BasePosition, result.Offset);
}
[Obsolete("Use Microsoft.CodeAnalysis.Indentation.IIndentationService instead.")]
internal interface IIndentationService : ILanguageService
{
Task<IndentationResult?> GetDesiredIndentation(Document document, int lineNumber, CancellationToken cancellationToken);
}
[Obsolete("Use Microsoft.CodeAnalysis.Indentation.IIndentationService instead.")]
internal interface ISynchronousIndentationService : ILanguageService
{
/// <summary>
......
......@@ -2,7 +2,7 @@
using System;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Indentation;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -10,6 +10,10 @@
using Microsoft.VisualStudio.Text.Editor;
using Roslyn.Utilities;
using NewIndentationService = Microsoft.CodeAnalysis.Indentation.IIndentationService;
using OldIndentationService = Microsoft.CodeAnalysis.Editor.IIndentationService;
using OldSynchronousIndentationService = Microsoft.CodeAnalysis.Editor.ISynchronousIndentationService;
namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
{
internal partial class SmartIndent : ISmartIndent
......@@ -40,21 +44,39 @@ public void Dispose()
using (Logger.LogBlock(FunctionId.SmartIndentation_Start, cancellationToken))
{
var document = lineToBeIndented.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
var syncService = document?.GetLanguageService<ISynchronousIndentationService>();
if (document == null)
{
return null;
}
if (syncService != null)
// First, try to go through the normal feature-layer indentation service.
var newService = document.GetLanguageService<NewIndentationService>();
if (newService != null)
{
var result = syncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
var result = newService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
}
var asyncService = document?.GetLanguageService<IIndentationService>();
if (asyncService != null)
// If we don't have a feature-layer service, try to fall back to the legacy
// editor-feature-layer interfaces.
#pragma warning disable CS0618 // Type or member is obsolete
var oldSyncService = document.GetLanguageService<OldSynchronousIndentationService>();
if (oldSyncService != null)
{
var result = asyncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken).WaitAndGetResult(cancellationToken);
var result = (Indentation.IndentationResult?)oldSyncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
}
var oldAsyncService = document.GetLanguageService<OldIndentationService>();
if (oldAsyncService != null)
{
var result = (Indentation.IndentationResult?)oldAsyncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken).WaitAndGetResult(cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
}
#pragma warning restore CS0618 // Type or member is obsolete
return null;
}
}
......
......@@ -4,7 +4,7 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
namespace Microsoft.CodeAnalysis.Editor.Shared.Extensions
namespace Microsoft.CodeAnalysis.Indentation
{
internal static class SmartIndentExtensions
{
......
......@@ -44,10 +44,6 @@ internal static class FeatureOnOffOptions
nameof(FeatureOnOffOptions), nameof(AutoFormattingOnTyping), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Typing"));
public static readonly PerLanguageOption<bool> AutoFormattingOnReturn = new PerLanguageOption<bool>(
nameof(FeatureOnOffOptions), nameof(AutoFormattingOnReturn), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Return"));
public static readonly PerLanguageOption<bool> AutoFormattingOnCloseBrace = new PerLanguageOption<bool>(
nameof(FeatureOnOffOptions), nameof(AutoFormattingOnCloseBrace), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Close Brace"));
......@@ -107,7 +103,6 @@ internal class FeatureOnOffOptionsProvider : IOptionProvider
FeatureOnOffOptions.AutoInsertBlockCommentStartString,
FeatureOnOffOptions.PrettyListing,
FeatureOnOffOptions.AutoFormattingOnTyping,
FeatureOnOffOptions.AutoFormattingOnReturn,
FeatureOnOffOptions.AutoFormattingOnCloseBrace,
FeatureOnOffOptions.AutoFormattingOnSemicolon,
FeatureOnOffOptions.RenameTrackingPreview,
......
......@@ -21,9 +21,9 @@ namespace Microsoft.CodeAnalysis.Editor.Wrapping
/// </summary>
internal abstract partial class AbstractSyntaxWrapper : ISyntaxWrapper
{
protected IBlankLineIndentationService IndentationService { get; }
protected Indentation.IIndentationService IndentationService { get; }
protected AbstractSyntaxWrapper(IBlankLineIndentationService indentationService)
protected AbstractSyntaxWrapper(Indentation.IIndentationService indentationService)
{
this.IndentationService = indentationService;
}
......
......@@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.Editor.Wrapping.BinaryExpression
{
......@@ -17,7 +16,7 @@ internal abstract partial class AbstractBinaryExpressionWrapper<TBinaryExpressio
private readonly IPrecedenceService _precedenceService;
protected AbstractBinaryExpressionWrapper(
IBlankLineIndentationService indentationService,
Indentation.IIndentationService indentationService,
ISyntaxFactsService syntaxFacts,
IPrecedenceService precedenceService) : base(indentationService)
{
......
......@@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Indentation;
namespace Microsoft.CodeAnalysis.Editor.Wrapping.SeparatedSyntaxList
{
......@@ -30,7 +31,7 @@ internal abstract partial class AbstractSeparatedSyntaxListWrapper<
protected abstract string Wrap_every_item { get; }
protected AbstractSeparatedSyntaxListWrapper(IBlankLineIndentationService indentationService)
protected AbstractSeparatedSyntaxListWrapper(Indentation.IIndentationService indentationService)
: base(indentationService)
{
}
......
......@@ -4,11 +4,11 @@
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation;
using Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Indentation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
......@@ -70,7 +70,7 @@ public abstract class CoreFormatterTestsBase
var indentationLineFromBuffer = snapshot.GetLineFromLineNumber(indentationLine);
var document = workspace.CurrentSolution.Projects.Single().Documents.Single();
var blankLineIndenter = (IBlankLineIndentationService)document.GetLanguageService<ISynchronousIndentationService>();
var blankLineIndenter = document.GetLanguageService<Indentation.IIndentationService>();
var indentStyle = workspace.Options.GetOption(FormattingOptions.SmartIndent, GetLanguageName());
var blankLineIndentResult = blankLineIndenter.GetBlankLineIndentation(
document, indentationLine, indentStyle, CancellationToken.None);
......
......@@ -57,8 +57,8 @@ private static Type[] GetNeutralAndCSharpAndVisualBasicTypes()
typeof(CodeAnalysis.VisualBasic.IntroduceVariable.VisualBasicIntroduceVariableService), // Ensures that BasicFeatures is included in the composition
typeof(CSharp.ContentType.ContentTypeDefinitions), // CSharp Content Type
typeof(VisualBasic.ContentType.ContentTypeDefinitions), // VB Content Type
typeof(VisualBasic.Formatting.Indentation.VisualBasicIndentationService),
typeof(CSharp.Formatting.Indentation.CSharpIndentationService),
typeof(CodeAnalysis.VisualBasic.Indentation.VisualBasicIndentationService),
typeof(CodeAnalysis.CSharp.Indentation.CSharpIndentationService),
typeof(CodeAnalysis.CSharp.CSharpCompilationFactoryService),
typeof(CodeAnalysis.VisualBasic.VisualBasicCompilationFactoryService),
typeof(CodeAnalysis.CSharp.CSharpSyntaxTreeFactoryServiceFactory), // CSharpServicesCore
......
......@@ -7,6 +7,7 @@ Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Formatting.Rules
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Indentation
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.VisualStudio.Text.Operations
Imports Microsoft.VisualStudio.Utilities
......@@ -20,8 +21,6 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Friend Class SmartTokenFormatterCommandHandler
Inherits AbstractSmartTokenFormatterCommandHandler
Private ReadOnly _formattingRules As IEnumerable(Of AbstractFormattingRule)
<ImportingConstructor()>
Public Sub New(undoHistoryRegistry As ITextUndoHistoryRegistry,
editorOperationsFactoryService As IEditorOperationsFactoryService)
......
' 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 Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Imports Microsoft.CodeAnalysis.Editor.Wrapping.BinaryExpression
Imports Microsoft.CodeAnalysis.VisualBasic.Indentation
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Wrapping.BinaryExpression
......
' 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 Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Imports Microsoft.CodeAnalysis.Editor.Wrapping.SeparatedSyntaxList
Imports Microsoft.CodeAnalysis.VisualBasic.Indentation
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Wrapping.SeparatedSyntaxList
Partial Friend MustInherit Class AbstractVisualBasicSeparatedSyntaxListWrapper(
......
......@@ -7,6 +7,7 @@ Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.CodeAnalysis.VisualBasic.Indentation
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.VisualStudio.Text.Editor
Imports Moq
......
......@@ -4,21 +4,19 @@
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Formatting;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Indentation;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
namespace Microsoft.CodeAnalysis.CSharp.Indentation
{
internal partial class CSharpIndentationService
{
......
......@@ -4,25 +4,21 @@
using System.Composition;
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation;
using Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Indentation;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
namespace Microsoft.CodeAnalysis.CSharp.Indentation
{
[ExportLanguageService(typeof(ISynchronousIndentationService), LanguageNames.CSharp), Shared]
[ExportLanguageService(typeof(IIndentationService), LanguageNames.CSharp), Shared]
internal sealed partial class CSharpIndentationService : AbstractIndentationService<CompilationUnitSyntax>
{
public static readonly CSharpIndentationService Instance = new CSharpIndentationService();
......@@ -52,7 +48,7 @@ protected override AbstractFormattingRule GetSpecializedIndentationFormattingRul
Contract.ThrowIfNull(formattingRules);
Contract.ThrowIfNull(root);
if (!optionSet.GetOption(FeatureOnOffOptions.AutoFormattingOnReturn, LanguageNames.CSharp))
if (!optionSet.GetOption(FormattingOptions.AutoFormattingOnReturn, LanguageNames.CSharp))
{
return false;
}
......
......@@ -11,9 +11,8 @@
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
namespace Microsoft.CodeAnalysis.Indentation
{
internal abstract partial class AbstractIndentationService<TSyntaxRoot>
{
......
// 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;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
......@@ -12,10 +11,9 @@
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
namespace Microsoft.CodeAnalysis.Indentation
{
internal abstract partial class AbstractIndentationService<TSyntaxRoot>
: ISynchronousIndentationService, IBlankLineIndentationService
internal abstract partial class AbstractIndentationService<TSyntaxRoot> : IIndentationService
where TSyntaxRoot : SyntaxNode, ICompilationUnitSyntax
{
protected abstract AbstractFormattingRule GetSpecializedIndentationFormattingRule();
......
// 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.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.Indentation
{
/// <summary>
/// An indentation result represents where the indent should be placed. It conveys this through
/// a pair of values. A position in the existing document where the indent should be relative,
/// and the number of columns after that the indent should be placed at.
///
/// This pairing provides flexibility to the implementor to compute the indentation results in
/// a variety of ways. For example, one implementation may wish to express indentation of a
/// newline as being four columns past the start of the first token on a previous line. Another
/// may wish to simply express the indentation as an absolute amount from the start of the
/// current line. With this tuple, both forms can be expressed, and the implementor does not
/// have to convert from one to the other.
/// </summary>
internal struct IndentationResult
{
/// <summary>
/// The base position in the document that the indent should be relative to. This position
/// can occur on any line (including the current line, or a previous line).
/// </summary>
public int BasePosition { get; }
/// <summary>
/// The number of columns the indent should be at relative to the BasePosition's column.
/// </summary>
public int Offset { get; }
public IndentationResult(int basePosition, int offset) : this()
{
this.BasePosition = basePosition;
this.Offset = offset;
}
}
internal interface IIndentationService : ILanguageService
{
/// <summary>
/// Determines the desired indentation of a given line. May return <see langword="null"/> if the
/// <paramref name="document"/> does not want any sort of automatic indentation. May also return
/// <see langword="null"/> if the line in question is not blank and thus indentation should
/// be deferred to the formatting command handler to handle.
/// </summary>
IndentationResult? GetDesiredIndentation(Document document, int lineNumber, CancellationToken cancellationToken);
/// <summary>
/// Determines indentation for a blank line (i.e. after hitting enter at the end of a line,
/// or after moving to a blank line).
///
/// Specifically, this function operates as if the line specified by <paramref name="lineNumber"/>
/// is blank. The actual contents of the line do not matter. All indentation information is
/// determined from the previous lines in the document.
///
/// This is often useful for features which want to insert new code at a certain
/// location, indented to the appropriate amount. This allows those features to
/// figure out that position, without having to care about what might already be
/// at that line (or further on in the document).
///
/// This function will always succeed.
/// </summary>
IndentationResult GetBlankLineIndentation(
Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken);
}
}
......@@ -7,8 +7,7 @@ Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
Friend Class SpecialFormattingRule
Inherits CompatAbstractFormattingRule
......
......@@ -3,14 +3,14 @@
Imports System.Threading
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Formatting.Rules
Imports Microsoft.CodeAnalysis.Indentation
Imports Microsoft.CodeAnalysis.LanguageServices
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.CodeAnalysis.VisualBasic.Formatting
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
Partial Friend Class VisualBasicIndentationService
Private Class Indenter
Inherits AbstractIndenter
......
......@@ -2,17 +2,16 @@
Imports System.Composition
Imports System.Threading
Imports Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
Imports Microsoft.CodeAnalysis.Formatting.Rules
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.Indentation
Imports Microsoft.CodeAnalysis.LanguageServices
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
<ExportLanguageService(GetType(ISynchronousIndentationService), LanguageNames.VisualBasic), [Shared]>
Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
<ExportLanguageService(GetType(IIndentationService), LanguageNames.VisualBasic), [Shared]>
Partial Friend NotInheritable Class VisualBasicIndentationService
Inherits AbstractIndentationService(Of CompilationUnitSyntax)
......
......@@ -99,6 +99,9 @@ private static string GetEndOfLineEditorConfigString(string option)
internal static Option<bool> AllowDisjointSpanMerging { get; } = CreateOption(OptionGroup.Default, nameof(AllowDisjointSpanMerging), defaultValue: false);
internal static readonly PerLanguageOption<bool> AutoFormattingOnReturn = CreatePerLanguageOption(OptionGroup.Default, nameof(AutoFormattingOnReturn), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Return"));
static FormattingOptions()
{
// Note that the static constructor executes after all the static field initializers for the options have executed,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册