Skip to content

Commit acce64b

Browse files
authored
Merge pull request #96 from mhutch/no-minieditor
Remove MiniEditor dependency
2 parents 73ce703 + a7f689f commit acce64b

27 files changed

+488
-70
lines changed

.github/workflows/main.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,30 @@ jobs:
66
build:
77
strategy:
88
matrix:
9-
os: [ ubuntu-latest, windows-latest ]
9+
os:
10+
- name: windows-latest
11+
sln: MonoDevelop.Xml.sln
12+
- name: ubuntu-latest
13+
sln: NoVSEditor.slnf
1014
config: [ Debug ]
1115
fail-fast: false
12-
runs-on: ${{ matrix.os }}
16+
runs-on: ${{ matrix.os.name }}
1317

1418
steps:
1519
- uses: actions/checkout@v4
1620
with:
1721
fetch-depth: 0 # GitVersioning needs deep clone
18-
submodules: recursive
1922

2023
- uses: actions/setup-dotnet@v4
2124
with:
2225
dotnet-version: |
2326
8.0.x
2427
2528
- name: Restore
26-
run: dotnet restore MonoDevelop.Xml.sln
29+
run: dotnet restore ${{ matrix.os.sln }}
2730

2831
- name: Build
29-
run: dotnet build MonoDevelop.Xml.sln -c ${{ matrix.config }} --no-restore
32+
run: dotnet build ${{ matrix.os.sln }} -c ${{ matrix.config }} --no-restore
3033

3134
- name: Test
32-
run: dotnet test -c ${{ matrix.config }} --no-build
35+
run: dotnet test -c ${{ matrix.config }} --no-build ${{ matrix.os.sln }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[Bb]in/
77
packages/
88
TestResults/
9+
artifacts/
910

1011
# globs
1112
Makefile.in

.gitmodules

-3
This file was deleted.

Core.Tests/MonoDevelop.Xml.Core.Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<!-- conditionally only build net48 on !windows so nunit doesn't try to run them -->
56
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">net48;net8.0</TargetFrameworks>
67
<NUnitDisableSupportAssemblies>true</NUnitDisableSupportAssemblies>
78
<RootNamespace>MonoDevelop.Xml.Tests</RootNamespace>
@@ -31,5 +32,7 @@
3132
<PackageReference Include="NUnit.Analyzers" />
3233
<PackageReference Include="NUnit3TestAdapter" />
3334
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
35+
<!-- upgrade vulnerable transitive dependencies -->
36+
<PackageReference Include="System.Text.Json" />
3437
</ItemGroup>
3538
</Project>

Directory.Build.props

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)private.snk</AssemblyOriginatorKeyFile>
55
<LangVersion>latest</LangVersion>
66
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
7+
<UseArtifactsOutput>True</UseArtifactsOutput>
78
</PropertyGroup>
89
</Project>

