Skip to content

Commit

Permalink
Add TS external access API for ICommentSelectionService
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Apr 11, 2022
1 parent ae66fbc commit d9c3610
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
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);
}
}
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))
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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;

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(IVSTypeScriptCommentSelectionServiceImplementation impl)
=> _impl = impl;

public async Task<CommentSelectionInfo> GetInfoAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
{
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)
=> _impl.FormatAsync(document, changes, cancellationToken);
}
}

0 comments on commit d9c3610

Please sign in to comment.