From 7badcb719a6999eeb05f5529daebd6ff2868aeba Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 09:28:16 -0800 Subject: [PATCH 01/16] remove type with no effect --- ...SignatureHelpAfterCompletionCommandHandler.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs index c999a5dbe5519..b7f80b51c5c9c 100644 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs +++ b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs @@ -33,14 +33,14 @@ namespace Microsoft.CodeAnalysis.Editor.CommandHandlers /// down to those command handlers. /// It is called after . /// - [Export] - [Export(typeof(ICommandHandler))] - [ContentType(ContentTypeNames.RoslynContentType)] - [Name(PredefinedCommandHandlerNames.SignatureHelpAfterCompletion)] - [Order(After = PredefinedCompletionNames.CompletionCommandHandler)] - // Ensure roslyn comes after LSP to allow them to provide results. - // https://github.com/dotnet/roslyn/issues/42338 - [Order(After = "LSP SignatureHelpCommandHandler")] + //[Export] + //[Export(typeof(ICommandHandler))] + //[ContentType(ContentTypeNames.RoslynContentType)] + //[Name(PredefinedCommandHandlerNames.SignatureHelpAfterCompletion)] + //[Order(After = PredefinedCompletionNames.CompletionCommandHandler)] + //// Ensure roslyn comes after LSP to allow them to provide results. + //// https://github.com/dotnet/roslyn/issues/42338 + //[Order(After = "LSP SignatureHelpCommandHandler")] internal class SignatureHelpAfterCompletionCommandHandler : AbstractSignatureHelpCommandHandler, IChainedCommandHandler, From e883fcad30d379561405a3292003d8a9b5df084c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 09:45:37 -0800 Subject: [PATCH 02/16] Remove tests --- .../Controller_NavigationKeys.cs | 92 ++++---- ...natureHelpAfterCompletionCommandHandler.cs | 176 +++++++-------- .../Core/IntelliSense/AbstractController.cs | 39 ++-- .../Core/IntelliSense/ISession.cs | 4 +- .../Core/IntelliSense/ModelComputation.cs | 6 +- .../Core/IntelliSense/Session.cs | 5 +- .../Test2/IntelliSense/ModelTests.vb | 16 +- .../SignatureHelpControllerTests.vb | 211 +++--------------- .../TestUtilities2/Intellisense/TestState.vb | 18 +- 9 files changed, 208 insertions(+), 359 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs index d2730efa02baf..0ded7b117b19b 100644 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs +++ b/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs @@ -11,57 +11,57 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHel { internal partial class Controller { - internal bool TryHandleUpKey() - { - this.ThreadingContext.ThrowIfNotOnUIThread(); - return ChangeSelection(() => sessionOpt.PresenterSession.SelectPreviousItem()); - } + //internal bool TryHandleUpKey() + //{ + // this.ThreadingContext.ThrowIfNotOnUIThread(); + // return ChangeSelection(() => sessionOpt.PresenterSession.SelectPreviousItem()); + //} - internal bool TryHandleDownKey() - { - this.ThreadingContext.ThrowIfNotOnUIThread(); - return ChangeSelection(() => sessionOpt.PresenterSession.SelectNextItem()); - } + //internal bool TryHandleDownKey() + //{ + // this.ThreadingContext.ThrowIfNotOnUIThread(); + // return ChangeSelection(() => sessionOpt.PresenterSession.SelectNextItem()); + //} - private bool ChangeSelection(Action computationAction) - { - this.ThreadingContext.ThrowIfNotOnUIThread(); + //private bool ChangeSelection(Action computationAction) + //{ + // this.ThreadingContext.ThrowIfNotOnUIThread(); - if (!IsSessionActive) - { - // No computation running, so just let the editor handle this. - return false; - } + // if (!IsSessionActive) + // { + // // No computation running, so just let the editor handle this. + // return false; + // } - // If we haven't started our editor session yet, just abort. - // The user hasn't seen a SigHelp presentation yet, so they're - // probably not trying to change the currently visible overload. - if (!sessionOpt.PresenterSession.EditorSessionIsActive) - { - DismissSessionIfActive(); - return false; - } + // // If we haven't started our editor session yet, just abort. + // // The user hasn't seen a SigHelp presentation yet, so they're + // // probably not trying to change the currently visible overload. + // if (!sessionOpt.PresenterSession.EditorSessionIsActive) + // { + // DismissSessionIfActive(); + // return false; + // } - // If we've finished computing the items then use the navigation commands to change the - // selected item. Otherwise, the user was just typing and is now moving through the - // file. In this case stop everything we're doing. - var model = sessionOpt.InitialUnfilteredModel != null ? WaitForController() : null; + // // If we've finished computing the items then use the navigation commands to change the + // // selected item. Otherwise, the user was just typing and is now moving through the + // // file. In this case stop everything we're doing. + // var model = sessionOpt.InitialUnfilteredModel != null ? WaitForController() : null; - // Check if completion is still active. Then update the computation appropriately. - // - // Also, if we only computed one item, then the user doesn't want to select anything - // else. Just stop and let the editor handle the nav character. - if (model != null && model.Items.Count > 1) - { - computationAction(); - return true; - } - else - { - // Dismiss ourselves and actually allow the editor to navigate. - DismissSessionIfActive(); - return false; - } - } + // // Check if completion is still active. Then update the computation appropriately. + // // + // // Also, if we only computed one item, then the user doesn't want to select anything + // // else. Just stop and let the editor handle the nav character. + // if (model != null && model.Items.Count > 1) + // { + // computationAction(); + // return true; + // } + // else + // { + // // Dismiss ourselves and actually allow the editor to navigate. + // DismissSessionIfActive(); + // return false; + // } + //} } } diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs index b7f80b51c5c9c..e807cbe8f6e30 100644 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs +++ b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs @@ -1,101 +1,101 @@ -// 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. +//// 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. -#nullable disable +//#nullable disable -using System; -using System.ComponentModel.Composition; -using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHelp; -using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.VisualStudio.Commanding; -using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion; -using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; -using Microsoft.VisualStudio.Utilities; +//using System; +//using System.ComponentModel.Composition; +//using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHelp; +//using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +//using Microsoft.CodeAnalysis.Host.Mef; +//using Microsoft.CodeAnalysis.Options; +//using Microsoft.VisualStudio.Commanding; +//using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion; +//using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; +//using Microsoft.VisualStudio.Utilities; -namespace Microsoft.CodeAnalysis.Editor.CommandHandlers -{ - /// - /// There are two forms of intellisense that may be active at the same time. Completion and - /// SigHelp. Completion precedes SigHelp in - /// because it wants to make sure - /// it's operating on a buffer *after* Completion has changed it. i.e. if "WriteL(" is typed, - /// sig help wants to allow completion to complete that to "WriteLine(" before it tried to - /// proffer sig help. If we were to reverse things, then we'd get a bogus situation where sig - /// help would see "WriteL(" would have nothing to offer and would return. - /// - /// However, despite wanting sighelp to receive typechar first and then defer it to completion, - /// we want completion to receive other events first (like escape, and navigation keys). We - /// consider completion to have higher priority for those commands. In order to accomplish that, - /// we introduced the current command handler. This command handler then delegates escape, up and - /// down to those command handlers. - /// It is called after . - /// - //[Export] - //[Export(typeof(ICommandHandler))] - //[ContentType(ContentTypeNames.RoslynContentType)] - //[Name(PredefinedCommandHandlerNames.SignatureHelpAfterCompletion)] - //[Order(After = PredefinedCompletionNames.CompletionCommandHandler)] - //// Ensure roslyn comes after LSP to allow them to provide results. - //// https://github.com/dotnet/roslyn/issues/42338 - //[Order(After = "LSP SignatureHelpCommandHandler")] - internal class SignatureHelpAfterCompletionCommandHandler : - AbstractSignatureHelpCommandHandler, - IChainedCommandHandler, - IChainedCommandHandler, - IChainedCommandHandler - { - public string DisplayName => EditorFeaturesResources.Signature_Help; +//namespace Microsoft.CodeAnalysis.Editor.CommandHandlers +//{ +// /// +// /// There are two forms of intellisense that may be active at the same time. Completion and +// /// SigHelp. Completion precedes SigHelp in +// /// because it wants to make sure +// /// it's operating on a buffer *after* Completion has changed it. i.e. if "WriteL(" is typed, +// /// sig help wants to allow completion to complete that to "WriteLine(" before it tried to +// /// proffer sig help. If we were to reverse things, then we'd get a bogus situation where sig +// /// help would see "WriteL(" would have nothing to offer and would return. +// /// +// /// However, despite wanting sighelp to receive typechar first and then defer it to completion, +// /// we want completion to receive other events first (like escape, and navigation keys). We +// /// consider completion to have higher priority for those commands. In order to accomplish that, +// /// we introduced the current command handler. This command handler then delegates escape, up and +// /// down to those command handlers. +// /// It is called after . +// /// +// //[Export] +// //[Export(typeof(ICommandHandler))] +// //[ContentType(ContentTypeNames.RoslynContentType)] +// //[Name(PredefinedCommandHandlerNames.SignatureHelpAfterCompletion)] +// //[Order(After = PredefinedCompletionNames.CompletionCommandHandler)] +// //// Ensure roslyn comes after LSP to allow them to provide results. +// //// https://github.com/dotnet/roslyn/issues/42338 +// //[Order(After = "LSP SignatureHelpCommandHandler")] +// internal class SignatureHelpAfterCompletionCommandHandler : +// AbstractSignatureHelpCommandHandler, +// IChainedCommandHandler, +// IChainedCommandHandler, +// IChainedCommandHandler +// { +// public string DisplayName => EditorFeaturesResources.Signature_Help; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SignatureHelpAfterCompletionCommandHandler( - IThreadingContext threadingContext, - SignatureHelpControllerProvider controllerProvider, - IGlobalOptionService globalOptions) - : base(threadingContext, controllerProvider, globalOptions) - { - } +// [ImportingConstructor] +// [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +// public SignatureHelpAfterCompletionCommandHandler( +// IThreadingContext threadingContext, +// SignatureHelpControllerProvider controllerProvider, +// IGlobalOptionService globalOptions) +// : base(threadingContext, controllerProvider, globalOptions) +// { +// } - public CommandState GetCommandState(EscapeKeyCommandArgs args, Func nextHandler) - => nextHandler(); +// public CommandState GetCommandState(EscapeKeyCommandArgs args, Func nextHandler) +// => nextHandler(); - public CommandState GetCommandState(UpKeyCommandArgs args, Func nextHandler) - => nextHandler(); +// public CommandState GetCommandState(UpKeyCommandArgs args, Func nextHandler) +// => nextHandler(); - public CommandState GetCommandState(DownKeyCommandArgs args, Func nextHandler) - => nextHandler(); +// public CommandState GetCommandState(DownKeyCommandArgs args, Func nextHandler) +// => nextHandler(); - public void ExecuteCommand(EscapeKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) - { - if (TryGetController(args, out var controller) && controller.TryHandleEscapeKey()) - { - return; - } +// //public void ExecuteCommand(EscapeKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) +// //{ +// // if (TryGetController(args, out var controller) && controller.TryHandleEscapeKey()) +// // { +// // return; +// // } - nextHandler(); - } +// // nextHandler(); +// //} - public void ExecuteCommand(UpKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) - { - if (TryGetController(args, out var controller) && controller.TryHandleUpKey()) - { - return; - } +// //public void ExecuteCommand(UpKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) +// //{ +// // if (TryGetController(args, out var controller) && controller.TryHandleUpKey()) +// // { +// // return; +// // } - nextHandler(); - } +// // nextHandler(); +// //} - public void ExecuteCommand(DownKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) - { - if (TryGetController(args, out var controller) && controller.TryHandleDownKey()) - { - return; - } +// //public void ExecuteCommand(DownKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) +// //{ +// // if (TryGetController(args, out var controller) && controller.TryHandleDownKey()) +// // { +// // return; +// // } - nextHandler(); - } - } -} +// // nextHandler(); +// //} +// } +//} diff --git a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs index f240f64e55d4a..52b571ed71240 100644 --- a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs +++ b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs @@ -12,6 +12,7 @@ using Microsoft.VisualStudio.Text.Editor; using Roslyn.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; +using System.Threading.Tasks; namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense; @@ -77,11 +78,11 @@ private void OnTextViewClosed(object sender, EventArgs e) this.TextView.TextBuffer.PostChanged -= this.OnTextViewBufferPostChanged; } - public TModel WaitForController() + public Task WaitForModelComputationAsync() { this.ThreadingContext.ThrowIfNotOnUIThread(); VerifySessionIsActive(); - return sessionOpt.WaitForController(); + return sessionOpt.WaitForModelComputationAsync(); } void IController.OnModelUpdated(TModel result, bool updateController) @@ -137,25 +138,25 @@ public void StopModelComputation() localSession.Stop(); } - public bool TryHandleEscapeKey() - { - this.ThreadingContext.ThrowIfNotOnUIThread(); + //public bool TryHandleEscapeKey() + //{ + // this.ThreadingContext.ThrowIfNotOnUIThread(); - // Escape simply dismissed a session if it's up. Otherwise let the next thing in the - // chain handle us. - if (!IsSessionActive) - { - return false; - } + // // Escape simply dismissed a session if it's up. Otherwise let the next thing in the + // // chain handle us. + // if (!IsSessionActive) + // { + // return false; + // } - // If we haven't even computed a model yet, then also send this command to anyone - // listening. It's unlikely that the command was intended for us (as we wouldn't - // have even shown ui yet. - var handledCommand = sessionOpt.InitialUnfilteredModel != null; + // // If we haven't even computed a model yet, then also send this command to anyone + // // listening. It's unlikely that the command was intended for us (as we wouldn't + // // have even shown ui yet. + // var handledCommand = sessionOpt.InitialUnfilteredModel != null; - // In the presence of an escape, we always stop what we're doing. - this.StopModelComputation(); + // // In the presence of an escape, we always stop what we're doing. + // this.StopModelComputation(); - return handledCommand; - } + // return handledCommand; + //} } diff --git a/src/EditorFeatures/Core/IntelliSense/ISession.cs b/src/EditorFeatures/Core/IntelliSense/ISession.cs index d68a14cdc820e..71b9ffd8e24ac 100644 --- a/src/EditorFeatures/Core/IntelliSense/ISession.cs +++ b/src/EditorFeatures/Core/IntelliSense/ISession.cs @@ -4,6 +4,8 @@ #nullable disable +using System.Threading.Tasks; + namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense; internal interface ISession @@ -12,5 +14,5 @@ internal interface ISession void Stop(); - TModel WaitForController(); + Task WaitForModelComputationAsync(); } diff --git a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs index 114447e876c3d..dcf455d66e08e 100644 --- a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs +++ b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs @@ -81,11 +81,11 @@ public Task ModelTask } } - public TModel WaitForController() + public async Task WaitForModelComputationAsync() { ThreadingContext.ThrowIfNotOnUIThread(); - var model = ModelTask.WaitAndGetResult(CancellationToken.None); + var model = await ModelTask.ConfigureAwait(true); if (!_notifyControllerTask.IsCompleted) { OnModelUpdated(model, updateController: true); @@ -93,8 +93,6 @@ public TModel WaitForController() // Reset lastTask so controller.OnModelUpdated is only called once _lastTask = Task.FromResult(model); } - - return model; } public virtual void Stop() diff --git a/src/EditorFeatures/Core/IntelliSense/Session.cs b/src/EditorFeatures/Core/IntelliSense/Session.cs index 9c63ae8f13eb1..c40bb6948f32b 100644 --- a/src/EditorFeatures/Core/IntelliSense/Session.cs +++ b/src/EditorFeatures/Core/IntelliSense/Session.cs @@ -5,6 +5,7 @@ #nullable disable using System; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Roslyn.Utilities; @@ -52,9 +53,9 @@ public virtual void Stop() this.PresenterSession.Dismiss(); } - public TModel WaitForController() + public Task WaitForModelComputationAsync() { Computation.ThreadingContext.ThrowIfNotOnUIThread(); - return Computation.WaitForController(); + return Computation.WaitForModelComputationAsync(); } } diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb index 4f3770a0fbdcd..de5f85b31cb67 100644 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb @@ -32,10 +32,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Return New TestModelComputation(threadingContext, controller) End Function - - Friend Sub Wait() - WaitForController() - End Sub End Class @@ -55,7 +51,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Sub - Public Sub ChainingTaskThatCompletesNotifiesController() + Public Async Function ChainingTaskThatCompletesNotifiesController() As Task Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) Dim model = New Model() Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) @@ -64,13 +60,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) - modelComputation.Wait() + Await modelComputation.WaitForModelComputationAsync() controller.Verify(Sub(c) c.OnModelUpdated(model, True)) - End Sub + End Function - Public Sub ControllerIsOnlyUpdatedAfterLastTaskCompletes() + Public Async Function ControllerIsOnlyUpdatedAfterLastTaskCompletes() As Task Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) Dim model = New Model() Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) @@ -87,10 +83,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) Monitor.Exit(gate) - modelComputation.Wait() + Await modelComputation.WaitForModelComputationAsync() controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) - End Sub + End Function Public Async Function ControllerIsNotUpdatedIfComputationIsCancelled() As Task diff --git a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb index 0b99ed7563aa2..8d373a5067332 100644 --- a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb @@ -25,61 +25,37 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense <[UseExportProvider]> Public Class SignatureHelpControllerTests - Public Sub InvokeSignatureHelpWithoutDocumentShouldNotStartNewSession() + Public Async Function InvokeSignatureHelpWithoutDocumentShouldNotStartNewSession() As Task Dim emptyProvider = New Mock(Of IDocumentProvider)(MockBehavior.Strict) emptyProvider.Setup(Function(p) p.GetDocument(It.IsAny(Of ITextSnapshot), It.IsAny(Of CancellationToken))).Returns(DirectCast(Nothing, Document)) - Dim controller As Controller = CreateController(CreateWorkspace(), documentProvider:=emptyProvider) + Dim controller As Controller = Await CreateController(CreateWorkspace(), documentProvider:=emptyProvider) GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - controller.WaitForController() + Await controller.WaitForModelComputationAsync() Assert.Equal(0, GetMocks(controller).Provider.GetItemsCount) - End Sub + End Function - Public Sub InvokeSignatureHelpWithDocumentShouldStartNewSession() - Dim controller = CreateController(CreateWorkspace()) + Public Async Function InvokeSignatureHelpWithDocumentShouldStartNewSession() As Task + Dim controller = Await CreateController(CreateWorkspace()) GetMocks(controller).Presenter.Verify(Function(p) p.CreateSession(It.IsAny(Of ITextView), It.IsAny(Of ITextBuffer), It.IsAny(Of ISignatureHelpSession)), Times.Once) - End Sub + End Function - Public Sub EmptyModelShouldStopSession() + Public Async Function EmptyModelShouldStopSession() As Task Dim presenterSession = New Mock(Of ISignatureHelpPresenterSession)(MockBehavior.Strict) presenterSession.Setup(Sub(p) p.Dismiss()) - Dim controller = CreateController(CreateWorkspace(), presenterSession:=presenterSession, items:={}, waitForPresentation:=True) - - GetMocks(controller).PresenterSession.Verify(Sub(p) p.Dismiss(), Times.Once) - End Sub - - - Public Sub UpKeyShouldDismissWhenThereIsOnlyOneItem() - Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(1), waitForPresentation:=True) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - - Dim handled = controller.TryHandleUpKey() + Dim controller = Await CreateController(CreateWorkspace(), presenterSession:=presenterSession, items:={}, waitForPresentation:=True) - Assert.False(handled) GetMocks(controller).PresenterSession.Verify(Sub(p) p.Dismiss(), Times.Once) - End Sub - - - Public Sub UpKeyShouldNavigateWhenThereAreMultipleItems() - Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=True) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.SelectPreviousItem()) - - Dim handled = controller.TryHandleUpKey() - - Assert.True(handled) - GetMocks(controller).PresenterSession.Verify(Sub(p) p.SelectPreviousItem(), Times.Once) - End Sub + End Function - Public Sub UpKeyShouldNotCrashWhenSessionIsDismissed() + Public Async Function UpKeyShouldNotCrashWhenSessionIsDismissed() As Task Dim options = New MemberDisplayOptions() ' Create a provider that will return an empty state when queried the second time @@ -88,7 +64,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense slowProvider.Setup(Function(p) p.IsRetriggerCharacter(" "c)).Returns(True) slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ .Returns(Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing))) - Dim controller = CreateController(CreateWorkspace(), provider:=slowProvider.Object, waitForPresentation:=True) + Dim controller = Await CreateController(CreateWorkspace(), provider:=slowProvider.Object, waitForPresentation:=True) ' Now force an update to the model that will result in stopping the session slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ @@ -97,164 +73,42 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), " "c), Sub() GetMocks(controller).Buffer.Insert(0, " "), TestCommandExecutionContext.Create()) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - - Dim handled = controller.TryHandleUpKey() ' this will block on the model being updated which should dismiss the session - - Assert.False(handled) - GetMocks(controller).PresenterSession.Verify(Sub(p) p.Dismiss(), Times.Once) - End Sub - - - Public Sub DownKeyShouldNotBlockOnModelComputation() - Dim options = New MemberDisplayOptions() - Dim mre = New ManualResetEvent(False) - Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=False) - Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict) - slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ - .Returns(Function() - mre.WaitOne() - Return Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing)) - End Function) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - GetMocks(controller).PresenterSession.Setup(Function(p) p.EditorSessionIsActive).Returns(False) - - Dim handled = controller.TryHandleDownKey() - - Assert.False(handled) - End Sub - - - Public Sub UpKeyShouldNotBlockOnModelComputation() - Dim options = New MemberDisplayOptions() - Dim mre = New ManualResetEvent(False) - Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=False) - Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict) - slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ - .Returns(Function() - mre.WaitOne() - Return Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing)) - End Function) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - GetMocks(controller).PresenterSession.Setup(Function(p) p.EditorSessionIsActive).Returns(False) - - Dim handled = controller.TryHandleUpKey() - - Assert.False(handled) - End Sub - - - Public Async Function UpKeyShouldBlockOnRecomputationAfterPresentation() As Task - Dim options = New MemberDisplayOptions() - Dim workspace = CreateWorkspace() - Dim threadingContext = workspace.GetService(Of IThreadingContext)() - - Dim worker = Async Function() - Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict) - slowProvider.Setup(Function(p) p.IsTriggerCharacter(" "c)).Returns(True) - slowProvider.Setup(Function(p) p.IsRetriggerCharacter(" "c)).Returns(True) - slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ - .Returns(Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing))) - - Await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync() - Dim controller = CreateController(workspace, provider:=slowProvider.Object, waitForPresentation:=True) - - ' Update session so that providers are requeried. - ' SlowProvider now blocks on the checkpoint's task. - Dim checkpoint = New Checkpoint() - slowProvider.Setup(Function(p) p.GetItemsAsync(It.IsAny(Of Document), It.IsAny(Of Integer), It.IsAny(Of SignatureHelpTriggerInfo), options, It.IsAny(Of CancellationToken))) _ - .Returns(Function() - checkpoint.Task.Wait() - Return Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 2), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing)) - End Function) - - Await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync() - DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( - New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), " "c), - Sub() GetMocks(controller).Buffer.Insert(0, " "), TestCommandExecutionContext.Create()) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.SelectPreviousItem()) - - Dim handled = threadingContext.JoinableTaskFactory.RunAsync(Async Function() - Await Task.Yield() - ' Send the controller an up key, which should block on the computation - Return controller.TryHandleUpKey() - End Function) - checkpoint.Release() ' Allow slowprovider to finish - Await handled.JoinAsync().ConfigureAwait(False) - - ' We expect 2 calls to the presenter (because we had an existing presentation session when we started the second computation). - Assert.True(handled.Task.Result) - GetMocks(controller).PresenterSession.Verify(Sub(p) p.PresentItems(It.IsAny(Of ITrackingSpan), It.IsAny(Of IList(Of SignatureHelpItem)), - It.IsAny(Of SignatureHelpItem), It.IsAny(Of Integer?)), Times.Exactly(2)) - End Function - - Await worker().ConfigureAwait(False) - End Function - Public Sub DownKeyShouldNavigateWhenThereAreMultipleItems() - Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=True) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.SelectNextItem()) - - Dim handled = controller.TryHandleDownKey() - - Assert.True(handled) - GetMocks(controller).PresenterSession.Verify(Sub(p) p.SelectNextItem(), Times.Once) - End Sub - - - Public Sub UpAndDownKeysShouldStillNavigateWhenDuplicateItemsAreFiltered() - Dim item = CreateItems(1).Single() - Dim controller = CreateController(CreateWorkspace(), items:={item, item}, waitForPresentation:=True) - - GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - - Dim handled = controller.TryHandleUpKey() - - Assert.False(handled) - GetMocks(controller).PresenterSession.Verify(Sub(p) p.Dismiss(), Times.Once) - End Sub - - - Public Sub CaretMoveWithActiveSessionShouldRecomputeModel() - Dim controller = CreateController(CreateWorkspace(), waitForPresentation:=True) + Public Async Function CaretMoveWithActiveSessionShouldRecomputeModel() As Task + Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True) Mock.Get(GetMocks(controller).View.Object.Caret).Raise(Sub(c) AddHandler c.PositionChanged, Nothing, New CaretPositionChangedEventArgs(Nothing, Nothing, Nothing)) - controller.WaitForController() + Await controller.WaitForModelComputationAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the PositionChanged event Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) - End Sub + End Function - Public Sub RetriggerActiveSessionOnClosingBrace() - Dim controller = CreateController(CreateWorkspace(), waitForPresentation:=True) + Public Async Function RetriggerActiveSessionOnClosingBrace() As Task + Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True) DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), ")"c), Sub() GetMocks(controller).Buffer.Insert(0, ")"), TestCommandExecutionContext.Create()) - controller.WaitForController() + Await controller.WaitForModelComputationAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the typechar command Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) - End Sub + End Function - Public Sub TypingNonTriggerCharacterShouldNotRequestDocument() - Dim controller = CreateController(CreateWorkspace(), triggerSession:=False) + Public Async Function TypingNonTriggerCharacterShouldNotRequestDocument() As Task + Dim controller = Await CreateController(CreateWorkspace(), triggerSession:=False) DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), "a"c), Sub() GetMocks(controller).Buffer.Insert(0, "a"), TestCommandExecutionContext.Create()) GetMocks(controller).DocumentProvider.Verify(Function(p) p.GetDocument(It.IsAny(Of ITextSnapshot), It.IsAny(Of CancellationToken)), Times.Never) - End Sub + End Function Private Shared ReadOnly s_controllerMocksMap As New ConditionalWeakTable(Of Controller, ControllerMocks) Private Shared Function GetMocks(controller As Controller) As ControllerMocks @@ -273,13 +127,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense , composition:=EditorTestCompositions.EditorFeatures) End Function - Private Shared Function CreateController(workspace As TestWorkspace, - Optional documentProvider As Mock(Of IDocumentProvider) = Nothing, - Optional presenterSession As Mock(Of ISignatureHelpPresenterSession) = Nothing, - Optional items As IList(Of SignatureHelpItem) = Nothing, - Optional provider As ISignatureHelpProvider = Nothing, - Optional waitForPresentation As Boolean = False, - Optional triggerSession As Boolean = True) As Controller + Private Shared Async Function CreateController( + workspace As TestWorkspace, + Optional documentProvider As Mock(Of IDocumentProvider) = Nothing, + Optional presenterSession As Mock(Of ISignatureHelpPresenterSession) = Nothing, + Optional items As IList(Of SignatureHelpItem) = Nothing, + Optional provider As ISignatureHelpProvider = Nothing, + Optional waitForPresentation As Boolean = False, + Optional triggerSession As Boolean = True) As Task(Of Controller) Dim document = workspace.CurrentSolution.GetDocument(workspace.Documents.Single().Id) Dim threadingContext = workspace.GetService(Of IThreadingContext) @@ -297,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense provider = New MockSignatureHelpProvider(items) End If - Dim presenter = New Mock(Of IIntelliSensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession))(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock} + Dim presenter = New Mock(Of IIntellisensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession))(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock} presenterSession = If(presenterSession, New Mock(Of ISignatureHelpPresenterSession)(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock}) presenter.Setup(Function(p) p.CreateSession(It.IsAny(Of ITextView), It.IsAny(Of ITextBuffer), It.IsAny(Of ISignatureHelpSession))).Returns(presenterSession.Object) presenterSession.Setup(Sub(p) p.PresentItems(It.IsAny(Of ITrackingSpan), It.IsAny(Of IList(Of SignatureHelpItem)), It.IsAny(Of SignatureHelpItem), It.IsAny(Of Integer?))) _ @@ -330,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of InvokeSignatureHelpCommandArgs)).ExecuteCommand( New InvokeSignatureHelpCommandArgs(view.Object, buffer), Nothing, TestCommandExecutionContext.Create()) If waitForPresentation Then - controller.WaitForController() + Await controller.WaitForModelComputationAsync() End If End If diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index 26ff01d1018b4..e9b084392a39f 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Protected ReadOnly SessionTestState As IIntelliSenseTestState Private ReadOnly SignatureHelpBeforeCompletionCommandHandler As SignatureHelpBeforeCompletionCommandHandler - Protected ReadOnly SignatureHelpAfterCompletionCommandHandler As SignatureHelpAfterCompletionCommandHandler + ' Protected ReadOnly SignatureHelpAfterCompletionCommandHandler As SignatureHelpAfterCompletionCommandHandler Protected ReadOnly CompleteStatementCommandHandler As CompleteStatementCommandHandler Private ReadOnly FormatCommandHandler As FormatCommandHandler @@ -73,7 +73,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Me.SignatureHelpBeforeCompletionCommandHandler = GetExportedValue(Of SignatureHelpBeforeCompletionCommandHandler)() - Me.SignatureHelpAfterCompletionCommandHandler = GetExportedValue(Of SignatureHelpAfterCompletionCommandHandler)() + ' Me.SignatureHelpAfterCompletionCommandHandler = GetExportedValue(Of SignatureHelpAfterCompletionCommandHandler)() Me.CompleteStatementCommandHandler = GetExportedValue(Of CompleteStatementCommandHandler)() Me.FormatCommandHandler = If(includeFormatCommandHandler, GetExportedValue(Of FormatCommandHandler)(), Nothing) @@ -171,23 +171,19 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function Public Overloads Sub SendEscape() - MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() SignatureHelpAfterCompletionCommandHandler.ExecuteCommand(a, n, c), c), Sub() Return) + MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), Sub() Return) End Sub Public Overloads Sub SendDownKey() MyBase.SendDownKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() SignatureHelpAfterCompletionCommandHandler.ExecuteCommand(a, n, c), c), - Sub() - EditorOperations.MoveLineDown(extendSelection:=False) - End Sub) + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineDown(extendSelection:=False), c), + Sub() EditorOperations.MoveLineDown(extendSelection:=False)) End Sub Public Overloads Sub SendUpKey() MyBase.SendUpKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() SignatureHelpAfterCompletionCommandHandler.ExecuteCommand(a, n, c), c), - Sub() - EditorOperations.MoveLineUp(extendSelection:=False) - End Sub) + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineUp(extendSelection:=False), c), + Sub() EditorOperations.MoveLineUp(extendSelection:=False)) End Sub Public Overloads Sub SendPageUp() From cf379babba720975d7b70cb46a340d87828b1818 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 09:45:58 -0800 Subject: [PATCH 03/16] Delete --- ...natureHelpAfterCompletionCommandHandler.cs | 101 ------------------ 1 file changed, 101 deletions(-) delete mode 100644 src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs deleted file mode 100644 index e807cbe8f6e30..0000000000000 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpAfterCompletionCommandHandler.cs +++ /dev/null @@ -1,101 +0,0 @@ -//// 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. - -//#nullable disable - -//using System; -//using System.ComponentModel.Composition; -//using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHelp; -//using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -//using Microsoft.CodeAnalysis.Host.Mef; -//using Microsoft.CodeAnalysis.Options; -//using Microsoft.VisualStudio.Commanding; -//using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion; -//using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; -//using Microsoft.VisualStudio.Utilities; - -//namespace Microsoft.CodeAnalysis.Editor.CommandHandlers -//{ -// /// -// /// There are two forms of intellisense that may be active at the same time. Completion and -// /// SigHelp. Completion precedes SigHelp in -// /// because it wants to make sure -// /// it's operating on a buffer *after* Completion has changed it. i.e. if "WriteL(" is typed, -// /// sig help wants to allow completion to complete that to "WriteLine(" before it tried to -// /// proffer sig help. If we were to reverse things, then we'd get a bogus situation where sig -// /// help would see "WriteL(" would have nothing to offer and would return. -// /// -// /// However, despite wanting sighelp to receive typechar first and then defer it to completion, -// /// we want completion to receive other events first (like escape, and navigation keys). We -// /// consider completion to have higher priority for those commands. In order to accomplish that, -// /// we introduced the current command handler. This command handler then delegates escape, up and -// /// down to those command handlers. -// /// It is called after . -// /// -// //[Export] -// //[Export(typeof(ICommandHandler))] -// //[ContentType(ContentTypeNames.RoslynContentType)] -// //[Name(PredefinedCommandHandlerNames.SignatureHelpAfterCompletion)] -// //[Order(After = PredefinedCompletionNames.CompletionCommandHandler)] -// //// Ensure roslyn comes after LSP to allow them to provide results. -// //// https://github.com/dotnet/roslyn/issues/42338 -// //[Order(After = "LSP SignatureHelpCommandHandler")] -// internal class SignatureHelpAfterCompletionCommandHandler : -// AbstractSignatureHelpCommandHandler, -// IChainedCommandHandler, -// IChainedCommandHandler, -// IChainedCommandHandler -// { -// public string DisplayName => EditorFeaturesResources.Signature_Help; - -// [ImportingConstructor] -// [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -// public SignatureHelpAfterCompletionCommandHandler( -// IThreadingContext threadingContext, -// SignatureHelpControllerProvider controllerProvider, -// IGlobalOptionService globalOptions) -// : base(threadingContext, controllerProvider, globalOptions) -// { -// } - -// public CommandState GetCommandState(EscapeKeyCommandArgs args, Func nextHandler) -// => nextHandler(); - -// public CommandState GetCommandState(UpKeyCommandArgs args, Func nextHandler) -// => nextHandler(); - -// public CommandState GetCommandState(DownKeyCommandArgs args, Func nextHandler) -// => nextHandler(); - -// //public void ExecuteCommand(EscapeKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) -// //{ -// // if (TryGetController(args, out var controller) && controller.TryHandleEscapeKey()) -// // { -// // return; -// // } - -// // nextHandler(); -// //} - -// //public void ExecuteCommand(UpKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) -// //{ -// // if (TryGetController(args, out var controller) && controller.TryHandleUpKey()) -// // { -// // return; -// // } - -// // nextHandler(); -// //} - -// //public void ExecuteCommand(DownKeyCommandArgs args, Action nextHandler, CommandExecutionContext context) -// //{ -// // if (TryGetController(args, out var controller) && controller.TryHandleDownKey()) -// // { -// // return; -// // } - -// // nextHandler(); -// //} -// } -//} From 2b01911d1381e393c20daca72aa318a44ab62891 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 09:47:05 -0800 Subject: [PATCH 04/16] Delete --- .../Controller_NavigationKeys.cs | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs deleted file mode 100644 index 0ded7b117b19b..0000000000000 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/Controller_NavigationKeys.cs +++ /dev/null @@ -1,67 +0,0 @@ -// 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. - -#nullable disable - -using System; -using Microsoft.CodeAnalysis.Editor.Shared.Extensions; - -namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.SignatureHelp -{ - internal partial class Controller - { - //internal bool TryHandleUpKey() - //{ - // this.ThreadingContext.ThrowIfNotOnUIThread(); - // return ChangeSelection(() => sessionOpt.PresenterSession.SelectPreviousItem()); - //} - - //internal bool TryHandleDownKey() - //{ - // this.ThreadingContext.ThrowIfNotOnUIThread(); - // return ChangeSelection(() => sessionOpt.PresenterSession.SelectNextItem()); - //} - - //private bool ChangeSelection(Action computationAction) - //{ - // this.ThreadingContext.ThrowIfNotOnUIThread(); - - // if (!IsSessionActive) - // { - // // No computation running, so just let the editor handle this. - // return false; - // } - - // // If we haven't started our editor session yet, just abort. - // // The user hasn't seen a SigHelp presentation yet, so they're - // // probably not trying to change the currently visible overload. - // if (!sessionOpt.PresenterSession.EditorSessionIsActive) - // { - // DismissSessionIfActive(); - // return false; - // } - - // // If we've finished computing the items then use the navigation commands to change the - // // selected item. Otherwise, the user was just typing and is now moving through the - // // file. In this case stop everything we're doing. - // var model = sessionOpt.InitialUnfilteredModel != null ? WaitForController() : null; - - // // Check if completion is still active. Then update the computation appropriately. - // // - // // Also, if we only computed one item, then the user doesn't want to select anything - // // else. Just stop and let the editor handle the nav character. - // if (model != null && model.Items.Count > 1) - // { - // computationAction(); - // return true; - // } - // else - // { - // // Dismiss ourselves and actually allow the editor to navigate. - // DismissSessionIfActive(); - // return false; - // } - //} - } -} From 7447145c8ed5fa4c1465dfeccac11fcf85b0d87e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 09:52:13 -0800 Subject: [PATCH 05/16] Cleanup --- .../Core/IntelliSense/AbstractController.cs | 22 ------------------- .../Test2/IntelliSense/ModelTests.vb | 1 + 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs index 52b571ed71240..a2c58a5c774d2 100644 --- a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs +++ b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs @@ -137,26 +137,4 @@ public void StopModelComputation() sessionOpt = null; localSession.Stop(); } - - //public bool TryHandleEscapeKey() - //{ - // this.ThreadingContext.ThrowIfNotOnUIThread(); - - // // Escape simply dismissed a session if it's up. Otherwise let the next thing in the - // // chain handle us. - // if (!IsSessionActive) - // { - // return false; - // } - - // // If we haven't even computed a model yet, then also send this command to anyone - // // listening. It's unlikely that the command was intended for us (as we wouldn't - // // have even shown ui yet. - // var handledCommand = sessionOpt.InitialUnfilteredModel != null; - - // // In the presence of an escape, we always stop what we're doing. - // this.StopModelComputation(); - - // return handledCommand; - //} } diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb index de5f85b31cb67..e540d6aa24b2e 100644 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb @@ -86,6 +86,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Await modelComputation.WaitForModelComputationAsync() controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) + controller.Verify(Sub(c) c.OnModelUpdated(null, False), Times.Once) End Function From 57a581bf6433f43406ab5cc92ae4620f52b4b4e1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 10:03:06 -0800 Subject: [PATCH 06/16] Remove code --- ...natureHelpBeforeCompletionCommandHandler.cs | 18 +++++------------- .../Core/IntelliSense/AbstractController.cs | 4 ++-- .../Core/IntelliSense/ISession.cs | 2 +- .../Core/IntelliSense/ModelComputation.cs | 15 ++------------- .../Core/IntelliSense/Session.cs | 4 ++-- .../Test2/IntelliSense/ModelTests.vb | 7 ++++--- .../SignatureHelpControllerTests.vb | 10 +++++----- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpBeforeCompletionCommandHandler.cs b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpBeforeCompletionCommandHandler.cs index 59688bdaa08f8..301980e672a3d 100644 --- a/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpBeforeCompletionCommandHandler.cs +++ b/src/EditorFeatures/Core.Wpf/SignatureHelp/SignatureHelpBeforeCompletionCommandHandler.cs @@ -20,19 +20,11 @@ namespace Microsoft.CodeAnalysis.Editor.CommandHandlers { /// - /// There are two forms of intellisense that may be active at the same time. Completion and - /// SigHelp. Completion precedes SigHelp in the command handler because it wants to make sure - /// it's operating on a buffer *after* Completion has changed it. i.e. if "WriteL(" is typed, - /// sig help wants to allow completion to complete that to "WriteLine(" before it tried to - /// proffer sig help. If we were to reverse things, then we'd get a bogus situation where sig - /// help would see "WriteL(" would have nothing to offer and would return. - /// - /// However, despite wanting sighelp to receive typechar first and then defer it to completion, - /// we want completion to receive other events first (like escape, and navigation keys). We - /// consider completion to have higher priority for those commands. In order to accomplish that, - /// we introduced - /// This command handler then delegates escape, up and down to those command handlers. - /// It is called before . + /// There are two forms of intellisense that may be active at the same time. Completion and SigHelp. Completion + /// precedes SigHelp in the command handler because it wants to make sure it's operating on a buffer *after* + /// Completion has changed it. i.e. if "WriteL(" is typed, sig help wants to allow completion to complete that to + /// "WriteLine(" before it tried to proffer sig help. If we were to reverse things, then we'd get a bogus situation + /// where sig help would see "WriteL(" would have nothing to offer and would return. /// [Export] [Export(typeof(ICommandHandler))] diff --git a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs index a2c58a5c774d2..b4265f3b01c70 100644 --- a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs +++ b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs @@ -78,11 +78,11 @@ private void OnTextViewClosed(object sender, EventArgs e) this.TextView.TextBuffer.PostChanged -= this.OnTextViewBufferPostChanged; } - public Task WaitForModelComputationAsync() + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() { this.ThreadingContext.ThrowIfNotOnUIThread(); VerifySessionIsActive(); - return sessionOpt.WaitForModelComputationAsync(); + return sessionOpt.WaitForModelComputation_ForTestingPurposesOnlyAsync(); } void IController.OnModelUpdated(TModel result, bool updateController) diff --git a/src/EditorFeatures/Core/IntelliSense/ISession.cs b/src/EditorFeatures/Core/IntelliSense/ISession.cs index 71b9ffd8e24ac..e1b777b77937c 100644 --- a/src/EditorFeatures/Core/IntelliSense/ISession.cs +++ b/src/EditorFeatures/Core/IntelliSense/ISession.cs @@ -14,5 +14,5 @@ internal interface ISession void Stop(); - Task WaitForModelComputationAsync(); + Task WaitForModelComputation_ForTestingPurposesOnlyAsync(); } diff --git a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs index dcf455d66e08e..73eafa53f97a8 100644 --- a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs +++ b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs @@ -81,19 +81,8 @@ public Task ModelTask } } - public async Task WaitForModelComputationAsync() - { - ThreadingContext.ThrowIfNotOnUIThread(); - - var model = await ModelTask.ConfigureAwait(true); - if (!_notifyControllerTask.IsCompleted) - { - OnModelUpdated(model, updateController: true); - - // Reset lastTask so controller.OnModelUpdated is only called once - _lastTask = Task.FromResult(model); - } - } + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() + => ModelTask; public virtual void Stop() { diff --git a/src/EditorFeatures/Core/IntelliSense/Session.cs b/src/EditorFeatures/Core/IntelliSense/Session.cs index c40bb6948f32b..e3c7a1bdb52df 100644 --- a/src/EditorFeatures/Core/IntelliSense/Session.cs +++ b/src/EditorFeatures/Core/IntelliSense/Session.cs @@ -53,9 +53,9 @@ public virtual void Stop() this.PresenterSession.Dismiss(); } - public Task WaitForModelComputationAsync() + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() { Computation.ThreadingContext.ThrowIfNotOnUIThread(); - return Computation.WaitForModelComputationAsync(); + return Computation.WaitForModelComputation_ForTestingPurposesOnlyAsync(); } } diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb index e540d6aa24b2e..16322f2218294 100644 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb @@ -60,7 +60,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) - Await modelComputation.WaitForModelComputationAsync() + Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync() controller.Verify(Sub(c) c.OnModelUpdated(model, True)) End Function @@ -83,10 +83,11 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) Monitor.Exit(gate) - Await modelComputation.WaitForModelComputationAsync() + Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync() controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) - controller.Verify(Sub(c) c.OnModelUpdated(null, False), Times.Once) + + ' controller.Verify(Sub(c) c.OnModelUpdated(null, False), Times.Once) End Function diff --git a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb index 8d373a5067332..2409e8479831e 100644 --- a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - Await controller.WaitForModelComputationAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() Assert.Equal(0, GetMocks(controller).Provider.GetItemsCount) End Function @@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True) Mock.Get(GetMocks(controller).View.Object.Caret).Raise(Sub(c) AddHandler c.PositionChanged, Nothing, New CaretPositionChangedEventArgs(Nothing, Nothing, Nothing)) - Await controller.WaitForModelComputationAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the PositionChanged event Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), ")"c), Sub() GetMocks(controller).Buffer.Insert(0, ")"), TestCommandExecutionContext.Create()) - Await controller.WaitForModelComputationAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the typechar command Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -152,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense provider = New MockSignatureHelpProvider(items) End If - Dim presenter = New Mock(Of IIntellisensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession))(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock} + Dim presenter = New Mock(Of IIntelliSensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession))(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock} presenterSession = If(presenterSession, New Mock(Of ISignatureHelpPresenterSession)(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock}) presenter.Setup(Function(p) p.CreateSession(It.IsAny(Of ITextView), It.IsAny(Of ITextBuffer), It.IsAny(Of ISignatureHelpSession))).Returns(presenterSession.Object) presenterSession.Setup(Sub(p) p.PresentItems(It.IsAny(Of ITrackingSpan), It.IsAny(Of IList(Of SignatureHelpItem)), It.IsAny(Of SignatureHelpItem), It.IsAny(Of Integer?))) _ @@ -185,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of InvokeSignatureHelpCommandArgs)).ExecuteCommand( New InvokeSignatureHelpCommandArgs(view.Object, buffer), Nothing, TestCommandExecutionContext.Create()) If waitForPresentation Then - Await controller.WaitForModelComputationAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() End If End If From 2c7382c0048b76d5c20f02100ec6ed55b3adf0a9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 10:28:56 -0800 Subject: [PATCH 07/16] Update tests --- .../CSharpSignatureHelpCommandHandlerTests.vb | 6 +++--- .../TestUtilities2/Intellisense/TestState.vb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/Test2/IntelliSense/CSharpSignatureHelpCommandHandlerTests.vb b/src/EditorFeatures/Test2/IntelliSense/CSharpSignatureHelpCommandHandlerTests.vb index 95d6b23a8dbd3..34a9bc96ce441 100644 --- a/src/EditorFeatures/Test2/IntelliSense/CSharpSignatureHelpCommandHandlerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/CSharpSignatureHelpCommandHandlerTests.vb @@ -499,7 +499,7 @@ class C state.SendEscape() End If - state.SendUpKey() + state.CurrentSignatureHelpPresenterSession.SelectPreviousItem() Await state.AssertSelectedSignatureHelpItem("void C.M(int i, int j, int k)") state.SendTypeChars("1") @@ -545,7 +545,7 @@ class C state.SendEscape() End If - state.SendDownKey() + state.CurrentSignatureHelpPresenterSession.SelectNextItem() Await state.AssertSelectedSignatureHelpItem("void C.M(int i, string x)") state.SendTypeChars("1") @@ -580,7 +580,7 @@ class C state.SendTypeChars("1, """" ") Await state.AssertSelectedSignatureHelpItem("void C.M(int i, string x)") - state.SendUpKey() + state.CurrentSignatureHelpPresenterSession.SelectPreviousItem() Await state.AssertSelectedSignatureHelpItem("void C.M(int i, int j)") state.SendTypeChars(",") diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index e9b084392a39f..bed1fdc280284 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Protected ReadOnly SessionTestState As IIntelliSenseTestState Private ReadOnly SignatureHelpBeforeCompletionCommandHandler As SignatureHelpBeforeCompletionCommandHandler - ' Protected ReadOnly SignatureHelpAfterCompletionCommandHandler As SignatureHelpAfterCompletionCommandHandler + Protected ReadOnly EditorSignatureHelpCommandHandler As ICommandHandler Protected ReadOnly CompleteStatementCommandHandler As CompleteStatementCommandHandler Private ReadOnly FormatCommandHandler As FormatCommandHandler @@ -73,7 +73,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Me.SignatureHelpBeforeCompletionCommandHandler = GetExportedValue(Of SignatureHelpBeforeCompletionCommandHandler)() - ' Me.SignatureHelpAfterCompletionCommandHandler = GetExportedValue(Of SignatureHelpAfterCompletionCommandHandler)() + ' Me.EditorSignatureHelpCommandHandler = Me.CompleteStatementCommandHandler = GetExportedValue(Of CompleteStatementCommandHandler)() Me.FormatCommandHandler = If(includeFormatCommandHandler, GetExportedValue(Of FormatCommandHandler)(), Nothing) @@ -176,13 +176,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Overloads Sub SendDownKey() MyBase.SendDownKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineDown(extendSelection:=False), c), + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), Sub() EditorOperations.MoveLineDown(extendSelection:=False)) End Sub Public Overloads Sub SendUpKey() MyBase.SendUpKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineUp(extendSelection:=False), c), + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), Sub() EditorOperations.MoveLineUp(extendSelection:=False)) End Sub From 0d976c837628b3971eed732a4eee5c9735b3c9a5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 10:29:54 -0800 Subject: [PATCH 08/16] Delete --- src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index bed1fdc280284..9286438ba7f9f 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -34,7 +34,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Protected ReadOnly SessionTestState As IIntelliSenseTestState Private ReadOnly SignatureHelpBeforeCompletionCommandHandler As SignatureHelpBeforeCompletionCommandHandler - Protected ReadOnly EditorSignatureHelpCommandHandler As ICommandHandler Protected ReadOnly CompleteStatementCommandHandler As CompleteStatementCommandHandler Private ReadOnly FormatCommandHandler As FormatCommandHandler From 4b6c875a8faf103851b94a42eff9b377150980a7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 10:30:07 -0800 Subject: [PATCH 09/16] Delete --- src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index 9286438ba7f9f..ff876a1341a0f 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -72,7 +72,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Me.SignatureHelpBeforeCompletionCommandHandler = GetExportedValue(Of SignatureHelpBeforeCompletionCommandHandler)() - ' Me.EditorSignatureHelpCommandHandler = Me.CompleteStatementCommandHandler = GetExportedValue(Of CompleteStatementCommandHandler)() Me.FormatCommandHandler = If(includeFormatCommandHandler, GetExportedValue(Of FormatCommandHandler)(), Nothing) From a111984bd64321636426fbf2bb933178cd746dda Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 10:33:48 -0800 Subject: [PATCH 10/16] Delete --- src/EditorFeatures/Test2/IntelliSense/ModelTests.vb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb index 16322f2218294..daac59eadd923 100644 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb @@ -83,11 +83,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) Monitor.Exit(gate) - Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync() - controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) - ' controller.Verify(Sub(c) c.OnModelUpdated(null, False), Times.Once) + controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) End Function From f6542d50c2a90c88899f39589e455b79e74c3131 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 11:03:12 -0800 Subject: [PATCH 11/16] Fixup tests --- .../Core/IntelliSense/AbstractController.cs | 4 ++-- src/EditorFeatures/Core/IntelliSense/ISession.cs | 2 +- .../Core/IntelliSense/ModelComputation.cs | 15 ++++++++++++--- src/EditorFeatures/Core/IntelliSense/Session.cs | 4 ++-- .../Test2/IntelliSense/ModelTests.vb | 11 ++++++----- .../IntelliSense/SignatureHelpControllerTests.vb | 8 ++++---- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs index b4265f3b01c70..8bce26b904abb 100644 --- a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs +++ b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs @@ -78,11 +78,11 @@ private void OnTextViewClosed(object sender, EventArgs e) this.TextView.TextBuffer.PostChanged -= this.OnTextViewBufferPostChanged; } - public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() + public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() { this.ThreadingContext.ThrowIfNotOnUIThread(); VerifySessionIsActive(); - return sessionOpt.WaitForModelComputation_ForTestingPurposesOnlyAsync(); + return sessionOpt.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); } void IController.OnModelUpdated(TModel result, bool updateController) diff --git a/src/EditorFeatures/Core/IntelliSense/ISession.cs b/src/EditorFeatures/Core/IntelliSense/ISession.cs index e1b777b77937c..5a9af88fa3618 100644 --- a/src/EditorFeatures/Core/IntelliSense/ISession.cs +++ b/src/EditorFeatures/Core/IntelliSense/ISession.cs @@ -14,5 +14,5 @@ internal interface ISession void Stop(); - Task WaitForModelComputation_ForTestingPurposesOnlyAsync(); + Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); } diff --git a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs index 73eafa53f97a8..fdcaeae010635 100644 --- a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs +++ b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs @@ -81,10 +81,19 @@ public Task ModelTask } } - public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() - => ModelTask; + public async Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + { + var model = await ModelTask.ConfigureAwait(true); + if (!_notifyControllerTask.IsCompleted) + { + // Reset lastTask so controller.OnModelUpdated is only called once + _lastTask = Task.FromResult(model); + } + + await _notifyControllerTask.ConfigureAwait(true); + } - public virtual void Stop() + public void Stop() { ThreadingContext.ThrowIfNotOnUIThread(); diff --git a/src/EditorFeatures/Core/IntelliSense/Session.cs b/src/EditorFeatures/Core/IntelliSense/Session.cs index e3c7a1bdb52df..4ade89d98d7f1 100644 --- a/src/EditorFeatures/Core/IntelliSense/Session.cs +++ b/src/EditorFeatures/Core/IntelliSense/Session.cs @@ -53,9 +53,9 @@ public virtual void Stop() this.PresenterSession.Dismiss(); } - public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() + public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() { Computation.ThreadingContext.ThrowIfNotOnUIThread(); - return Computation.WaitForModelComputation_ForTestingPurposesOnlyAsync(); + return Computation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); } } diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb index daac59eadd923..82b125f77272b 100644 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb @@ -56,13 +56,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim model = New Model() Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) controller.Setup(Function(c) c.BeginAsyncOperation("", Nothing, It.IsAny(Of String), It.IsAny(Of Integer))).Returns(EmptyAsyncToken.Instance) - controller.Setup(Sub(c) c.OnModelUpdated(model, True)) + controller.Setup(Sub(c) c.OnModelUpdated(model, False)) + Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) - Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() - controller.Verify(Sub(c) c.OnModelUpdated(model, True)) + controller.Verify(Sub(c) c.OnModelUpdated(model, False)) End Function @@ -83,9 +84,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function) modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) Monitor.Exit(gate) - Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() - controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once) + controller.Verify(Sub(c) c.OnModelUpdated(DirectCast(Nothing, Model), False), Times.Once) End Function diff --git a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb index 2409e8479831e..d13d0322c0f7b 100644 --- a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() Assert.Equal(0, GetMocks(controller).Provider.GetItemsCount) End Function @@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True) Mock.Get(GetMocks(controller).View.Object.Caret).Raise(Sub(c) AddHandler c.PositionChanged, Nothing, New CaretPositionChangedEventArgs(Nothing, Nothing, Nothing)) - Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the PositionChanged event Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), ")"c), Sub() GetMocks(controller).Buffer.Insert(0, ")"), TestCommandExecutionContext.Create()) - Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the typechar command Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -185,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of InvokeSignatureHelpCommandArgs)).ExecuteCommand( New InvokeSignatureHelpCommandArgs(view.Object, buffer), Nothing, TestCommandExecutionContext.Create()) If waitForPresentation Then - Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() End If End If From 2bd12aeb23163c7db54fc8e9631168e3280eb616 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 12:05:27 -0800 Subject: [PATCH 12/16] remove tests --- .../Core/IntelliSense/ModelComputation.cs | 2 +- .../Test2/IntelliSense/ModelTests.vb | 126 ------------------ .../EndConstructCommandHandler.vb | 2 +- 3 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 src/EditorFeatures/Test2/IntelliSense/ModelTests.vb diff --git a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs index fdcaeae010635..3b96a90b49610 100644 --- a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs +++ b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense; -internal class ModelComputation where TModel : class +internal sealed class ModelComputation where TModel : class { #region Fields that can be accessed from either thread diff --git a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb b/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb deleted file mode 100644 index 82b125f77272b..0000000000000 --- a/src/EditorFeatures/Test2/IntelliSense/ModelTests.vb +++ /dev/null @@ -1,126 +0,0 @@ -' 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. - -Imports System.Threading -Imports Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense -Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities -Imports Microsoft.CodeAnalysis.Shared.TestHooks -Imports Microsoft.VisualStudio.Threading -Imports Moq - -Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense - - - - Public NotInheritable Class ModelTests - Public Class Model - End Class - - Private Class TestModelComputation - Inherits ModelComputation(Of Model) - - Public Sub New(threadingContext As IThreadingContext, controller As IController(Of Model)) - MyBase.New(threadingContext, controller) - End Sub - - Friend Shared Function Create(threadingContext As IThreadingContext, Optional controller As IController(Of Model) = Nothing) As TestModelComputation - If controller Is Nothing Then - Dim mock = New Mock(Of IController(Of Model))(MockBehavior.Strict) - controller = mock.Object - End If - - Return New TestModelComputation(threadingContext, controller) - End Function - End Class - - - Public Sub ChainingTaskStartsAsyncOperation() - Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) - Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) - controller.Setup(Function(c) c.BeginAsyncOperation("", Nothing, It.IsAny(Of String), It.IsAny(Of Integer))).Returns(EmptyAsyncToken.Instance) - Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) - - modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(m)) - - controller.Verify(Sub(c) c.BeginAsyncOperation( - It.IsAny(Of String), - Nothing, - It.IsAny(Of String), - It.IsAny(Of Integer))) - End Sub - - - Public Async Function ChainingTaskThatCompletesNotifiesController() As Task - Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) - Dim model = New Model() - Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) - controller.Setup(Function(c) c.BeginAsyncOperation("", Nothing, It.IsAny(Of String), It.IsAny(Of Integer))).Returns(EmptyAsyncToken.Instance) - controller.Setup(Sub(c) c.OnModelUpdated(model, False)) - - Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) - - modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) - Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() - - controller.Verify(Sub(c) c.OnModelUpdated(model, False)) - End Function - - - Public Async Function ControllerIsOnlyUpdatedAfterLastTaskCompletes() As Task - Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) - Dim model = New Model() - Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) - controller.Setup(Function(c) c.BeginAsyncOperation("", Nothing, It.IsAny(Of String), It.IsAny(Of Integer))).Returns(EmptyAsyncToken.Instance) - controller.Setup(Sub(c) c.OnModelUpdated(model, True)) - Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) - Dim gate = New Object - - Monitor.Enter(gate) - modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) - SyncLock gate - Return Task.FromResult(Of Model)(Nothing) - End SyncLock - End Function) - modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model)) - Monitor.Exit(gate) - Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() - - controller.Verify(Sub(c) c.OnModelUpdated(DirectCast(Nothing, Model), False), Times.Once) - End Function - - - Public Async Function ControllerIsNotUpdatedIfComputationIsCancelled() As Task - Dim threadingContext = EditorTestCompositions.EditorFeatures.ExportProviderFactory.CreateExportProvider().GetExportedValue(Of IThreadingContext) - Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict) - Dim token = New Mock(Of IAsyncToken)(MockBehavior.Strict) - controller.Setup(Function(c) c.BeginAsyncOperation( - It.IsAny(Of String), - Nothing, - It.IsAny(Of String), - It.IsAny(Of Integer))).Returns(token.Object) - Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object) - Dim model = New Model() - Dim checkpoint1 = New Checkpoint - Dim checkpoint2 = New Checkpoint - Dim checkpoint3 = New Checkpoint - - token.Setup(Sub(t) t.Dispose()).Callback(Sub() checkpoint3.Release()) - - modelComputation.ChainTaskAndNotifyControllerWhenFinished( - Function(model1, c) - checkpoint1.Release() - checkpoint2.Task.Wait() - c.ThrowIfCancellationRequested() - Return Task.FromResult(model1) - End Function) - Await checkpoint1.Task - modelComputation.Stop() - checkpoint2.Release() - Await checkpoint3.Task - - controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Never) - End Function - - End Class -End Namespace diff --git a/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb b/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb index 7d593f2862e37..305feaae5d3b2 100644 --- a/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb @@ -141,7 +141,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration End Function) Dim options = buffer.GetCodeCleanupOptions(_editorOptionsService, document.Project.GetFallbackAnalyzerOptions(), document.Project.Services, explicitFormat:=False, allowImportsInHiddenRegions:=document.AllowImportsInHiddenRegions()) - Dim cleanDocument = CodeCleaner.CleanupAsync(document, GetSpanToCleanup(statement), Options, codeCleanups, cancellationToken:=cancellationToken).WaitAndGetResult(cancellationToken) + Dim cleanDocument = CodeCleaner.CleanupAsync(document, GetSpanToCleanup(statement), options, codeCleanups, cancellationToken:=cancellationToken).WaitAndGetResult(cancellationToken) Dim changes = cleanDocument.GetTextChangesAsync(document, cancellationToken).WaitAndGetResult(cancellationToken) Using transaction = New CaretPreservingEditTransaction(VBEditorResources.End_Construct, view, _undoHistoryRegistry, _editorOperationsFactoryService) From 39942232266423759076f0dedcb25d101c257db4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 12:07:46 -0800 Subject: [PATCH 13/16] rename --- .../Core/IntelliSense/AbstractController.cs | 4 ++-- src/EditorFeatures/Core/IntelliSense/ISession.cs | 2 +- .../Core/IntelliSense/ModelComputation.cs | 13 ++----------- src/EditorFeatures/Core/IntelliSense/Session.cs | 4 ++-- .../IntelliSense/SignatureHelpControllerTests.vb | 8 ++++---- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs index 8bce26b904abb..b4265f3b01c70 100644 --- a/src/EditorFeatures/Core/IntelliSense/AbstractController.cs +++ b/src/EditorFeatures/Core/IntelliSense/AbstractController.cs @@ -78,11 +78,11 @@ private void OnTextViewClosed(object sender, EventArgs e) this.TextView.TextBuffer.PostChanged -= this.OnTextViewBufferPostChanged; } - public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() { this.ThreadingContext.ThrowIfNotOnUIThread(); VerifySessionIsActive(); - return sessionOpt.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); + return sessionOpt.WaitForModelComputation_ForTestingPurposesOnlyAsync(); } void IController.OnModelUpdated(TModel result, bool updateController) diff --git a/src/EditorFeatures/Core/IntelliSense/ISession.cs b/src/EditorFeatures/Core/IntelliSense/ISession.cs index 5a9af88fa3618..e1b777b77937c 100644 --- a/src/EditorFeatures/Core/IntelliSense/ISession.cs +++ b/src/EditorFeatures/Core/IntelliSense/ISession.cs @@ -14,5 +14,5 @@ internal interface ISession void Stop(); - Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); + Task WaitForModelComputation_ForTestingPurposesOnlyAsync(); } diff --git a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs index 3b96a90b49610..0e6b5e87d57e8 100644 --- a/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs +++ b/src/EditorFeatures/Core/IntelliSense/ModelComputation.cs @@ -81,17 +81,8 @@ public Task ModelTask } } - public async Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() - { - var model = await ModelTask.ConfigureAwait(true); - if (!_notifyControllerTask.IsCompleted) - { - // Reset lastTask so controller.OnModelUpdated is only called once - _lastTask = Task.FromResult(model); - } - - await _notifyControllerTask.ConfigureAwait(true); - } + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() + => ModelTask; public void Stop() { diff --git a/src/EditorFeatures/Core/IntelliSense/Session.cs b/src/EditorFeatures/Core/IntelliSense/Session.cs index 4ade89d98d7f1..e3c7a1bdb52df 100644 --- a/src/EditorFeatures/Core/IntelliSense/Session.cs +++ b/src/EditorFeatures/Core/IntelliSense/Session.cs @@ -53,9 +53,9 @@ public virtual void Stop() this.PresenterSession.Dismiss(); } - public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + public Task WaitForModelComputation_ForTestingPurposesOnlyAsync() { Computation.ThreadingContext.ThrowIfNotOnUIThread(); - return Computation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync(); + return Computation.WaitForModelComputation_ForTestingPurposesOnlyAsync(); } } diff --git a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb index d13d0322c0f7b..2409e8479831e 100644 --- a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss()) - Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() Assert.Equal(0, GetMocks(controller).Provider.GetItemsCount) End Function @@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True) Mock.Get(GetMocks(controller).View.Object.Caret).Raise(Sub(c) AddHandler c.PositionChanged, Nothing, New CaretPositionChangedEventArgs(Nothing, Nothing, Nothing)) - Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the PositionChanged event Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand( New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), ")"c), Sub() GetMocks(controller).Buffer.Insert(0, ")"), TestCommandExecutionContext.Create()) - Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() ' GetItemsAsync is called once initially, and then once as a result of handling the typechar command Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount) @@ -185,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense DirectCast(controller, IChainedCommandHandler(Of InvokeSignatureHelpCommandArgs)).ExecuteCommand( New InvokeSignatureHelpCommandArgs(view.Object, buffer), Nothing, TestCommandExecutionContext.Create()) If waitForPresentation Then - Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync() + Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync() End If End If From d601703a13ce6021805da60a9026658c43447e3c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 12:20:01 -0800 Subject: [PATCH 14/16] Fix test --- src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index ff876a1341a0f..6a933a03b559d 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -174,13 +174,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Overloads Sub SendDownKey() MyBase.SendDownKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineDown(extendSelection:=False), c), Sub() EditorOperations.MoveLineDown(extendSelection:=False)) End Sub Public Overloads Sub SendUpKey() MyBase.SendUpKey( - Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), + Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() EditorOperations.MoveLineUp(extendSelection:=False), c), Sub() EditorOperations.MoveLineUp(extendSelection:=False)) End Sub From 028c0e819b47ddc27e139e1db7a4012ed2748f3e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 12:24:57 -0800 Subject: [PATCH 15/16] Fix test --- src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index 6a933a03b559d..ac87e4e41bbda 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -169,7 +169,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function Public Overloads Sub SendEscape() - MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Return, c), Sub() Return) + MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Me.CurrentSignatureHelpPresenterSession.Dismiss(), c), Sub() Return) End Sub Public Overloads Sub SendDownKey() From 9c434a3b9d63010a403ba20de93a05b5a365c688 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 18 Dec 2024 12:27:28 -0800 Subject: [PATCH 16/16] Fix test --- src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb index ac87e4e41bbda..7e18860b93d6e 100644 --- a/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb +++ b/src/EditorFeatures/TestUtilities2/Intellisense/TestState.vb @@ -169,7 +169,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function Public Overloads Sub SendEscape() - MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Me.CurrentSignatureHelpPresenterSession.Dismiss(), c), Sub() Return) + MyBase.SendEscape(Sub(a, n, c) EditorCompletionCommandHandler.ExecuteCommand(a, Sub() Me.CurrentSignatureHelpPresenterSession?.Dismiss(), c), Sub() Return) End Sub Public Overloads Sub SendDownKey()