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,9 +15,8 @@
using Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryImports;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.UnitTests;
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 @@ -280,6 +279,10 @@ 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 @@ -294,21 +297,23 @@ class Test
</Project>
</Workspace>";

using var workspace = TestWorkspace.Create(workspaceXml);
using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition);
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(1, spans.Count());
Assert.Equal(2, 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 @@ -325,14 +330,14 @@ class Test
</Project>
</Workspace>";

using var workspace = TestWorkspace.Create(workspaceXml);
using var workspace = TestWorkspace.Create(workspaceXml, composition: s_mockComposition);
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 @@ -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 @@ -41,13 +41,14 @@ 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, globalOptions, visibilityTracker, listenerProvider)
: base(threadingContext, diagnosticService, analyzerService, globalOptions, visibilityTracker, listenerProvider)
{
_editorFormatMap = editorFormatMapService.GetEditorFormatMap("text");
_classificationFormatMapService = classificationFormatMapService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,28 @@ internal abstract class AbstractDiagnosticsAdornmentTaggerProvider<TTag> :
protected AbstractDiagnosticsAdornmentTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
IGlobalOptionService globalOptions,
ITextBufferVisibilityTracker? visibilityTracker,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext, diagnosticService, globalOptions, visibilityTracker, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
: base(threadingContext, diagnosticService, analyzerService, globalOptions, visibilityTracker, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
{
}

protected internal sealed override bool IsEnabled => true;

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

// Live update squiggles have to be at least 1 character long.
var minimumLength = isLiveUpdate ? 1 : 0;
var adjustedSpan = AdjustSnapshotSpan(span, minimumLength);
// 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);
if (adjustedSpan.Length == 0)
{
return null;
}

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

protected virtual SnapshotSpan AdjustSnapshotSpan(SnapshotSpan span, int minimumLength)
=> AdjustSnapshotSpan(span, minimumLength, int.MaxValue);
// 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 static SnapshotSpan AdjustSnapshotSpan(SnapshotSpan span, int minimumLength, int maximumLength)
{
Expand Down
Loading