-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60687 from tmat/TSExternalAccess
Add TS external access API for ICommentSelectionService
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...able/ExternalAccess/VSTypeScript/Api/IVSTypeScriptCommentSlectionServiceImplementation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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. | ||
|
||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api | ||
{ | ||
internal interface IVSTypeScriptCommentSelectionServiceImplementation : ILanguageService | ||
{ | ||
Task<VSTypeScriptCommentSelectionInfo> GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken); | ||
|
||
Task<Document> FormatAsync(Document document, ImmutableArray<TextSpan> changes, CancellationToken cancellationToken); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...eatures/Core/Portable/ExternalAccess/VSTypeScript/Api/VSTypeScriptCommentSelectionInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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. | ||
|
||
using Microsoft.CodeAnalysis.CommentSelection; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api | ||
{ | ||
internal readonly struct VSTypeScriptCommentSelectionInfo | ||
{ | ||
internal readonly CommentSelectionInfo UnderlyingObject; | ||
|
||
internal VSTypeScriptCommentSelectionInfo(CommentSelectionInfo underlyingObject) | ||
{ | ||
UnderlyingObject = underlyingObject; | ||
} | ||
|
||
public VSTypeScriptCommentSelectionInfo( | ||
bool supportsSingleLineComment, | ||
bool supportsBlockComment, | ||
string singleLineCommentString, | ||
string blockCommentStartString, | ||
string blockCommentEndString) : this(new( | ||
supportsSingleLineComment, | ||
supportsBlockComment, | ||
singleLineCommentString, | ||
blockCommentStartString, | ||
blockCommentEndString)) | ||
{ | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CommentSelection; | ||
using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; | ||
using Microsoft.CodeAnalysis.Formatting; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript | ||
{ | ||
[ExportLanguageService(typeof(ICommentSelectionService), InternalLanguageNames.TypeScript), Shared] | ||
internal sealed class VSTypeScriptCommentSelectionService : ICommentSelectionService | ||
{ | ||
private readonly IVSTypeScriptCommentSelectionServiceImplementation? _impl; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public VSTypeScriptCommentSelectionService( | ||
// Optional to work around test issue: https://github.com/dotnet/roslyn/issues/60690 | ||
[Import(AllowDefault = true)] IVSTypeScriptCommentSelectionServiceImplementation? impl) | ||
{ | ||
_impl = impl; | ||
} | ||
|
||
public async Task<CommentSelectionInfo> GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) | ||
{ | ||
// Will never be null in product. | ||
Contract.ThrowIfNull(_impl); | ||
|
||
var info = await _impl.GetInfoAsync(document, textSpan, cancellationToken).ConfigureAwait(false); | ||
return info.UnderlyingObject; | ||
} | ||
|
||
public Task<Document> FormatAsync(Document document, ImmutableArray<TextSpan> changes, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken) | ||
{ | ||
// Will never be null in product. | ||
Contract.ThrowIfNull(_impl); | ||
|
||
return _impl.FormatAsync(document, changes, cancellationToken); | ||
} | ||
} | ||
} |