Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Sep 12, 2022
1 parent d0b329c commit 1a57252
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.TodoComments;

Expand Down Expand Up @@ -51,15 +52,21 @@ private async Task<ImmutableArray<DiagnosticData>> GetTodoCommentDiagnosticsAsyn
if (this.Document is not Document document)
return ImmutableArray<DiagnosticData>.Empty;

var service = document.GetLanguageService<ITodoCommentDataService>();
var service = document.GetLanguageService<ITodoCommentService>();
if (service == null)
return ImmutableArray<DiagnosticData>.Empty;

var tokenList = document.Project.Solution.Options.GetOption(TodoCommentOptionsStorage.TokenList);
var descriptors = GetAndCacheDescriptors(tokenList);

var comments = await service.GetTodoCommentDataAsync(document, descriptors, cancellationToken).ConfigureAwait(false);
return comments.SelectAsArray(comment => new DiagnosticData(
var comments = await service.GetTodoCommentsAsync(document, descriptors, cancellationToken).ConfigureAwait(false);
if (comments.Length == 0)
return ImmutableArray<DiagnosticData>.Empty;

using var _ = ArrayBuilder<TodoCommentData>.GetInstance(out var converted);
await TodoComment.ConvertAsync(document, comments, converted, cancellationToken).ConfigureAwait(false);

return converted.SelectAsArray(comment => new DiagnosticData(
id: "TODO",
category: "TODO",
message: comment.Message,
Expand All @@ -73,16 +80,16 @@ private async Task<ImmutableArray<DiagnosticData>> GetTodoCommentDiagnosticsAsyn
language: document.Project.Language,
location: new DiagnosticDataLocation(
document.Id,
originalFilePath: comment.Span.Path,
mappedFilePath: comment.MappedSpan.Path,
originalStartLine: comment.Span.StartLinePosition.Line,
originalStartColumn: comment.Span.StartLinePosition.Character,
originalEndLine: comment.Span.EndLinePosition.Line,
originalEndColumn: comment.Span.EndLinePosition.Character,
mappedStartLine: comment.MappedSpan.StartLinePosition.Line,
mappedStartColumn: comment.MappedSpan.StartLinePosition.Character,
mappedEndLine: comment.MappedSpan.EndLinePosition.Line,
mappedEndColumn: comment.MappedSpan.EndLinePosition.Character)));
originalFilePath: comment.OriginalFilePath,
mappedFilePath: comment.MappedFilePath,
originalStartLine: comment.OriginalLine,
originalStartColumn: comment.OriginalColumn,
originalEndLine: comment.OriginalLine,
originalEndColumn: comment.OriginalColumn,
mappedStartLine: comment.MappedLine,
mappedStartColumn: comment.MappedColumn,
mappedEndLine: comment.MappedLine,
mappedEndColumn: comment.MappedColumn)));
}

private static ImmutableArray<TodoCommentDescriptor> GetAndCacheDescriptors(ImmutableArray<string> tokenList)
Expand Down

0 comments on commit 1a57252

Please sign in to comment.