Directory.Packages.props

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
<Project>
2-
<PropertyGroup>
3-
<!--
4-
We cannot go higher than 17.5.
5-
IConnectedSpan gained a new Disconnect() method in 17.6, which we cannot implement as it is internal.
6-
-->
7-
<VSEditorNugetVersion>17.5.279</VSEditorNugetVersion>
8-
</PropertyGroup>
92
<ItemGroup>
103
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
114
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
125
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
13-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14-
<PackageVersion Include="Microsoft.VisualStudio.ImageCatalog" Version="17.5.33428.366" />
15-
<PackageVersion Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" Version="17.5.33428.366" />
16-
<PackageVersion Include="Microsoft.VisualStudio.Language.Intellisense" Version="$(VSEditorNugetVersion)" />
17-
<PackageVersion Include="Microsoft.VisualStudio.Language.StandardClassification" Version="$(VSEditorNugetVersion)" />
18-
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.5.22" />
6+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
7+
<PackageVersion Include="Microsoft.VisualStudio.ImageCatalog" Version="17.10.40170" />
8+
<PackageVersion Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" Version="17.10.40152" />
9+
<PackageVersion Include="Microsoft.VisualStudio.Language.Intellisense" Version="17.10.191" />
10+
<PackageVersion Include="Microsoft.VisualStudio.Language.StandardClassification" Version="17.10.191" />
11+
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.10.48" />
12+
<PackageVersion Include="Microsoft.VisualStudio.Editor" Version="17.10.191" />
1913
<PackageVersion Include="NUnit" Version="3.14.0" />
2014
<PackageVersion Include="NUnit.Analyzers" Version="3.10.0" />
21-
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
15+
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
2216
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
17+
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
18+
<PackageVersion Include="Microsoft.VisualStudio.Utilities" Version="17.10.40170" />
19+
<PackageVersion Include="Microsoft.VisualStudio.Interop" Version="17.10.40170" />
20+
<PackageVersion Include="Microsoft.VisualStudio.GraphModel" Version="17.10.40170" />
21+
<PackageVersion Include="Microsoft.VisualStudio.Imaging" Version="17.10.40170" />
22+
<PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.10.40170" />
23+
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.10.40170" />
24+
<PackageVersion Include="StreamJsonRpc" Version="2.19.27" />
25+
<PackageVersion Include="Microsoft.VisualStudio.Platform.VSEditor" Version="17.10.191" />
26+
<PackageVersion Include="Microsoft.VisualStudio.Text.Internal" Version="17.10.191" />
27+
<PackageVersion Include="BasicUndo" Version="0.9.3" />
28+
<PackageVersion Include="Microsoft.VisualStudio.Language" Version="17.10.191" />
29+
<PackageVersion Include="Microsoft.IO.Redist" Version="6.0.1" />
2330
</ItemGroup>
2431
<ItemGroup>
25-
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" />
26-
<GlobalPackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All"/>
32+
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.143" PrivateAssets="all" />
33+
<GlobalPackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.4" PrivateAssets="All"/>
2734
</ItemGroup>
2835
</Project>

Editor.Tests/Commands/ExpandSelectionTests.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ this is some text
6363

6464
const string TextNode = "this is some text";
6565

66+
const string TextNodeWithWhitespace = @" this is some text
67+
";
68+
6669
const string AttributesFoo = @"hello=""hi"" goodbye=""bye""";
6770

6871
const string AttributeHello = @"hello=""hi""";
@@ -91,16 +94,19 @@ this is some text
9194

9295
const string CommentBar = @"<!--another comment-->";
9396

