未验证 提交 7a17eb72 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #42821 from CyrusNajmabadi/legacyTodo

Add back in a legacy todo-comment entrypoint for TypeScript.
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Threading;
......@@ -29,12 +31,14 @@ public TodoComment(TodoCommentDescriptor descriptor, string message, int positio
}
internal TodoCommentData CreateSerializableData(
Document document, SourceText text, SyntaxTree tree)
Document document, SourceText text, SyntaxTree? tree)
{
// make sure given position is within valid text range.
var textSpan = new TextSpan(Math.Min(text.Length, Math.Max(0, Position)), 0);
var location = tree.GetLocation(textSpan);
var location = tree == null
? Location.Create(document.FilePath!, textSpan, text.Lines.GetLinePositionSpan(textSpan))
: tree.GetLocation(textSpan);
var originalLineInfo = location.GetLineSpan();
var mappedLineInfo = location.GetMappedLineSpan();
......
// 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;
using Microsoft.CodeAnalysis.TodoComments;
namespace Microsoft.VisualStudio.LanguageServices.ExternalAccess.VSTypeScript.Api
{
internal interface IVsTypeScriptTodoCommentService
{
/// <summary>
/// Legacy entry-point to allow existing in-process TypeScript language service to report todo comments.
/// TypeScript is responsible for determining when to compute todo comments (for example, on <see
/// cref="Workspace.WorkspaceChanged"/>). This can be called on any thread.
/// </summary>
Task ReportTodoCommentsAsync(Document document, ImmutableArray<TodoComment> todoComments, CancellationToken cancellationToken);
}
}
......@@ -5,7 +5,6 @@
#nullable enable
using System.Threading;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.TodoComments
{
......
......@@ -21,14 +21,20 @@
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.TodoComments;
using Microsoft.VisualStudio.LanguageServices.ExternalAccess.VSTypeScript.Api;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.TodoComments
{
[Export(typeof(IVisualStudioTodoCommentsService))]
[Export(typeof(IVsTypeScriptTodoCommentService))]
internal class VisualStudioTodoCommentsService
: ForegroundThreadAffinitizedObject, IVisualStudioTodoCommentsService, ITodoCommentsListener, ITodoListProvider
: ForegroundThreadAffinitizedObject,
IVisualStudioTodoCommentsService,
ITodoCommentsListener,
ITodoListProvider,
IVsTypeScriptTodoCommentService
{
private readonly VisualStudioWorkspaceImpl _workspace;
private readonly EventListenerTracker<ITodoListProvider> _eventListenerTracker;
......@@ -181,20 +187,38 @@ public ImmutableArray<TodoCommentData> GetTodoItems(Workspace workspace, Documen
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public Task ReportTodoCommentDataAsync(DocumentId documentId, ImmutableArray<TodoCommentData> infos, CancellationToken cancellationToken)
public Task OnDocumentRemovedAsync(DocumentId documentId, CancellationToken cancellationToken)
{
Contract.ThrowIfNull(_workQueue);
_workQueue.AddWork(new DocumentAndComments(documentId, infos));
_documentToInfos.TryRemove(documentId, out _);
return Task.CompletedTask;
}
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public Task OnDocumentRemovedAsync(DocumentId documentId, CancellationToken cancellationToken)
public Task ReportTodoCommentDataAsync(DocumentId documentId, ImmutableArray<TodoCommentData> infos, CancellationToken cancellationToken)
{
_documentToInfos.TryRemove(documentId, out _);
Contract.ThrowIfNull(_workQueue);
_workQueue.AddWork(new DocumentAndComments(documentId, infos));
return Task.CompletedTask;
}
/// <inheritdoc cref="IVsTypeScriptTodoCommentService.ReportTodoCommentsAsync(Document, ImmutableArray{TodoComment}, CancellationToken)"/>
async Task IVsTypeScriptTodoCommentService.ReportTodoCommentsAsync(
Document document, ImmutableArray<TodoComment> todoComments, CancellationToken cancellationToken)
{
using var _ = ArrayBuilder<TodoCommentData>.GetInstance(out var converted);
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var tree = document.SupportsSyntaxTree
? await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false)
: null;
foreach (var comment in todoComments)
converted.Add(comment.CreateSerializableData(document, text, tree));
await ReportTodoCommentDataAsync(
document.Id, converted.ToImmutable(), cancellationToken).ConfigureAwait(false);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册