提交 8b62f184 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #15552 from CyrusNajmabadi/docCommentHandler2

Remove dependency between DocComment insertion and Completion.
......@@ -18,6 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.DocumentationComments
{
[ExportCommandHandler(PredefinedCommandHandlerNames.DocumentationComments, ContentTypeNames.CSharpContentType)]
[Order(After = PredefinedCommandHandlerNames.Rename)]
[Order(After = PredefinedCommandHandlerNames.Completion)]
internal class DocumentationCommentCommandHandler
: AbstractDocumentationCommentCommandHandler<DocumentationCommentTriviaSyntax, MemberDeclarationSyntax>
{
......@@ -25,16 +26,12 @@ internal class DocumentationCommentCommandHandler
public DocumentationCommentCommandHandler(
IWaitIndicator waitIndicator,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
IAsyncCompletionService completionService) :
base(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService, completionService)
IEditorOperationsFactoryService editorOperationsFactoryService)
: base(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService)
{
}
protected override string ExteriorTriviaText
{
get { return "///"; }
}
protected override string ExteriorTriviaText => "///";
protected override MemberDeclarationSyntax GetContainingMember(
SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)
......
......@@ -1886,10 +1886,9 @@ protected override char DocumentationCommentCharacter
internal override ICommandHandler CreateCommandHandler(
IWaitIndicator waitIndicator,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
IAsyncCompletionService completionService)
IEditorOperationsFactoryService editorOperationsFactoryService)
{
return new DocumentationCommentCommandHandler(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService, completionService);
return new DocumentationCommentCommandHandler(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService);
}
protected override Task<TestWorkspace> CreateTestWorkspaceAsync(string code)
......@@ -1897,4 +1896,4 @@ protected override Task<TestWorkspace> CreateTestWorkspaceAsync(string code)
return TestWorkspace.CreateCSharpAsync(code);
}
}
}
}
\ No newline at end of file
......@@ -7,7 +7,8 @@ namespace Microsoft.CodeAnalysis.Editor.CommandHandlers
{
[Export]
[ExportCommandHandler(PredefinedCommandHandlerNames.Completion, ContentTypeNames.RoslynContentType)]
[Order(After = PredefinedCommandHandlerNames.SignatureHelp)]
[Order(After = PredefinedCommandHandlerNames.SignatureHelp,
Before = PredefinedCommandHandlerNames.DocumentationComments)]
internal sealed class CompletionCommandHandler : AbstractCompletionCommandHandler
{
[ImportingConstructor]
......
......@@ -8,8 +8,6 @@ namespace Microsoft.CodeAnalysis.Editor
{
internal interface IAsyncCompletionService
{
bool WaitForComputation(ITextView textView, ITextBuffer subjectBuffer);
bool TryGetController(ITextView textView, ITextBuffer subjectBuffer, out Controller controller);
}
}
......@@ -32,23 +32,19 @@ internal abstract class AbstractDocumentationCommentCommandHandler<TDocumentatio
private readonly IWaitIndicator _waitIndicator;
private readonly ITextUndoHistoryRegistry _undoHistoryRegistry;
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
private readonly IAsyncCompletionService _completionService;
protected AbstractDocumentationCommentCommandHandler(
IWaitIndicator waitIndicator,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
IAsyncCompletionService completionService)
IEditorOperationsFactoryService editorOperationsFactoryService)
{
Contract.ThrowIfNull(waitIndicator);
Contract.ThrowIfNull(undoHistoryRegistry);
Contract.ThrowIfNull(editorOperationsFactoryService);
Contract.ThrowIfNull(completionService);
_waitIndicator = waitIndicator;
_undoHistoryRegistry = undoHistoryRegistry;
_editorOperationsFactoryService = editorOperationsFactoryService;
_completionService = completionService;
}
protected abstract string ExteriorTriviaText { get; }
......@@ -518,14 +514,6 @@ public void ExecuteCommand(ReturnKeyCommandArgs args, Action nextHandler)
return;
}
// Finally, wait and see if completion is computing. If it is, we want to allow
// the list to pop up rather than insert a blank line in the buffer.
if (_completionService.WaitForComputation(args.TextView, args.SubjectBuffer))
{
nextHandler();
return;
}
// According to JasonMal, the text undo history is associated with the surface buffer
// in projection buffer scenarios, so the following line's usage of the surface buffer
// is correct.
......
......@@ -67,16 +67,6 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn
_autoBraceCompletionCharSet = new Dictionary<IContentType, ImmutableHashSet<char>>();
}
public bool WaitForComputation(ITextView textView, ITextBuffer subjectBuffer)
{
if (!TryGetController(textView, subjectBuffer, out var controller))
{
return false;
}
return controller.WaitForComputation();
}
public bool TryGetController(ITextView textView, ITextBuffer subjectBuffer, out Controller controller)
{
AssertIsForeground();
......
......@@ -90,18 +90,6 @@ internal partial class Controller :
isDebugger, isImmediateWindow));
}
internal bool WaitForComputation()
{
if (sessionOpt == null)
{
return false;
}
var model = sessionOpt.WaitForModel();
return model != null;
}
private SnapshotPoint GetCaretPointInViewBuffer()
{
AssertIsForeground();
......@@ -125,8 +113,10 @@ internal override void OnModelUpdated(Model modelOpt)
{
var selectedItem = modelOpt.SelectedItem;
var viewSpan = selectedItem == null ? (ViewTextSpan?)null : modelOpt.GetViewBufferSpan(selectedItem.Span);
var triggerSpan = viewSpan == null ? null : modelOpt.GetCurrentSpanInSnapshot(viewSpan.Value, this.TextView.TextSnapshot)
.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive);
var triggerSpan = viewSpan == null
? null
: modelOpt.GetCurrentSpanInSnapshot(viewSpan.Value, this.TextView.TextSnapshot)
.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive);
sessionOpt.PresenterSession.PresentItems(
triggerSpan, modelOpt.FilteredItems, selectedItem,
......
......@@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
......@@ -22,7 +21,7 @@ public abstract class AbstractDocumentationCommentTests
{
protected abstract char DocumentationCommentCharacter { get; }
internal abstract ICommandHandler CreateCommandHandler(IWaitIndicator waitIndicator, ITextUndoHistoryRegistry undoHistoryRegistry, IEditorOperationsFactoryService editorOperationsFactoryService, IAsyncCompletionService completionService);
internal abstract ICommandHandler CreateCommandHandler(IWaitIndicator waitIndicator, ITextUndoHistoryRegistry undoHistoryRegistry, IEditorOperationsFactoryService editorOperationsFactoryService);
protected abstract Task<TestWorkspace> CreateTestWorkspaceAsync(string code);
protected async Task VerifyTypingCharacterAsync(string initialMarkup, string expectedMarkup, bool useTabs = false, bool autoGenerateXmlDocComments = true)
......@@ -30,7 +29,7 @@ protected async Task VerifyTypingCharacterAsync(string initialMarkup, string exp
await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments,
execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) =>
{
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<TypeCharCommandArgs>;
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<TypeCharCommandArgs>;
var commandArgs = new TypeCharCommandArgs(view, view.TextBuffer, DocumentationCommentCharacter);
var nextHandler = CreateInsertTextHandler(view, DocumentationCommentCharacter.ToString());
......@@ -44,7 +43,7 @@ protected async Task VerifyPressingEnterAsync(string initialMarkup, string expec
await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments,
execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) =>
{
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<ReturnKeyCommandArgs>;
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<ReturnKeyCommandArgs>;
var commandArgs = new ReturnKeyCommandArgs(view, view.TextBuffer);
var nextHandler = CreateInsertTextHandler(view, "\r\n");
......@@ -58,7 +57,7 @@ protected async Task VerifyInsertCommentCommandAsync(string initialMarkup, strin
await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments,
execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) =>
{
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<InsertCommentCommandArgs>;
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<InsertCommentCommandArgs>;
var commandArgs = new InsertCommentCommandArgs(view, view.TextBuffer);
Action nextHandler = delegate { };
......@@ -72,7 +71,7 @@ protected async Task VerifyOpenLineAboveAsync(string initialMarkup, string expec
await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments,
execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) =>
{
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<OpenLineAboveCommandArgs>;
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<OpenLineAboveCommandArgs>;
var commandArgs = new OpenLineAboveCommandArgs(view, view.TextBuffer);
Action nextHandler = () =>
......@@ -90,7 +89,7 @@ protected async Task VerifyOpenLineBelowAsync(string initialMarkup, string expec
await VerifyAsync(initialMarkup, expectedMarkup, useTabs, autoGenerateXmlDocComments,
execute: (view, undoHistoryRegistry, editorOperationsFactoryService, completionService) =>
{
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService, completionService) as ICommandHandler<OpenLineBelowCommandArgs>;
var commandHandler = CreateCommandHandler(TestWaitIndicator.Default, undoHistoryRegistry, editorOperationsFactoryService) as ICommandHandler<OpenLineBelowCommandArgs>;
var commandArgs = new OpenLineBelowCommandArgs(view, view.TextBuffer);
Action nextHandler = () =>
......
......@@ -11,6 +11,7 @@ Imports Microsoft.VisualStudio.Utilities
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.DocumentationComments
<ExportCommandHandler(PredefinedCommandHandlerNames.DocumentationComments, ContentTypeNames.VisualBasicContentType)>
<Order(Before:=PredefinedCommandHandlerNames.Commit, After:=PredefinedCommandHandlerNames.Rename)>
<Order(After:=PredefinedCommandHandlerNames.Completion)>
Friend Class DocumentationCommentCommandHandler
Inherits AbstractDocumentationCommentCommandHandler(Of DocumentationCommentTriviaSyntax, DeclarationStatementSyntax)
......@@ -18,10 +19,9 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.DocumentationComments
Public Sub New(
waitIndicator As IWaitIndicator,
undoHistoryRegistry As ITextUndoHistoryRegistry,
editorOperationsFactoryService As IEditorOperationsFactoryService,
completionService As IAsyncCompletionService)
editorOperationsFactoryService As IEditorOperationsFactoryService)
MyBase.New(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService, completionService)
MyBase.New(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService)
End Sub
Protected Overrides ReadOnly Property ExteriorTriviaText As String
......
......@@ -1197,10 +1197,9 @@ End Class
Friend Overrides Function CreateCommandHandler(
waitIndicator As IWaitIndicator,
undoHistoryRegistry As ITextUndoHistoryRegistry,
editorOperationsFactoryService As IEditorOperationsFactoryService,
completionService As IAsyncCompletionService) As ICommandHandler
editorOperationsFactoryService As IEditorOperationsFactoryService) As ICommandHandler
Return New DocumentationCommentCommandHandler(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService, completionService)
Return New DocumentationCommentCommandHandler(waitIndicator, undoHistoryRegistry, editorOperationsFactoryService)
End Function
Protected Overrides Function CreateTestWorkspaceAsync(code As String) As Task(Of TestWorkspace)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册