Skip to content

Commit e5924c0

Browse files
authored
Allow Razor to get task list items for a document (#80102)
Missed this when doing diagnostics
2 parents a083089 + a8af102 commit e5924c0

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/LanguageServer/Protocol/Handler/Diagnostics/DiagnosticSources/TaskListDiagnosticSource.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ internal sealed class TaskListDiagnosticSource(Document document, IGlobalOptionS
2929

3030
private readonly IGlobalOptionService _globalOptions = globalOptions;
3131

32-
public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
33-
RequestContext context, CancellationToken cancellationToken)
32+
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken)
33+
=> GetTaskListItemsAsync(this.Document, _globalOptions, cancellationToken);
34+
35+
internal static async Task<ImmutableArray<DiagnosticData>> GetTaskListItemsAsync(Document document, IGlobalOptionService globalOptions, CancellationToken cancellationToken)
3436
{
35-
var service = this.Document.GetLanguageService<ITaskListService>();
37+
var service = document.GetLanguageService<ITaskListService>();
3638
if (service == null)
3739
return [];
3840

39-
var options = _globalOptions.GetTaskListOptions();
41+
var options = globalOptions.GetTaskListOptions();
4042
var descriptors = GetAndCacheDescriptors(options.Descriptors);
4143

42-
var items = await service.GetTaskListItemsAsync(this.Document, descriptors, cancellationToken).ConfigureAwait(false);
44+
var items = await service.GetTaskListItemsAsync(document, descriptors, cancellationToken).ConfigureAwait(false);
4345
if (items.Length == 0)
4446
return [];
4547

@@ -53,9 +55,9 @@ public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
5355
warningLevel: 0,
5456
customTags: s_todoCommentCustomTags,
5557
properties: GetProperties(i.Priority),
56-
projectId: this.Document.Project.Id,
57-
language: this.Document.Project.Language,
58-
location: new DiagnosticDataLocation(i.Span, this.Document.Id, mappedFileSpan: i.MappedSpan)));
58+
projectId: document.Project.Id,
59+
language: document.Project.Language,
60+
location: new DiagnosticDataLocation(i.Span, document.Id, mappedFileSpan: i.MappedSpan)));
5961
}
6062

6163
private static ImmutableDictionary<string, string?> GetProperties(TaskListItemPriority priority)

src/Tools/ExternalAccess/Razor/Features/Cohost/Handlers/Diagnostics.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Diagnostics;
99
using Microsoft.CodeAnalysis.LanguageServer;
10+
using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics;
1011
using Microsoft.CodeAnalysis.Options;
1112
using Microsoft.CodeAnalysis.PooledObjects;
1213
using LSP = Roslyn.LanguageServer.Protocol;
@@ -24,6 +25,21 @@ internal static class Diagnostics
2425
var diagnostics = await diagnosticAnalyzerService.GetDiagnosticsForSpanAsync(
2526
document, range: null, DiagnosticKind.All, cancellationToken).ConfigureAwait(false);
2627

28+
return GetLspDiagnostics(document, supportsVisualStudioExtensions, globalOptionsService, diagnostics);
29+
}
30+
31+
public static async Task<ImmutableArray<LSP.Diagnostic>> GetTaskListAsync(Document document, bool supportsVisualStudioExtensions, CancellationToken cancellationToken)
32+
{
33+
var solutionServices = document.Project.Solution.Services;
34+
var globalOptionsService = solutionServices.ExportProvider.GetService<IGlobalOptionService>();
35+
36+
var items = await TaskListDiagnosticSource.GetTaskListItemsAsync(document, globalOptionsService, cancellationToken).ConfigureAwait(false);
37+
38+
return GetLspDiagnostics(document, supportsVisualStudioExtensions, globalOptionsService, items);
39+
}
40+
41+
private static ImmutableArray<LSP.Diagnostic> GetLspDiagnostics(Document document, bool supportsVisualStudioExtensions, IGlobalOptionService globalOptionsService, ImmutableArray<DiagnosticData> diagnostics)
42+
{
2743
var project = document.Project;
2844
// Potential duplicate is only set for workspace diagnostics
2945
const bool PotentialDuplicate = false;

0 commit comments

Comments
 (0)