Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove notification on diagnostic updates in inline-diagnostics #72562

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Preview;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.ErrorReporting;
Expand Down Expand Up @@ -38,14 +39,12 @@ private sealed class SingleDiagnosticKindPullTaggerProvider(
AbstractDiagnosticsTaggerProvider<TTag> callback,
DiagnosticKind diagnosticKind,
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, the IDiagnosticAnalyzerService is where we actually get the diagnostics from. the IDiagnosticService is the legacy service that serves to push out notifications that diagnostics cahnged to registered listeners. We're removing hte latter.

IGlobalOptionService globalOptions,
ITextBufferVisibilityTracker? visibilityTracker,
IAsynchronousOperationListener listener) : AsynchronousTaggerProvider<TTag>(threadingContext, globalOptions, visibilityTracker, listener)
{
private readonly DiagnosticKind _diagnosticKind = diagnosticKind;
private readonly IDiagnosticService _diagnosticService = diagnosticService;
private readonly IDiagnosticAnalyzerService _analyzerService = analyzerService;

// The following three fields are used to help calculate diagnostic performance for syntax errors upon file open.
Expand Down Expand Up @@ -80,7 +79,17 @@ protected sealed override bool TagEquals(TTag tag1, TTag tag2)
=> _callback.TagEquals(tag1, tag2);

protected sealed override ITaggerEventSource CreateEventSource(ITextView? textView, ITextBuffer subjectBuffer)
=> CreateEventSourceWorker(subjectBuffer, _diagnosticService);
{
// OnTextChanged is added for diagnostics in source generated files: it's possible that the analyzer driver
// executed on content which was produced by a source generator but is not yet reflected in an open text
// buffer for that generated file. In this case, we need to update the tags after the buffer updates (which
// triggers a text changed event) to ensure diagnostics are positioned correctly.
return TaggerEventSources.Compose(
TaggerEventSources.OnDocumentActiveContextChanged(subjectBuffer),
TaggerEventSources.OnWorkspaceRegistrationChanged(subjectBuffer),
TaggerEventSources.OnWorkspaceChanged(subjectBuffer, this.AsyncListener),
TaggerEventSources.OnTextChanged(subjectBuffer));
}

protected sealed override Task ProduceTagsAsync(
TaggerContext<TTag> context, DocumentSnapshotSpan spanToTag, int? caretPosition, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal abstract partial class AbstractDiagnosticsTaggerProvider<TTag> : ITagge

public AbstractDiagnosticsTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
IGlobalOptionService globalOptions,
ITextBufferVisibilityTracker? visibilityTracker,
Expand All @@ -54,7 +53,7 @@ public AbstractDiagnosticsTaggerProvider(
return;

SingleDiagnosticKindPullTaggerProvider CreateDiagnosticsTaggerProvider(DiagnosticKind diagnosticKind)
=> new(this, diagnosticKind, threadingContext, diagnosticService, analyzerService, globalOptions, visibilityTracker, listener);
=> new(this, diagnosticKind, threadingContext, analyzerService, globalOptions, visibilityTracker, listener);
}

// Functionality for subclasses to control how this diagnostic tagging operates. All the individual
Expand Down Expand Up @@ -99,19 +98,6 @@ protected virtual ImmutableArray<DiagnosticDataLocation> GetLocationsToTag(Diagn
return genericTagger;
}

private static ITaggerEventSource CreateEventSourceWorker(ITextBuffer subjectBuffer, IDiagnosticService diagnosticService)
{
// OnTextChanged is added for diagnostics in source generated files: it's possible that the analyzer driver
// executed on content which was produced by a source generator but is not yet reflected in an open text
// buffer for that generated file. In this case, we need to update the tags after the buffer updates (which
// triggers a text changed event) to ensure diagnostics are positioned correctly.
return TaggerEventSources.Compose(
TaggerEventSources.OnDocumentActiveContextChanged(subjectBuffer),
TaggerEventSources.OnWorkspaceRegistrationChanged(subjectBuffer),
TaggerEventSources.OnDiagnosticsChanged(subjectBuffer, diagnosticService),
TaggerEventSources.OnTextChanged(subjectBuffer));
}

protected ITagSpan<TTag>? CreateTagSpan(Workspace workspace, SnapshotSpan span, DiagnosticData data)
{
var errorTag = CreateTag(workspace, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace Microsoft.CodeAnalysis.Editor.InlineDiagnostics;
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class InlineDiagnosticsTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
IGlobalOptionService globalOptions,
[Import(AllowDefault = true)] ITextBufferVisibilityTracker? visibilityTracker,
Expand All @@ -37,7 +36,6 @@ internal sealed class InlineDiagnosticsTaggerProvider(
IClassificationTypeRegistryService classificationTypeRegistryService)
: AbstractDiagnosticsTaggerProvider<InlineDiagnosticsTag>(
threadingContext,
diagnosticService,
analyzerService,
globalOptions,
visibilityTracker,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public static ITaggerEventSource OnReadOnlyRegionsChanged(ITextBuffer subjectBuf
public static ITaggerEventSource OnGlobalOptionChanged(IGlobalOptionService globalOptions, IOption2 globalOption)
=> new GlobalOptionChangedEventSource(globalOptions, globalOption);

public static ITaggerEventSource OnDiagnosticsChanged(ITextBuffer subjectBuffer, IDiagnosticService service)
=> new DiagnosticsChangedEventSource(subjectBuffer, service);

public static ITaggerEventSource OnParseOptionChanged(ITextBuffer subjectBuffer)
=> new ParseOptionChangedEventSource(subjectBuffer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public RemoteLanguageServiceWorkspace(
OpenTextBufferProvider openTextBufferProvider,
IVsFolderWorkspaceService vsFolderWorkspaceService,
SVsServiceProvider serviceProvider,
IDiagnosticService diagnosticService,
ITableManagerProvider tableManagerProvider,
IThreadingContext threadingContext)
: base(VisualStudioMefHostServices.Create(exportProvider), WorkspaceKind.CloudEnvironmentClientWorkspace)
Expand Down
Loading