97+
const string CommentBarWithWhitespace = @" <!--another comment-->
98+
";
99+
94100
//args are document, line, col, then the expected sequence of expansions
95101
[Test]
96102
[TestCase (Document, 1, 2, CommentDoc)]
97103
[TestCase (Document, 3, 2, "foo", ElementFoo, ElementWithBodyFoo)]
98104
[TestCase (Document, 3, 3, "foo", ElementFoo, ElementWithBodyFoo)]
99105
[TestCase (Document, 3, 15, "hi", AttributeHello, AttributesFoo, ElementFoo, ElementWithBodyFoo)]
100106
[TestCase (Document, 3, 7, "hello", AttributeHello, AttributesFoo, ElementFoo, ElementWithBodyFoo)]
101-
[TestCase (Document, 4, 7, TextNode, BodyFoo, ElementWithBodyFoo)]
107+
[TestCase (Document, 4, 7, "is", TextNode, TextNodeWithWhitespace, BodyFoo, ElementWithBodyFoo)]
102108
[TestCase (Document, 5, 22, "done", AttributeThing, ElementBaz, BodyBar, ElementWithBodyBar, BodyFoo, ElementWithBodyFoo)]
103-
[TestCase (Document, 6, 12, CommentBar, BodyBar, ElementWithBodyBar, BodyFoo, ElementWithBodyFoo)]
109+
[TestCase (Document, 6, 12, CommentBar, CommentBarWithWhitespace, BodyBar, ElementWithBodyBar, BodyFoo, ElementWithBodyFoo)]
104110
public async Task TestExpandShrink (object[] args)
105111
{
106112
var buffer = CreateTextBuffer ((string)args[0]);

Editor.Tests/Commands/SmartIndentTests.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
5-
using System.Collections.Generic;
4+
using System.Threading.Tasks;
65

76
using Microsoft.VisualStudio.Text.Editor;
87

@@ -27,7 +26,7 @@ class SmartIndentTests : XmlEditorTest
2726
[TestCase ("<a>w|</a>", 0)] // no indent for closing tag
2827
[TestCase ("<a>w| </a>", 0)] // no indent for closing tag preceded by whitespace
2928
[TestCase ("<a>|w</a>", 4)] // indent when content is present
30-
public void TestSmartIndent (string doc, int expectedIndent)
29+
public async Task TestSmartIndent (string doc, int expectedIndent)
3130
{
3231
var caretPos = doc.IndexOf ('|');
3332
if (caretPos > -1) {
@@ -38,7 +37,9 @@ public void TestSmartIndent (string doc, int expectedIndent)
3837
doc += "\n";
3938
}
4039

40+
await Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync ();
4141
var textView = CreateTextView (doc);
42+
4243
var line = textView.TextBuffer.CurrentSnapshot.GetLineFromPosition (caretPos);
4344
GetParser (textView.TextBuffer);
4445

Editor.Tests/EditorCatalog.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class EditorCatalog
3333
/// <returns>Enumeration of objects of requested type</returns>
3434
public IEnumerable<T> GetServices<T> () where T : class => host.GetServices<T> ();
3535

36-
public ITextViewFactoryService TextViewFactory => GetService<ITextViewFactoryService> ();
36+
public ITextEditorFactoryService TextEditorFactory => GetService<ITextEditorFactoryService> ();
3737
public ITextDocumentFactoryService TextDocumentFactoryService => GetService<ITextDocumentFactoryService> ();
3838
public IFileToContentTypeService FileToContentTypeService => GetService<IFileToContentTypeService> ();
3939
public ITextBufferFactoryService BufferFactoryService => GetService<ITextBufferFactoryService> ();

Editor.Tests/EditorTest.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Threading.Tasks;
56

67
using Microsoft.VisualStudio.Text;
78
using Microsoft.VisualStudio.Text.Editor;
@@ -26,11 +27,15 @@ public abstract class EditorTest
2627

2728
public virtual ITextView CreateTextView (string documentText, string filename = null)
2829
{
30+
if (!Catalog.JoinableTaskContext.IsOnMainThread) {
31+
throw new InvalidOperationException ("Must be on main thread");
32+
}
33+
2934
var buffer = CreateTextBuffer (documentText);
3035
if (filename != null) {
3136
Catalog.TextDocumentFactoryService.CreateTextDocument (buffer, filename);
3237
}
33-
return Catalog.TextViewFactory.CreateTextView (buffer);
38+
return Catalog.TextEditorFactory.CreateTextView (buffer);
3439
}
3540

3641
public virtual ITextBuffer CreateTextBuffer (string documentText)

Editor.Tests/Extensions/CompletionTestExtensions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66

77
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Data;
8+
using Microsoft.VisualStudio.Shell;
89
using Microsoft.VisualStudio.Text;
910
using Microsoft.VisualStudio.Text.Editor;
1011

@@ -14,15 +15,16 @@ namespace MonoDevelop.Xml.Editor.Tests.Extensions
1415
{
1516
public static class CompletionTestExtensions
1617
{
17-
public static Task<CompletionContext> GetCompletionContext (
18+
public static async Task<CompletionContext> GetCompletionContext (
1819
this EditorTest test,
1920
string documentText, CompletionTriggerReason reason = default, char triggerChar = '\0', char caretMarker = '$', string filename = default, CancellationToken cancellationToken = default)
2021
{
2122
(documentText, var caretOffset) = TextWithMarkers.ExtractSinglePosition (documentText, caretMarker);
2223

24+
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync ();
2325
var textView = test.CreateTextView (documentText, filename);
2426

25-
return test.GetCompletionContext (textView, caretOffset, reason, triggerChar, cancellationToken);
27+
return await test.GetCompletionContext (textView, caretOffset, reason, triggerChar, cancellationToken);
2628
}
2729

2830
public static async Task<CompletionContext> GetCompletionContext (

Editor.Tests/Extensions/EditorCommandExtensions.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ public static async Task TestCommands (
6565
Func<ITextView,Task> initialize = null,
6666
CancellationToken cancellationToken = default)
6767
{
68-
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync (cancellationToken);
69-
70-
var textView = test.CreateTextView (beforeDocumentText, filename);
68+
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync ();
69+
var textView = test.CreateTextView(beforeDocumentText, filename);
7170
textView.Caret.MoveTo (new SnapshotPoint (textView.TextBuffer.CurrentSnapshot, beforeCaretOffset));
7271

7372
if (initialize is not null) {

Editor.Tests/Extensions/QuickInfoTestExtensions.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MonoDevelop.Xml.Editor.Tests.Extensions
1313
{
1414
public static class QuickInfoTestExtensions
1515
{
16-
public static Task<QuickInfoItemsCollection> GetQuickInfoItems (
16+
public static async Task<QuickInfoItemsCollection> GetQuickInfoItems (
1717
this EditorTest test,
1818
string documentText,
1919
char caretMarker = '$')
@@ -24,8 +24,9 @@ public static Task<QuickInfoItemsCollection> GetQuickInfoItems (
2424
}
2525
documentText = documentText.Substring (0, caretOffset) + documentText.Substring (caretOffset + 1);
2626

27-
var textView = test.CreateTextView (documentText);
28-
return test.GetQuickInfoItems (textView, caretOffset);
27+
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync ();
28+
var textView = test.CreateTextView(documentText);
29+
return await test.GetQuickInfoItems (textView, caretOffset);
2930
}
3031

3132
public static async Task<QuickInfoItemsCollection> GetQuickInfoItems (
@@ -37,8 +38,6 @@ public static async Task<QuickInfoItemsCollection> GetQuickInfoItems (
3738
var broker = test.Catalog.AsyncQuickInfoBroker;
3839
var snapshot = textView.TextBuffer.CurrentSnapshot;
3940

40-
await test.Catalog.JoinableTaskContext.Factory.SwitchToMainThreadAsync ();
41-
4241
var items = await broker.GetQuickInfoItemsAsync (
4342
textView,
4443
snapshot.CreateTrackingPoint (caretPosition, PointTrackingMode.Positive),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using Microsoft.VisualStudio.Text;
4+
5+
namespace Microsoft.VisualStudio.MiniEditor
6+
{
7+
/// <summary>
8+
/// Implementation of <see cref="IExtensionErrorHandler"/>.
9+
/// Visual Studio provides error handler which writes to activity log and displays messages.
10+
/// This implementation forwards the exception to subscribers of <see cref="ExceptionHandled"/> event
11+
/// </summary>
12+
[Export (typeof (IExtensionErrorHandler))]
13+
public class CustomErrorHandler : IExtensionErrorHandler
14+
{
15+
// GuardedOperations imports IExtensionErrorHandler via Lazy<IExtensionErrorHandler> and
16+
// hence gets its own private instance. to access the event from the host we have to make it static
17+
public static event EventHandler<ExceptionEventArgs> ExceptionHandled;
18+
19+
public void HandleError (object sender, Exception exception)
20+
=> ExceptionHandled?.Invoke (sender, new ExceptionEventArgs (exception));
21+
22+
public class ExceptionEventArgs : EventArgs
23+
{
24+
public Exception Exception { get; }
25+
public ExceptionEventArgs (Exception ex)
26+
{
27+
Exception = ex;
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)