Skip to content

Commit b23154f

Browse files
authored
Implement TypeScript ExternalAccess wrappers for AsynchronousOperationListener (#77318)
1 parent e7f61a2 commit b23154f

File tree

7 files changed

+106
-24
lines changed

7 files changed

+106
-24
lines changed

src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptAsynchronousTaggerProvider.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,23 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
76
using Microsoft.CodeAnalysis.Editor.Tagging;
87
using Microsoft.CodeAnalysis.Shared.TestHooks;
9-
using Microsoft.CodeAnalysis.Workspaces;
108
using Microsoft.VisualStudio.Text.Tagging;
119

1210
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
1311

1412
internal abstract class VSTypeScriptAsynchronousTaggerProvider<TTag> : AsynchronousViewTaggerProvider<TTag>
1513
where TTag : ITag
1614
{
17-
[Obsolete("Use constructor that takes ITextBufferVisibilityTracker. Use `[Import(AllowDefault = true)] ITextBufferVisibilityTracker? visibilityTracker`")]
18-
protected VSTypeScriptAsynchronousTaggerProvider(
19-
IThreadingContext threadingContext,
20-
IAsynchronousOperationListenerProvider asyncListenerProvider,
21-
VSTypeScriptGlobalOptions globalOptions)
22-
: this(
23-
threadingContext,
24-
globalOptions,
25-
visibilityTracker: null,
26-
asyncListenerProvider)
27-
{
28-
}
29-
30-
[Obsolete("Use constructor that takes a single TaggerHost")]
31-
protected VSTypeScriptAsynchronousTaggerProvider(
32-
IThreadingContext threadingContext,
33-
VSTypeScriptGlobalOptions globalOptions,
34-
ITextBufferVisibilityTracker? visibilityTracker,
35-
IAsynchronousOperationListenerProvider asyncListenerProvider)
36-
: base(new TaggerHost(threadingContext, globalOptions.Service, visibilityTracker, asyncListenerProvider), FeatureAttribute.Classification)
15+
[Obsolete("Use constructor that takes VSTypeScriptTaggerHost")]
16+
protected VSTypeScriptAsynchronousTaggerProvider(TaggerHost taggerHost)
17+
: base(taggerHost, FeatureAttribute.Classification)
3718
{
3819
}
3920

40-
protected VSTypeScriptAsynchronousTaggerProvider(TaggerHost taggerHost)
41-
: base(taggerHost, FeatureAttribute.Classification)
21+
protected VSTypeScriptAsynchronousTaggerProvider(VSTypeScriptTaggerHost taggerHost)
22+
: base(taggerHost.UnderlyingObject, FeatureAttribute.Classification)
4223
{
4324
}
4425
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Composition;
7+
using Microsoft.CodeAnalysis.Editor.Tagging;
8+
using Microsoft.CodeAnalysis.Host.Mef;
9+
10+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
11+
12+
[Export(typeof(VSTypeScriptTaggerHost)), Shared]
13+
[method: ImportingConstructor]
14+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
15+
internal sealed class VSTypeScriptTaggerHost(TaggerHost underlyingObject)
16+
{
17+
internal TaggerHost UnderlyingObject { get; } = underlyingObject;
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.Shared.TestHooks;
7+
8+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
9+
10+
internal static class TaskExtensions
11+
{
12+
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
13+
public static Task CompletesAsyncOperation(this Task task, VSTypeScriptAsyncToken asyncToken)
14+
#pragma warning restore VSTHRD200
15+
=> task.CompletesAsyncOperation(asyncToken.UnderlyingObject);
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Microsoft.CodeAnalysis.Shared.TestHooks;
7+
8+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
9+
10+
internal sealed class VSTypeScriptAsyncToken(IAsyncToken underlyingObject) : IDisposable
11+
{
12+
internal IAsyncToken UnderlyingObject
13+
=> underlyingObject;
14+
15+
public void Dispose()
16+
=> UnderlyingObject.Dispose();
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.CompilerServices;
6+
using Microsoft.CodeAnalysis.Shared.TestHooks;
7+
8+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
9+
10+
internal readonly struct VSTypeScriptAsynchronousOperationListener(IAsynchronousOperationListener underlyingObject)
11+
{
12+
public VSTypeScriptAsyncToken BeginAsyncOperation(string name, object? tag = null, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
13+
=> new(underlyingObject.BeginAsyncOperation(name, tag, filePath, lineNumber));
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Composition;
7+
using Microsoft.CodeAnalysis.Host.Mef;
8+
using Microsoft.CodeAnalysis.Shared.TestHooks;
9+
10+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
11+
12+
[Shared]
13+
[Export(typeof(VSTypeScriptAsynchronousOperationListenerProvider))]
14+
[method: ImportingConstructor]
15+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
16+
internal sealed class VSTypeScriptAsynchronousOperationListenerProvider(
17+
IAsynchronousOperationListenerProvider provider)
18+
{
19+
public VSTypeScriptAsynchronousOperationListener GetListener(string featureName)
20+
=> new(provider.GetListener(featureName));
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis.Shared.TestHooks;
6+
7+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
8+
9+
internal static class VSTypeScriptFeatureAttribute
10+
{
11+
public const string RenameTracking = FeatureAttribute.RenameTracking;
12+
public const string Snippets = FeatureAttribute.Snippets;
13+
public const string Workspace = FeatureAttribute.Workspace;
14+
public const string SolutionCrawlerLegacy = FeatureAttribute.SolutionCrawlerLegacy;
15+
}

0 commit comments

Comments
 (0)