提交 b8143e51 编写于 作者: C CyrusNajmabadi

Merge pull request #11843 from CyrusNajmabadi/asyncIndentation

Restore the old IIndentationService.
......@@ -21,7 +21,7 @@
namespace Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation
{
[ExportLanguageService(typeof(IIndentationService), LanguageNames.CSharp), Shared]
[ExportLanguageService(typeof(ISynchronousIndentationService), LanguageNames.CSharp), Shared]
internal partial class CSharpIndentationService : AbstractIndentationService
{
private static readonly IFormattingRule s_instance = new FormattingRule();
......
......@@ -150,7 +150,7 @@ private string GetIndentString(SyntaxNode newRoot)
{
var newDocument = Document.WithSyntaxRoot(newRoot);
var indentationService = newDocument.GetLanguageService<IIndentationService>();
var indentationService = newDocument.GetLanguageService<ISynchronousIndentationService>();
var originalLineNumber = SourceText.Lines.GetLineFromPosition(CursorPosition).LineNumber;
var desiredIndentation = indentationService.GetDesiredIndentation(
newDocument, originalLineNumber + 1, CancellationToken);
......
......@@ -128,7 +128,7 @@ internal void ExecuteCommandWorker(ReturnKeyCommandArgs args, CancellationToken
return;
}
var indentationService = document.GetLanguageService<IIndentationService>();
var indentationService = document.GetLanguageService<ISynchronousIndentationService>();
var indentation = indentationService.GetDesiredIndentation(document,
currentPosition.GetContainingLine().LineNumber, cancellationToken);
......
......@@ -13,7 +13,7 @@
namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
{
internal abstract partial class AbstractIndentationService : IIndentationService
internal abstract partial class AbstractIndentationService : ISynchronousIndentationService
{
protected abstract IFormattingRule GetSpecializedIndentationFormattingRule();
......
......@@ -39,6 +39,11 @@ public IndentationResult(int basePosition, int offset) : this()
}
internal interface IIndentationService : ILanguageService
{
Task<IndentationResult?> GetDesiredIndentation(Document document, int lineNumber, CancellationToken cancellationToken);
}
internal interface ISynchronousIndentationService : ILanguageService
{
IndentationResult? GetDesiredIndentation(Document document, int lineNumber, CancellationToken cancellationToken);
}
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
{
......@@ -44,10 +45,23 @@ public void Dispose()
using (Logger.LogBlock(FunctionId.SmartIndentation_Start, cancellationToken))
{
var document = lineToBeIndented.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
var service = document?.GetLanguageService<IIndentationService>();
var result = service?.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
var syncService = document?.GetLanguageService<ISynchronousIndentationService>();
if (syncService != null)
{
var result = syncService.GetDesiredIndentation(document, lineToBeIndented.LineNumber, cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
}
var asyncService = document?.GetLanguageService<IIndentationService>();
if (asyncService != null)
{
var result = asyncService.GetDesiredIndentation(document, lineToBeIndented.LineBreakLength, cancellationToken).WaitAndGetResult(cancellationToken);
return result?.GetIndentation(_textView, lineToBeIndented);
}
return null;
}
}
}
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.VisualStudio.Text
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
<ExportLanguageService(GetType(IIndentationService), LanguageNames.VisualBasic), [Shared]>
<ExportLanguageService(GetType(ISynchronousIndentationService), LanguageNames.VisualBasic), [Shared]>
Partial Friend Class VisualBasicIndentationService
Inherits AbstractIndentationService
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册