From 5dacb62fff467c015c723961b1de67d323fe765a Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 25 Sep 2024 14:32:46 -0400 Subject: [PATCH 1/4] Add trace code to debug test failures on CI --- .../Completion/MSBuildCompletionSource.cs | 9 ++++++ .../Completion/MSBuildCommitTests.cs | 30 ++++++++++++------- MonoDevelop.Xml | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/MonoDevelop.MSBuild.Editor/Completion/MSBuildCompletionSource.cs b/MonoDevelop.MSBuild.Editor/Completion/MSBuildCompletionSource.cs index 479a3bfe..12b35320 100644 --- a/MonoDevelop.MSBuild.Editor/Completion/MSBuildCompletionSource.cs +++ b/MonoDevelop.MSBuild.Editor/Completion/MSBuildCompletionSource.cs @@ -56,10 +56,16 @@ protected override MSBuildCompletionContext CreateTriggerContext (IAsyncCompleti protected override Task> GetElementCompletionsAsync (MSBuildCompletionContext context, bool includeBracket, CancellationToken token) { + if (EnableDebugTrace) { + LogTrace ($"Entered GetElementCompletionsAsync"); + } var doc = context.Document; var nodePath = context.NodePath; if (!CompletionHelpers.TryGetElementSyntaxForElementCompletion(nodePath, out MSBuildElementSyntax languageElement, out string elementName)) { + if (EnableDebugTrace) { + LogTrace ($"Exited GetElementCompletionsAsync with no syntax"); + } return TaskCompleted (null); } @@ -80,6 +86,9 @@ protected override Task> GetElementCompletionsAsync (MSBui items.Add (c); } + if (EnableDebugTrace) { + LogTrace ($"Exited GetElementCompletionsAsync with {items.Count} items"); + } return TaskCompleted (items); } diff --git a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs index 090897c3..c64ea7ff 100644 --- a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs +++ b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.VisualStudio.Text.Editor.Commanding; +using MonoDevelop.MSBuild.Editor.Completion; using MonoDevelop.Xml.Editor.Tests.Extensions; @@ -15,18 +16,25 @@ namespace MonoDevelop.MSBuild.Tests.Editor.Completion [TestFixture] public class MSBuildCommitTests : MSBuildEditorTest { - Task TestTypeCommands (string filename, string before, string typeChars, string after) + async Task TestTypeCommands (string filename, string before, string typeChars, string after) { - return this.TestCommands ( - before, - after, - [ (s) => s.Type (typeChars) ], - filename: filename, - initialize: (tv) => { - tv.Options.SetOptionValue ("BraceCompletion/Enabled", true); - return Task.CompletedTask; - } - ); + CommandServiceExtensions.EnableDebugTrace = true; + MSBuildCompletionSource.EnableDebugTrace = true; + try { + await this.TestCommands ( + before, + after, + [ (s) => s.Type (typeChars) ], + filename: filename, + initialize: (tv) => { + tv.Options.SetOptionValue ("BraceCompletion/Enabled", true); + return Task.CompletedTask; + } + ); + } finally { + CommandServiceExtensions.EnableDebugTrace = false; + MSBuildCompletionSource.EnableDebugTrace = false; + } } [Test] diff --git a/MonoDevelop.Xml b/MonoDevelop.Xml index 361e2930..9c106a60 160000 --- a/MonoDevelop.Xml +++ b/MonoDevelop.Xml @@ -1 +1 @@ -Subproject commit 361e2930fe3cbaa8eee787702446ed54e767124c +Subproject commit 9c106a601d320f6578386dd3637a25511d3a35ca From 9212bb7103ad14c153690633fff983179448daf6 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 25 Sep 2024 19:30:38 -0400 Subject: [PATCH 2/4] Work around nondeterministic completion test failures on CI --- .../Completion/MSBuildCommitTests.cs | 14 +++++++------- MonoDevelop.Xml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs index c64ea7ff..0a418fd1 100644 --- a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs +++ b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs @@ -18,9 +18,9 @@ public class MSBuildCommitTests : MSBuildEditorTest { async Task TestTypeCommands (string filename, string before, string typeChars, string after) { - CommandServiceExtensions.EnableDebugTrace = true; - MSBuildCompletionSource.EnableDebugTrace = true; - try { + //CommandServiceExtensions.EnableDebugTrace = true; + //MSBuildCompletionSource.EnableDebugTrace = true; + //try { await this.TestCommands ( before, after, @@ -31,10 +31,10 @@ await this.TestCommands ( return Task.CompletedTask; } ); - } finally { - CommandServiceExtensions.EnableDebugTrace = false; - MSBuildCompletionSource.EnableDebugTrace = false; - } + //} finally { + // CommandServiceExtensions.EnableDebugTrace = false; + // MSBuildCompletionSource.EnableDebugTrace = false; + //} } [Test] diff --git a/MonoDevelop.Xml b/MonoDevelop.Xml index 9c106a60..a4e97ec6 160000 --- a/MonoDevelop.Xml +++ b/MonoDevelop.Xml @@ -1 +1 @@ -Subproject commit 9c106a601d320f6578386dd3637a25511d3a35ca +Subproject commit a4e97ec6d8c5ac51be2a09da488d1f965f7545a6 From 6ba2032b655f39dc126d2ea528963780dc16fc02 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 26 Sep 2024 13:55:42 -0400 Subject: [PATCH 3/4] Yield UI thread between editor commands in tests --- .../Completion/MSBuildCommitTests.cs | 6 +----- .../Refactorings/MSBuildEditorTestExtensions.cs | 8 +++++++- MonoDevelop.Xml | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs index 0a418fd1..23083cad 100644 --- a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs +++ b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs @@ -1,12 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.Threading.Tasks; -using Microsoft.VisualStudio.Text.Editor.Commanding; -using MonoDevelop.MSBuild.Editor.Completion; - using MonoDevelop.Xml.Editor.Tests.Extensions; using NUnit.Framework; @@ -24,7 +20,7 @@ async Task TestTypeCommands (string filename, string before, string typeChars, s await this.TestCommands ( before, after, - [ (s) => s.Type (typeChars) ], + EditorAction.Type (typeChars), filename: filename, initialize: (tv) => { tv.Options.SetOptionValue ("BraceCompletion/Enabled", true); diff --git a/MonoDevelop.MSBuild.Tests.Editor/Refactorings/MSBuildEditorTestExtensions.cs b/MonoDevelop.MSBuild.Tests.Editor/Refactorings/MSBuildEditorTestExtensions.cs index 4d5512ce..82095c2e 100644 --- a/MonoDevelop.MSBuild.Tests.Editor/Refactorings/MSBuildEditorTestExtensions.cs +++ b/MonoDevelop.MSBuild.Tests.Editor/Refactorings/MSBuildEditorTestExtensions.cs @@ -224,7 +224,13 @@ public static async Task TestCodeActionContext ( // the refactoring may have left multiple selections sp the user can e.g. type a new name for an extracted property await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync (default); var commandService = test.Catalog.CommandServiceFactory.GetService (ctx.TextView); - commandService.Type (typeText); + + foreach(var editorAction in EditorAction.Type (typeText)) { + editorAction (commandService); + // yield to let things catch up + // and so we don't block the UI thread between the commands + await Task.Delay (20); + } Assert.That ( ctx.TextBuffer.CurrentSnapshot.GetText (), diff --git a/MonoDevelop.Xml b/MonoDevelop.Xml index a4e97ec6..93927f4d 160000 --- a/MonoDevelop.Xml +++ b/MonoDevelop.Xml @@ -1 +1 @@ -Subproject commit a4e97ec6d8c5ac51be2a09da488d1f965f7545a6 +Subproject commit 93927f4dae3dcc508e7e00550ebb23c94664277d From 317b3e28191c972e5b486bb413bc9e11b19909a5 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 26 Sep 2024 14:18:00 -0400 Subject: [PATCH 4/4] Force initial parse before commit tests This may help with nondeterministic failures on CI where the machine has fewer cores and the parse doesn't catch up before completion is triggered. --- .../Completion/MSBuildCommitTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs index 23083cad..feeabfea 100644 --- a/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs +++ b/MonoDevelop.MSBuild.Tests.Editor/Completion/MSBuildCommitTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Threading; using System.Threading.Tasks; using MonoDevelop.Xml.Editor.Tests.Extensions; @@ -22,9 +23,10 @@ await this.TestCommands ( after, EditorAction.Type (typeChars), filename: filename, - initialize: (tv) => { + initialize: async (tv) => { tv.Options.SetOptionValue ("BraceCompletion/Enabled", true); - return Task.CompletedTask; + // ensure we have an initial parse before triggering completion + await Catalog.MSBuildParserProvider.GetParser (tv.TextBuffer).GetOrProcessAsync (tv.TextBuffer.CurrentSnapshot, CancellationToken.None); } ); //} finally {