Skip to content
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 @@ -15,8 +15,9 @@
using Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryImports;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Squiggles;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Options;
Expand Down Expand Up @@ -279,10 +280,6 @@ public async Task TestNoErrorsAfterProjectRemoved()
Assert.True(spans.Count == 0);
}

private static readonly TestComposition s_mockComposition = EditorTestCompositions.EditorFeatures
.AddExcludedPartTypes(typeof(IDiagnosticAnalyzerService))
.AddParts(typeof(MockDiagnosticAnalyzerService));

[WpfFact]
public async Task BuildErrorZeroLengthSpan()
{
Expand All @@ -297,23 +294,21 @@ class Test
</Project>
</Workspace>";

using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition);
using var workspace = TestWorkspace.Create(workspaceXml);
var document = workspace.Documents.First();

var updateArgs = DiagnosticsUpdatedArgs.DiagnosticsCreated(
new object(), workspace, workspace.CurrentSolution, document.Project.Id, document.Id,
ImmutableArray.Create(
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 0)),
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 1))));
new object(), workspace, workspace.CurrentSolution, document.Project.Id, document.Id,
ImmutableArray.Create(
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 0)),
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 1))));

var spans = await TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.GetErrorsFromUpdateSource(workspace, updateArgs);

Assert.Equal(2, spans.Count());
Assert.Equal(1, spans.Count());
var first = spans.First();
var second = spans.Last();

Assert.Equal(1, first.Span.Span.Length);
Assert.Equal(1, second.Span.Span.Length);
}

[WpfFact]
Expand All @@ -330,14 +325,14 @@ class Test
</Project>
</Workspace>";

using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition);
using var workspace = TestWorkspace.Create(workspaceXml);
var document = workspace.Documents.First();

var updateArgs = DiagnosticsUpdatedArgs.DiagnosticsCreated(
new LiveId(), workspace, workspace.CurrentSolution, document.Project.Id, document.Id,
ImmutableArray.Create(
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 0)),
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 1))));
new LiveId(), workspace, workspace.CurrentSolution, document.Project.Id, document.Id,
ImmutableArray.Create(
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 0)),
TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.CreateDiagnosticData(document, new TextSpan(0, 1))));

var spans = await TestDiagnosticTagProducer<DiagnosticsSquiggleTaggerProvider, IErrorTag>.GetErrorsFromUpdateSource(workspace, updateArgs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ internal class InlineDiagnosticsTaggerProvider : AbstractDiagnosticsAdornmentTag
public InlineDiagnosticsTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
IGlobalOptionService globalOptions,
[Import(AllowDefault = true)] ITextBufferVisibilityTracker? visibilityTracker,
IAsynchronousOperationListenerProvider listenerProvider,
IEditorFormatMapService editorFormatMapService,
IClassificationFormatMapService classificationFormatMapService,
IClassificationTypeRegistryService classificationTypeRegistryService)
: base(threadingContext, diagnosticService, analyzerService, globalOptions, visibilityTracker, listenerProvider)
: base(threadingContext, diagnosticService, globalOptions, visibilityTracker, listenerProvider)
{
_editorFormatMap = editorFormatMapService.GetEditorFormatMap("text");
_classificationFormatMapService = classificationFormatMapService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,31 @@ internal abstract class AbstractDiagnosticsAdornmentTaggerProvider<TTag> :
protected AbstractDiagnosticsAdornmentTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
IGlobalOptionService globalOptions,
ITextBufferVisibilityTracker? visibilityTracker,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext, diagnosticService, analyzerService, globalOptions, visibilityTracker, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
: base(threadingContext, diagnosticService, globalOptions, visibilityTracker, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
{
}

protected internal sealed override bool IsEnabled => true;

protected internal sealed override ITagSpan<TTag>? CreateTagSpan(
Workspace workspace, SnapshotSpan span, DiagnosticData data)
Workspace workspace, bool isLiveUpdate, SnapshotSpan span, DiagnosticData data)
{
var errorTag = CreateTag(workspace, data);
if (errorTag == null)
{
return null;
}

// Ensure the diagnostic has at least length 1. Tags must have a non-empty length in order to actually show
// up in the editor.
var adjustedSpan = AdjustSnapshotSpan(span);
// Live update squiggles have to be at least 1 character long.
var minimumLength = isLiveUpdate ? 1 : 0;
var adjustedSpan = AdjustSnapshotSpan(span, minimumLength);
if (adjustedSpan.Length == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: this restored logic means that push diags that have 0 length are filtered out. this is reflected in some test changes in this PR.

{
return null;
}

return new TagSpan<TTag>(adjustedSpan, errorTag);
}
Expand Down Expand Up @@ -75,9 +78,8 @@ protected static object CreateToolTipContent(Workspace workspace, DiagnosticData
new ClassifiedTextRun(ClassificationTypeNames.Text, diagnostic.Message)));
}

// By default, tags must have at least length '1' so that they can be visible in the UI layer.
protected virtual SnapshotSpan AdjustSnapshotSpan(SnapshotSpan span)
=> AdjustSnapshotSpan(span, minimumLength: 1, maximumLength: int.MaxValue);
protected virtual SnapshotSpan AdjustSnapshotSpan(SnapshotSpan span, int minimumLength)
=> AdjustSnapshotSpan(span, minimumLength, int.MaxValue);

protected static SnapshotSpan AdjustSnapshotSpan(SnapshotSpan span, int minimumLength, int maximumLength)
{
Expand Down
Loading