From e3e208f00f075c3b286792411e80a21eb04bc2e5 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Tue, 22 Jun 2021 10:21:11 -0700 Subject: [PATCH] Building again --- Directory.Build.props | 2 +- Src/VimApp/VimApp.csproj | 3 +- Src/VimApp/VimComponentHost.cs | 1 - Src/VimCore/AssemblyInfo.fs | 2 + ...ctory.JoinableTaskContextExportProvider.cs | 5 +- Src/VimEditorHost/EditorHostFactory.cs | 56 +++++++++++++++++-- Src/VimEditorHost/EditorSpecificUtil.cs | 18 ++++++ .../IVimErrorDetector.cs | 2 +- .../Implementation/Misc/VimErrorDetector.cs} | 5 +- Src/VimEditorHost/README.md | 9 ++- .../VimEditorHost.cs | 5 +- Src/VimEditorHost/VimEditorHost.projitems | 6 +- .../VimTestBase.cs | 6 +- .../WordCompletion/VimWordCompletionUtil.cs | 4 +- Src/VimSpecific/VimSpecificUtil.cs | 1 + .../Exports/OutlinerTaggerProvider.cs | 4 +- .../Extensions2.cs} | 16 +----- Src/VimTestUtils/Mock/Extensions.cs | 9 --- Src/VimTestUtils/Mock/MockObjectFactory.cs | 10 ++-- Src/VimTestUtils/Mock/MockVimHost.cs | 1 - .../TestableSynchronizationContext.cs | 1 - Src/VimTestUtils/Utilities/WpfTestInvoker.cs | 1 - .../Utilities/WpfTheoryTestCase.cs | 1 - .../Utilities/WpfTheoryTestCaseRunner.cs | 1 - Src/VimTestUtils/VimTestUtils.csproj | 36 ++++++++++++ Src/VimTestUtils/VimTestUtils.projitems | 53 ------------------ Src/VimTestUtils/VimTestUtils.shproj | 13 ----- Src/VimTestUtils/VimUtil.cs | 5 +- Src/VimTestUtils/WpfFactAttribute.cs | 37 +++--------- Test/VimCoreTest/InsertModeIntegrationTest.cs | 28 +++++----- Test/VimCoreTest/VimCoreTest.csproj | 3 +- Test/VimWpfTest/VimWpfTest.csproj | 3 +- Test/VsVimSharedTest/MemoryLeakTest.cs | 2 +- Test/VsVimSharedTest/VsIntegrationTest.cs | 4 +- Test/VsVimTest2017/VsVimTest2017.csproj | 3 +- Test/VsVimTest2019/VsVimTest2019.csproj | 3 +- VsVim.sln | 33 ++++++++--- 37 files changed, 205 insertions(+), 187 deletions(-) create mode 100644 Src/VimEditorHost/EditorSpecificUtil.cs rename Src/{VimTestUtils => VimEditorHost}/IVimErrorDetector.cs (94%) rename Src/{VimTestUtils/Exports/VimErrorHandler.cs => VimEditorHost/Implementation/Misc/VimErrorDetector.cs} (96%) rename Src/{VimTestUtils => VimEditorHost}/VimEditorHost.cs (94%) rename Src/{VimTestUtils => VimEditorHost}/VimTestBase.cs (96%) rename Src/{VimEditorHost/Extensions.cs => VimTestUtils/Extensions2.cs} (94%) create mode 100644 Src/VimTestUtils/VimTestUtils.csproj delete mode 100644 Src/VimTestUtils/VimTestUtils.projitems delete mode 100644 Src/VimTestUtils/VimTestUtils.shproj diff --git a/Directory.Build.props b/Directory.Build.props index 33f3ca3769..bccdbbd7b5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,7 +13,7 @@ - 14.0 + 16.0 $(NUGET_PACKAGES) diff --git a/Src/VimApp/VimApp.csproj b/Src/VimApp/VimApp.csproj index c8d4b1d1ac..e2dc759d08 100644 --- a/Src/VimApp/VimApp.csproj +++ b/Src/VimApp/VimApp.csproj @@ -6,7 +6,7 @@ VimApp VimApp net472 - true + $(DefineConstants);VS_SPECIFIC_VIM_APP $(VisualStudioTestVersionDefault) @@ -30,6 +30,7 @@ + diff --git a/Src/VimApp/VimComponentHost.cs b/Src/VimApp/VimComponentHost.cs index 9fa4af7abe..81d1f67639 100644 --- a/Src/VimApp/VimComponentHost.cs +++ b/Src/VimApp/VimComponentHost.cs @@ -35,7 +35,6 @@ internal VimComponentHost() editorHostFactory.Add(new AssemblyCatalog(typeof(IVim).Assembly)); editorHostFactory.Add(new AssemblyCatalog(typeof(VimKeyProcessor).Assembly)); - editorHostFactory.Add(new AssemblyCatalog(typeof(VimComponentHost).Assembly)); _editorHost = editorHostFactory.CreateEditorHost(); _vim = _editorHost.CompositionContainer.GetExportedValue(); diff --git a/Src/VimCore/AssemblyInfo.fs b/Src/VimCore/AssemblyInfo.fs index 75c4a9efcb..8929307347 100644 --- a/Src/VimCore/AssemblyInfo.fs +++ b/Src/VimCore/AssemblyInfo.fs @@ -11,6 +11,8 @@ open System.Runtime.CompilerServices [] [] [] +// TODO_SHARED this should be deleted +[] [] // Moq do() diff --git a/Src/VimEditorHost/EditorHostFactory.JoinableTaskContextExportProvider.cs b/Src/VimEditorHost/EditorHostFactory.JoinableTaskContextExportProvider.cs index 9f208f5e1b..95f24fff4c 100644 --- a/Src/VimEditorHost/EditorHostFactory.JoinableTaskContextExportProvider.cs +++ b/Src/VimEditorHost/EditorHostFactory.JoinableTaskContextExportProvider.cs @@ -31,11 +31,8 @@ private sealed class JoinableTaskContextExportProvider : ExportProvider internal JoinableTaskContextExportProvider() { _export = new Export(TypeFullName, GetValue); -#if VS_SPECIFIC_2017 || VS_SPECIFIC_2019 - _context = ThreadHelper.JoinableTaskContext; -#else +#pragma warning disable VSSDK005 _context = new JoinableTaskContext(Thread.CurrentThread, new DispatcherSynchronizationContext()); -#endif } protected override IEnumerable GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) diff --git a/Src/VimEditorHost/EditorHostFactory.cs b/Src/VimEditorHost/EditorHostFactory.cs index 017f94e692..4bc052da1c 100644 --- a/Src/VimEditorHost/EditorHostFactory.cs +++ b/Src/VimEditorHost/EditorHostFactory.cs @@ -15,7 +15,7 @@ namespace Vim.EditorHost public sealed partial class EditorHostFactory { #if VS_SPECIFIC_2015 - internal static EditorVersion DefaultEditorVersion => EditorVersion.Vs2017; + internal static EditorVersion DefaultEditorVersion => EditorVersion.Vs2015; internal static Version VisualStudioVersion => new Version(14, 0, 0, 0); internal static Version VisualStudioThreadingVersion => new Version(14, 0, 0, 0); #elif VS_SPECIFIC_2017 @@ -63,8 +63,34 @@ public void Add(ExportProvider exportProvider) public CompositionContainer CreateCompositionContainer() { - var catalog = new AggregateCatalog(_composablePartCatalogList.ToArray()); - return new CompositionContainer(catalog, _exportProviderList.ToArray()); + var aggregateCatalog = new AggregateCatalog(_composablePartCatalogList.ToArray()); +#if DEBUG + DumpExports(); +#endif + + return new CompositionContainer(aggregateCatalog, _exportProviderList.ToArray()); + +#if DEBUG + void DumpExports() + { + var exportNames = new List(); + foreach (var catalog in aggregateCatalog) + { + foreach (var exportDefinition in catalog.ExportDefinitions) + { + exportNames.Add(exportDefinition.ContractName); + } + } + + exportNames.Sort(); + var groupedExportNames = exportNames + .GroupBy(x => x) + .Select(x => (Count: x.Count(), x.Key)) + .OrderByDescending(x => x.Count) + .Select(x => $"{x.Count} {x.Key}") + .ToList(); + } +#endif } public EditorHost CreateEditorHost() @@ -78,7 +104,29 @@ private void BuildCatalog() AppendEditorAssemblies(editorAssemblyVersion); AppendEditorAssembly("Microsoft.VisualStudio.Threading", VisualStudioThreadingVersion); _exportProviderList.Add(new JoinableTaskContextExportProvider()); - _composablePartCatalogList.Add(new AssemblyCatalog(typeof(EditorHostFactory).Assembly)); + + // Other Exports needed to construct VsVim + var types = new List() + { + typeof(Implementation.BasicUndo.BasicTextUndoHistoryRegistry), + typeof(Implementation.Misc.BasicObscuringTipManager), + typeof(Implementation.Misc.VimErrorDetector), +#if VS_SPECIFIC_2019 + typeof(Implementation.Misc.BasicExperimentationServiceInternal), + typeof(Implementation.Misc.BasicLoggingServiceInternal), + typeof(Implementation.Misc.BasicObscuringTipManager), +#elif VS_SPECIFIC_2017 + typeof(Implementation.Misc.BasicLoggingServiceInternal), + typeof(Implementation.Misc.BasicObscuringTipManager), +#elif VS_SPECIFIC_2015 + +#else +#error Unsupported configuration +#endif + + }; + + _composablePartCatalogList.Add(new TypeCatalog(types)); } private void AppendEditorAssemblies(Version editorAssemblyVersion) diff --git a/Src/VimEditorHost/EditorSpecificUtil.cs b/Src/VimEditorHost/EditorSpecificUtil.cs new file mode 100644 index 0000000000..d67b945222 --- /dev/null +++ b/Src/VimEditorHost/EditorSpecificUtil.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Vim.EditorHost +{ + public static class EditorSpecificUtil + { +#if VS_SPECIFIC_2015 || VS_SPECIFIC_2017 + public const bool HasAsyncCompletion = false; +#elif VS_SPECIFIC_2019 || VS_SPECIFIC_MAC + public const bool HasAsyncCompletion = true; +#else +#error Unsupported configuration +#endif + public const bool HasLegacyCompletion = !HasAsyncCompletion; + } +} diff --git a/Src/VimTestUtils/IVimErrorDetector.cs b/Src/VimEditorHost/IVimErrorDetector.cs similarity index 94% rename from Src/VimTestUtils/IVimErrorDetector.cs rename to Src/VimEditorHost/IVimErrorDetector.cs index d7d0a76853..0367e89424 100644 --- a/Src/VimTestUtils/IVimErrorDetector.cs +++ b/Src/VimEditorHost/IVimErrorDetector.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Microsoft.VisualStudio.Text; -namespace Vim.UnitTest +namespace Vim.EditorHost { /// /// Several portions of the Editor code will swallow exceptions from an extension diff --git a/Src/VimTestUtils/Exports/VimErrorHandler.cs b/Src/VimEditorHost/Implementation/Misc/VimErrorDetector.cs similarity index 96% rename from Src/VimTestUtils/Exports/VimErrorHandler.cs rename to Src/VimEditorHost/Implementation/Misc/VimErrorDetector.cs index e1786d0645..2892cce1b8 100644 --- a/Src/VimTestUtils/Exports/VimErrorHandler.cs +++ b/Src/VimEditorHost/Implementation/Misc/VimErrorDetector.cs @@ -7,7 +7,7 @@ using Microsoft.VisualStudio.Utilities; using Vim.Extensions; -namespace Vim.UnitTest.Exports +namespace Vim.EditorHost.Implementation.Misc { /// /// IVimErrorDetector MEF component. Useful in tracking down errors which are silently @@ -129,12 +129,11 @@ void IExtensionErrorHandler.HandleError(object sender, Exception exception) { return; } - - #elif VS_SPECIFIC_2017 || VS_SPECIFIC_2015 #else #error Unsupported configuration #endif + _errorList.Add(exception); } diff --git a/Src/VimEditorHost/README.md b/Src/VimEditorHost/README.md index c60c815a3b..d9c47751c1 100644 --- a/Src/VimEditorHost/README.md +++ b/Src/VimEditorHost/README.md @@ -1,5 +1,10 @@ # Vim Editor Host -This is a library designed to make it easy to host `IWpfTextView` instances. This is used in simple -editor test apps and unit tests. +This is a library designed to make it easy to host `IVimBuffer` instances. It facilitates both the +`VimApp` project as well as hosting in the unit tests + +This is provided as a shared source project so that the editor behavior can be easily customized with +`#if` calls based on the specific editor we are creating + +Logic and helpers here should be minimal. The goal is **only** for hosting the editor and vim diff --git a/Src/VimTestUtils/VimEditorHost.cs b/Src/VimEditorHost/VimEditorHost.cs similarity index 94% rename from Src/VimTestUtils/VimEditorHost.cs rename to Src/VimEditorHost/VimEditorHost.cs index 5ed446d3d0..45117cb635 100644 --- a/Src/VimTestUtils/VimEditorHost.cs +++ b/Src/VimEditorHost/VimEditorHost.cs @@ -3,15 +3,14 @@ using System.ComponentModel.Composition.Hosting; using System.Linq; using System.Text; -using Vim.EditorHost; using Microsoft.VisualStudio.Text.Classification; using Vim.UI.Wpf; using Vim.UnitTest.Mock; using Microsoft.VisualStudio.Text; -namespace Vim.UnitTest +namespace Vim.EditorHost { - public sealed class VimEditorHost : EditorHost.EditorHost + public sealed class VimEditorHost : EditorHost { private readonly IVim _vim; private readonly IVimBufferFactory _vimBufferFactory; diff --git a/Src/VimEditorHost/VimEditorHost.projitems b/Src/VimEditorHost/VimEditorHost.projitems index ba1bf55d5c..f12b708e97 100644 --- a/Src/VimEditorHost/VimEditorHost.projitems +++ b/Src/VimEditorHost/VimEditorHost.projitems @@ -13,9 +13,9 @@ + - @@ -24,6 +24,10 @@ + + + + diff --git a/Src/VimTestUtils/VimTestBase.cs b/Src/VimEditorHost/VimTestBase.cs similarity index 96% rename from Src/VimTestUtils/VimTestBase.cs rename to Src/VimEditorHost/VimTestBase.cs index f6415111a6..cdff85b5c8 100644 --- a/Src/VimTestUtils/VimTestBase.cs +++ b/Src/VimEditorHost/VimTestBase.cs @@ -1,4 +1,5 @@ -using System; +#if VS_UNIT_TEST_HOST +using System; using System.Collections.Generic; using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition.Primitives; @@ -27,6 +28,7 @@ using Xunit.Sdk; using Vim.Extensions; using Vim.VisualStudio.Specific; +using Vim.EditorHost.Implementation.Misc; namespace Vim.UnitTest { @@ -560,7 +562,6 @@ private static VimEditorHost GetOrCreateVimEditorHost() typeof(TestableKeyboardDevice), typeof(TestableMouseDevice), typeof(global::Vim.UnitTest.Exports.VimHost), - typeof(VimErrorDetector), typeof(DisplayWindowBrokerFactoryService), typeof(AlternateKeyUtil), typeof(OutlinerTaggerProvider) @@ -628,3 +629,4 @@ public static IEnumerable SelectionOptions } } } +#endif diff --git a/Src/VimSpecific/Implementation/WordCompletion/VimWordCompletionUtil.cs b/Src/VimSpecific/Implementation/WordCompletion/VimWordCompletionUtil.cs index e42043b47c..9cec43efa0 100644 --- a/Src/VimSpecific/Implementation/WordCompletion/VimWordCompletionUtil.cs +++ b/Src/VimSpecific/Implementation/WordCompletion/VimWordCompletionUtil.cs @@ -84,9 +84,9 @@ private FSharpOption CreateWordCompletionSession(ITextVi #else #error Unsupported configuration #endif - + #region IWordCompletionSessionFactory - + FSharpOption IWordCompletionSessionFactory.CreateWordCompletionSession(ITextView textView, SnapshotSpan wordSpan, IEnumerable wordCollection, bool isForward) { return CreateWordCompletionSession(textView, wordSpan, wordCollection, isForward); diff --git a/Src/VimSpecific/VimSpecificUtil.cs b/Src/VimSpecific/VimSpecificUtil.cs index 0dc0feaf51..fc50b9044d 100644 --- a/Src/VimSpecific/VimSpecificUtil.cs +++ b/Src/VimSpecific/VimSpecificUtil.cs @@ -4,6 +4,7 @@ namespace Vim.VisualStudio.Specific { + // TODO_SHARED this type needs to be re-thought a lot internal static class VimSpecificUtil { #if VS_SPECIFIC_2015 || VS_SPECIFIC_2017 diff --git a/Src/VimTestUtils/Exports/OutlinerTaggerProvider.cs b/Src/VimTestUtils/Exports/OutlinerTaggerProvider.cs index c13c014786..22ba3f4455 100644 --- a/Src/VimTestUtils/Exports/OutlinerTaggerProvider.cs +++ b/Src/VimTestUtils/Exports/OutlinerTaggerProvider.cs @@ -3,7 +3,6 @@ using System.ComponentModel.Composition; using System.Linq; using System.Text; -using Vim.EditorHost; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Tagging; @@ -11,11 +10,12 @@ namespace Vim.UnitTest.Exports { + // TODO_SHARED move to editor host and make this internal again [Export(typeof(ITaggerProvider))] [ContentType("any")] [TextViewRole(PredefinedTextViewRoles.Structured)] [TagType(typeof(OutliningRegionTag))] - internal sealed class OutlinerTaggerProvider : ITaggerProvider + public sealed class OutlinerTaggerProvider : ITaggerProvider { ITagger ITaggerProvider.CreateTagger(ITextBuffer textBuffer) { diff --git a/Src/VimEditorHost/Extensions.cs b/Src/VimTestUtils/Extensions2.cs similarity index 94% rename from Src/VimEditorHost/Extensions.cs rename to Src/VimTestUtils/Extensions2.cs index c3d5e00028..32336f7da9 100644 --- a/Src/VimEditorHost/Extensions.cs +++ b/Src/VimTestUtils/Extensions2.cs @@ -14,7 +14,7 @@ namespace Vim.EditorHost { - public static class Extensions + public static partial class Extensions { #region ITextBufferFactoryService @@ -108,11 +108,6 @@ public static SnapshotPoint GetCaretPoint(this ITextView textView) return textView.Caret.Position.BufferPosition; } - public static VirtualSnapshotPoint GetCaretVirtualPoint(this ITextView textView) - { - return textView.Caret.Position.VirtualBufferPosition; - } - public static ITextSnapshotLine GetCaretLine(this ITextView textView) { return textView.Caret.Position.BufferPosition.GetContainingLine(); @@ -271,15 +266,6 @@ public static NormalizedSnapshotSpanCollection GetTaggerExtent(this ITextSnapsho #region SnapshotPoint - /// - /// Get the column that this SnapshotPoint occupies - /// - public static int GetColumn(this SnapshotPoint point) - { - var line = point.GetContainingLine(); - return point.Position - line.Start.Position; - } - public static SnapshotSpan GetSpan(this SnapshotPoint point, int length) { return new SnapshotSpan(point, length); diff --git a/Src/VimTestUtils/Mock/Extensions.cs b/Src/VimTestUtils/Mock/Extensions.cs index 360bd5ffd1..d9125b3d37 100644 --- a/Src/VimTestUtils/Mock/Extensions.cs +++ b/Src/VimTestUtils/Mock/Extensions.cs @@ -8,7 +8,6 @@ using Moq; using Moq.Language.Flow; using Vim.Extensions; -using Vim.EditorHost; namespace Vim.UnitTest.Mock { @@ -142,14 +141,6 @@ public static void SetupCommandVisual(this Mock commandUtil, Visua } } - public static void SetupPut(this Mock operations, ITextBuffer textBuffer, params string[] newText) - { - operations - .Setup(x => x.Put(It.IsAny(), It.IsAny(), It.IsAny())) - .Callback(() => textBuffer.SetText(newText)) - .Verifiable(); - } - public static void SetupProcess(this Mock mode, string input) { var count = 0; diff --git a/Src/VimTestUtils/Mock/MockObjectFactory.cs b/Src/VimTestUtils/Mock/MockObjectFactory.cs index 05bcec2d03..b12ac4e9f7 100644 --- a/Src/VimTestUtils/Mock/MockObjectFactory.cs +++ b/Src/VimTestUtils/Mock/MockObjectFactory.cs @@ -1,5 +1,4 @@ using System; -using Vim.EditorHost; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Formatting; @@ -357,22 +356,23 @@ public static Mock CreateBufferGraph(MockRepository factory = null MockRepository factory = null) { factory = factory ?? new MockRepository(MockBehavior.Strict); + var snapshot = textBuffer.CurrentSnapshot; var endLineValue = endLine ?? startLine; - var caretPositionValue = caretPosition ?? textBuffer.GetLine(startLine).Start.Position; + var caretPositionValue = caretPosition ?? snapshot.GetLineFromLineNumber(startLine).Start.Position; var caret = factory.Create(); caret.SetupGet(x => x.Position).Returns( new CaretPosition( - new VirtualSnapshotPoint(textBuffer.GetPoint(caretPositionValue)), + new VirtualSnapshotPoint(snapshot, caretPositionValue), factory.Create().Object, PositionAffinity.Predecessor)); var firstLine = factory.Create(); firstLine.SetupGet(x => x.VisibilityState).Returns(VisibilityState.FullyVisible); - firstLine.SetupGet(x => x.Start).Returns(textBuffer.GetLine(startLine).Start); + firstLine.SetupGet(x => x.Start).Returns(snapshot.GetLineFromLineNumber(startLine).Start); var lastLine = factory.Create(); lastLine.SetupGet(x => x.VisibilityState).Returns(VisibilityState.FullyVisible); - lastLine.SetupGet(x => x.End).Returns(textBuffer.GetLine(endLineValue).End); + lastLine.SetupGet(x => x.End).Returns(snapshot.GetLineFromLineNumber(endLineValue).End); var lineList = new List() { firstLine.Object, lastLine.Object }; diff --git a/Src/VimTestUtils/Mock/MockVimHost.cs b/Src/VimTestUtils/Mock/MockVimHost.cs index fc74917efe..49861be7f0 100644 --- a/Src/VimTestUtils/Mock/MockVimHost.cs +++ b/Src/VimTestUtils/Mock/MockVimHost.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Vim.EditorHost; using Microsoft.FSharp.Collections; using Microsoft.FSharp.Core; using Microsoft.VisualStudio.Text; diff --git a/Src/VimTestUtils/TestableSynchronizationContext.cs b/Src/VimTestUtils/TestableSynchronizationContext.cs index 714643b891..8a4feea673 100644 --- a/Src/VimTestUtils/TestableSynchronizationContext.cs +++ b/Src/VimTestUtils/TestableSynchronizationContext.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; -using Vim.EditorHost; using Vim.UnitTest.Utilities; namespace Vim.UnitTest diff --git a/Src/VimTestUtils/Utilities/WpfTestInvoker.cs b/Src/VimTestUtils/Utilities/WpfTestInvoker.cs index 4a905e9bd6..b88e75eb75 100644 --- a/Src/VimTestUtils/Utilities/WpfTestInvoker.cs +++ b/Src/VimTestUtils/Utilities/WpfTestInvoker.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Threading; -using Vim.EditorHost; using Xunit.Abstractions; using Xunit.Sdk; diff --git a/Src/VimTestUtils/Utilities/WpfTheoryTestCase.cs b/Src/VimTestUtils/Utilities/WpfTheoryTestCase.cs index baed7d622a..41d91f0e02 100644 --- a/Src/VimTestUtils/Utilities/WpfTheoryTestCase.cs +++ b/Src/VimTestUtils/Utilities/WpfTheoryTestCase.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Threading; -using Vim.EditorHost; using Xunit.Abstractions; using Xunit.Sdk; diff --git a/Src/VimTestUtils/Utilities/WpfTheoryTestCaseRunner.cs b/Src/VimTestUtils/Utilities/WpfTheoryTestCaseRunner.cs index 3cc5f11ec8..9b36a670f6 100644 --- a/Src/VimTestUtils/Utilities/WpfTheoryTestCaseRunner.cs +++ b/Src/VimTestUtils/Utilities/WpfTheoryTestCaseRunner.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Threading; -using Vim.EditorHost; using Xunit.Abstractions; using Xunit.Sdk; diff --git a/Src/VimTestUtils/VimTestUtils.csproj b/Src/VimTestUtils/VimTestUtils.csproj new file mode 100644 index 0000000000..30d37b503a --- /dev/null +++ b/Src/VimTestUtils/VimTestUtils.csproj @@ -0,0 +1,36 @@ + + + x86 + Library + Properties + Vim.UnitTest + Vim.UnitTest.Utils + net472 + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/VimTestUtils/VimTestUtils.projitems b/Src/VimTestUtils/VimTestUtils.projitems deleted file mode 100644 index b127d52557..0000000000 --- a/Src/VimTestUtils/VimTestUtils.projitems +++ /dev/null @@ -1,53 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 3ab92022-a1d2-4ded-a373-5b0aacfe2bc5 - - - VimTestUtils - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/VimTestUtils/VimTestUtils.shproj b/Src/VimTestUtils/VimTestUtils.shproj deleted file mode 100644 index 1e264094b2..0000000000 --- a/Src/VimTestUtils/VimTestUtils.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - 3ab92022-a1d2-4ded-a373-5b0aacfe2bc5 - 14.0 - - - - - - - - diff --git a/Src/VimTestUtils/VimUtil.cs b/Src/VimTestUtils/VimUtil.cs index ac8d850173..9800ec45e2 100644 --- a/Src/VimTestUtils/VimUtil.cs +++ b/Src/VimTestUtils/VimUtil.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Vim.EditorHost; using Microsoft.FSharp.Core; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -12,7 +11,7 @@ namespace Vim.UnitTest { - internal static class VimUtil + public static class VimUtil { internal static readonly FSharpOption MissingRegisterName = FSharpOption.None; @@ -304,7 +303,7 @@ internal static StringData CreateStringDataBlock(params string[] values) return StringData.NewBlock(NonEmptyCollectionUtil.OfSeq(values).Value); } - internal static VisualSpan CreateVisualSpanCharacter(SnapshotSpan span) + public static VisualSpan CreateVisualSpanCharacter(SnapshotSpan span) { return VisualSpan.NewCharacter(new CharacterSpan(span)); } diff --git a/Src/VimTestUtils/WpfFactAttribute.cs b/Src/VimTestUtils/WpfFactAttribute.cs index ace6ca7e28..4f7035eb5d 100644 --- a/Src/VimTestUtils/WpfFactAttribute.cs +++ b/Src/VimTestUtils/WpfFactAttribute.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Vim.VisualStudio.Specific; using Xunit; using Xunit.Extensions; using Xunit.Sdk; @@ -20,37 +19,17 @@ public class WpfTheoryAttribute : TheoryAttribute { } [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] [XunitTestCaseDiscoverer("Vim.UnitTest.Utilities.WpfFactDiscoverer", "Vim.UnitTest.Utils")] - public class LegacyCompletionWpfFactAttribute : WpfFactAttribute + public class ConditionalWpfFactAttribute : FactAttribute { - public override string Skip => VimSpecificUtil.HasLegacyCompletion - ? null - : $"Test only supported on legacy completion"; - - public LegacyCompletionWpfFactAttribute() { } - } - - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - [XunitTestCaseDiscoverer("Vim.UnitTest.Utilities.WpfFactDiscoverer", "Vim.UnitTest.Utils")] - public class Vs2017AndAboveWpfFactAttribute : WpfFactAttribute - { - public override string Skip => -#if VS_SPECIFIC_2015 - $"Test only supported in VS 2017 and above"; -#else - null; -#endif - - public Vs2017AndAboveWpfFactAttribute() { } - } + public bool Condition { get; } - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - [XunitTestCaseDiscoverer("Vim.UnitTest.Utilities.WpfFactDiscoverer", "Vim.UnitTest.Utils")] - public class AsyncCompletionWpfFactAttribute : WpfFactAttribute - { - public override string Skip => VimSpecificUtil.HasAsyncCompletion + public override string Skip => Condition ? null - : $"Test only supported on async completion"; + : "Test not valid in this configuration"; - public AsyncCompletionWpfFactAttribute() { } + public ConditionalWpfFactAttribute(bool condition) + { + Condition = condition; + } } } diff --git a/Test/VimCoreTest/InsertModeIntegrationTest.cs b/Test/VimCoreTest/InsertModeIntegrationTest.cs index 8d9d220534..9f45dc1fe4 100644 --- a/Test/VimCoreTest/InsertModeIntegrationTest.cs +++ b/Test/VimCoreTest/InsertModeIntegrationTest.cs @@ -2605,7 +2605,7 @@ public void ShiftLeft_Normal() /// /// Simple word completion action which accepts the first match /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_Simple_Legacy() { Create("c dog", "cat"); @@ -2615,7 +2615,7 @@ public void WordCompletion_Simple_Legacy() Assert.Equal("cat", _textView.GetLine(0).GetText()); } - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Simple_Async() { Create("c dog", "cat"); @@ -2629,7 +2629,7 @@ public void WordCompletion_Simple_Async() /// /// Simple word completion that is committed with space /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_Legacy_Commit_Space() { Create("c dog", "cat"); @@ -2639,7 +2639,7 @@ public void WordCompletion_Legacy_Commit_Space() Assert.Equal("cat dog", _textView.GetLine(0).GetText()); } - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Async_Commit_Space() { Create("c dog", "cat"); @@ -2653,7 +2653,7 @@ public void WordCompletion_Async_Commit_Space() /// /// Simple word completion that is accepted with ctrl+y /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_Legacy_Commit_CtrlY() { Create("c dog", "cat"); @@ -2663,7 +2663,7 @@ public void WordCompletion_Legacy_Commit_CtrlY() Assert.Equal("cat dog", _textView.GetLine(0).GetText()); } - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Async_Commit_CtrlY() { Create("c dog", "cat"); @@ -2678,7 +2678,7 @@ public void WordCompletion_Async_Commit_CtrlY() /// /// Simulate choosing the second possibility in the completion list /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_ChooseNext_Legacy() { Create("c dog", "cat copter"); @@ -2691,7 +2691,7 @@ public void WordCompletion_ChooseNext_Legacy() /// /// Simulate choosing the second possibility in the completion list /// - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_ChooseNext_Async() { Create("c dog", "cat copter"); @@ -2705,7 +2705,7 @@ public void WordCompletion_ChooseNext_Async() /// /// Simulate Aborting / Exiting a completion /// - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Abort_Legacy() { Create("c dog", "cat copter"); @@ -2720,7 +2720,7 @@ public void WordCompletion_Abort_Legacy() /// /// Simulate Aborting / Exiting a completion /// - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Abort_Async() { Create("c dog", "cat copter"); @@ -2737,7 +2737,7 @@ public void WordCompletion_Abort_Async() /// Typing a char while the completion list is up should cancel it out and /// cause the char to be added to the IVimBuffer /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_TypeAfter_Legacy() { Create("c dog", "cat"); @@ -2747,7 +2747,7 @@ public void WordCompletion_TypeAfter_Legacy() Assert.Equal("cats dog", _textView.GetLine(0).GetText()); } - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_TypeAfter_Async() { Create("c dog", "cat"); @@ -2760,7 +2760,7 @@ public void WordCompletion_TypeAfter_Async() /// /// Esacpe should both stop word completion and leave insert mode. /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_Escape_Legacy() { Create("c dog", "cat"); @@ -2775,7 +2775,7 @@ public void WordCompletion_Escape_Legacy() /// /// Esacpe should both stop word completion and leave insert mode. /// - [AsyncCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasAsyncCompletion)] public void WordCompletion_Escape_Async() { Create("c dog", "cat"); diff --git a/Test/VimCoreTest/VimCoreTest.csproj b/Test/VimCoreTest/VimCoreTest.csproj index 24ec73401a..83e0c891d2 100644 --- a/Test/VimCoreTest/VimCoreTest.csproj +++ b/Test/VimCoreTest/VimCoreTest.csproj @@ -6,6 +6,7 @@ Vim.Core.UnitTest net472 $(VisualStudioTestVersionDefault) + $(DefineConstants);VS_UNIT_TEST_HOST @@ -34,8 +35,8 @@ + - diff --git a/Test/VimWpfTest/VimWpfTest.csproj b/Test/VimWpfTest/VimWpfTest.csproj index d2b0fd6389..ca485f5aaa 100644 --- a/Test/VimWpfTest/VimWpfTest.csproj +++ b/Test/VimWpfTest/VimWpfTest.csproj @@ -6,6 +6,7 @@ Vim.UI.Wpf.UnitTest net472 $(VisualStudioTestVersionDefault) + $(DefineConstants);VS_UNIT_TEST_HOST @@ -28,8 +29,8 @@ + - diff --git a/Test/VsVimSharedTest/MemoryLeakTest.cs b/Test/VsVimSharedTest/MemoryLeakTest.cs index 5f2e608889..80db662421 100644 --- a/Test/VsVimSharedTest/MemoryLeakTest.cs +++ b/Test/VsVimSharedTest/MemoryLeakTest.cs @@ -231,7 +231,7 @@ private static VimEditorHost CreateVimEditorHost() { typeof(global::Vim.VisualStudio.UnitTest.MemoryLeakTest.ServiceProvider), typeof(global::Vim.VisualStudio.UnitTest.MemoryLeakTest.VsEditorAdaptersFactoryService), - typeof(VimErrorDetector) + typeof(global::Vim.EditorHost.Implementation.Misc.VimErrorDetector) }; editorHostFactory.Add(new TypeCatalog(types)); diff --git a/Test/VsVimSharedTest/VsIntegrationTest.cs b/Test/VsVimSharedTest/VsIntegrationTest.cs index 7632c2d880..639abaaa74 100644 --- a/Test/VsVimSharedTest/VsIntegrationTest.cs +++ b/Test/VsVimSharedTest/VsIntegrationTest.cs @@ -293,7 +293,7 @@ public void SwitchMode_InsertKey() /// Make sure that we allow keys like down to make it directly to Insert mode when there is /// an active IWordCompletionSession /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_Down() { Create("c dog", "cat copter"); @@ -311,7 +311,7 @@ public void WordCompletion_Down() /// When there is an active IWordCompletionSession we want to let even direct input go directly /// to insert mode. /// - [LegacyCompletionWpfFact] + [ConditionalWpfFact(EditorSpecificUtil.HasLegacyCompletion)] public void WordCompletion_TypeChar() { Create("c dog", "cat"); diff --git a/Test/VsVimTest2017/VsVimTest2017.csproj b/Test/VsVimTest2017/VsVimTest2017.csproj index adb62f589d..c2ad5dc7b7 100644 --- a/Test/VsVimTest2017/VsVimTest2017.csproj +++ b/Test/VsVimTest2017/VsVimTest2017.csproj @@ -6,6 +6,7 @@ Vim.VisualStudio.Shared.2017.UnitTest net472 15.0 + $(DefineConstants);VS_UNIT_TEST_HOST @@ -52,9 +53,9 @@ + - diff --git a/Test/VsVimTest2019/VsVimTest2019.csproj b/Test/VsVimTest2019/VsVimTest2019.csproj index 2b9fa30ffb..e4118abdfc 100644 --- a/Test/VsVimTest2019/VsVimTest2019.csproj +++ b/Test/VsVimTest2019/VsVimTest2019.csproj @@ -6,6 +6,7 @@ Vim.VisualStudio.Shared.2019.UnitTest net472 16.0 + $(DefineConstants);VS_UNIT_TEST_HOST @@ -52,9 +53,9 @@ + - diff --git a/VsVim.sln b/VsVim.sln index 899f9f1a99..229852ffaa 100644 --- a/VsVim.sln +++ b/VsVim.sln @@ -50,33 +50,28 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VsVimSharedTest", "Test\VsV EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VimEditorHost", "Src\VimEditorHost\VimEditorHost.shproj", "{5E2E483E-6D89-4C17-B4A6-7153654B06BF}" EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VimTestUtils", "Src\VimTestUtils\VimTestUtils.shproj", "{3AB92022-A1D2-4DED-A373-5B0AACFE2BC5}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VsVim2019", "Src\VsVim2019\VsVim2019.csproj", "{1AACC1AC-A8C6-4281-A080-91A4A3C5F21D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VsVimTest2017", "Test\VsVimTest2017\VsVimTest2017.csproj", "{E9FB3820-5279-4489-B9C7-6FDBF44F07F2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VsVimTest2019", "Test\VsVimTest2019\VsVimTest2019.csproj", "{FF0EE51E-BF6D-4A81-A5D3-7EF572F68303}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VimTestUtils", "Src\VimTestUtils\VimTestUtils.csproj", "{AFA7BF34-3687-453F-80A0-46396ACE5E78}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution Src\VimSpecific\VimSpecific.projitems*{1aacc1ac-a8c6-4281-a080-91a4a3c5f21d}*SharedItemsImports = 5 Src\VsVimShared\VsVimShared.projitems*{1aacc1ac-a8c6-4281-a080-91a4a3c5f21d}*SharedItemsImports = 5 Src\VimSpecific\VimSpecific.projitems*{2e2a2014-666c-4b22-83f2-4a94102247c6}*SharedItemsImports = 5 Src\VsVimShared\VsVimShared.projitems*{2e2a2014-666c-4b22-83f2-4a94102247c6}*SharedItemsImports = 5 - Src\VimTestUtils\VimTestUtils.projitems*{3ab92022-a1d2-4ded-a373-5b0aacfe2bc5}*SharedItemsImports = 13 Src\VimEditorHost\VimEditorHost.projitems*{5e2e483e-6d89-4c17-b4a6-7153654b06bf}*SharedItemsImports = 13 Test\VsVimSharedTest\VsVimSharedTest.projitems*{5f7f6c25-d91c-4143-ac7d-df29a0a831ef}*SharedItemsImports = 13 Src\VsVimShared\VsVimShared.projitems*{6dbed15c-fc2c-46e9-914d-685518573f0d}*SharedItemsImports = 13 Src\VimSpecific\VimSpecific.projitems*{797c1463-3984-47be-8cd2-4ff68d1e30da}*SharedItemsImports = 5 - Src\VimTestUtils\VimTestUtils.projitems*{797c1463-3984-47be-8cd2-4ff68d1e30da}*SharedItemsImports = 5 Src\VimSpecific\VimSpecific.projitems*{8db1c327-21a1-448b-a7a1-23eef6baa785}*SharedItemsImports = 5 Src\VimSpecific\VimSpecific.projitems*{b4fc7c81-e500-47c8-a884-2dbb7ca77123}*SharedItemsImports = 5 - Src\VimTestUtils\VimTestUtils.projitems*{b4fc7c81-e500-47c8-a884-2dbb7ca77123}*SharedItemsImports = 5 Src\VimSpecific\VimSpecific.projitems*{de7e4031-d2e8-450e-8558-f00a6f19fa5c}*SharedItemsImports = 13 - Src\VimTestUtils\VimTestUtils.projitems*{e9fb3820-5279-4489-b9c7-6fdbf44f07f2}*SharedItemsImports = 5 Test\VsVimSharedTest\VsVimSharedTest.projitems*{e9fb3820-5279-4489-b9c7-6fdbf44f07f2}*SharedItemsImports = 5 - Src\VimTestUtils\VimTestUtils.projitems*{ff0ee51e-bf6d-4a81-a5d3-7ef572f68303}*SharedItemsImports = 5 Test\VsVimSharedTest\VsVimSharedTest.projitems*{ff0ee51e-bf6d-4a81-a5d3-7ef572f68303}*SharedItemsImports = 5 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -335,6 +330,30 @@ Global {FF0EE51E-BF6D-4A81-A5D3-7EF572F68303}.ReleaseMac|Mixed Platforms.Build.0 = Release|Any CPU {FF0EE51E-BF6D-4A81-A5D3-7EF572F68303}.ReleaseMac|x86.ActiveCfg = Release|Any CPU {FF0EE51E-BF6D-4A81-A5D3-7EF572F68303}.ReleaseMac|x86.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|x86.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Debug|x86.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|Any CPU.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|Mixed Platforms.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|Mixed Platforms.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|x86.ActiveCfg = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.DebugMac|x86.Build.0 = Debug|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|Any CPU.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|x86.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.Release|x86.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|Any CPU.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|Any CPU.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|Mixed Platforms.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|Mixed Platforms.Build.0 = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|x86.ActiveCfg = Release|Any CPU + {AFA7BF34-3687-453F-80A0-46396ACE5E78}.ReleaseMac|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE