Skip to content

Commit c3f6743

Browse files
committed
Adds diagnostic provider which uses the ITableDataSources directly.
addresses #4
1 parent 388fb47 commit c3f6743

10 files changed

+413
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using FakeItEasy;
4+
using Microsoft.VisualStudio.Shell;
5+
using Microsoft.VisualStudio.Shell.TableControl;
6+
using Microsoft.VisualStudio.Shell.TableManager;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
using Steroids.CodeQuality.Services;
9+
10+
namespace Steroids.CodeQuality.Tests.Services
11+
{
12+
[TestClass]
13+
public class ErrorListDiagnosticProviderTest
14+
{
15+
private readonly IWpfTableControl _tableControl = A.Fake<IWpfTableControl>();
16+
private readonly IErrorList _errorList = A.Fake<IErrorList>();
17+
18+
//[TestMethod]
19+
//public void MethodName_Scenario_Expectation()
20+
//{
21+
// // Arrange
22+
// var sut = CreateSut();
23+
// var entries = A.Fake<EntriesChangedEventArgs>();
24+
// A.CallTo(() => entries.AllEntries).Returns(new List<ITableEntryHandle>
25+
// {
26+
27+
// });
28+
29+
// // Act
30+
// _tableControl.EntriesChanged += Raise.With()
31+
32+
// // Assert
33+
//}
34+
35+
//private static ITableEntryHandle CreateTableEntryFake(string path)
36+
//{
37+
// string documentName;
38+
39+
// var tableEntry = A.Fake<ITableEntryHandle>();
40+
// A.CallTo(() => tableEntry.TryGetValue(StandardTableKeyNames.DocumentName, out documentName)).AssignsOutAndRefParameters(path);
41+
//}
42+
43+
private ErrorListDiagnosticProvider CreateSut()
44+
{
45+
A.CallTo(() => _errorList.TableControl).Returns(_tableControl);
46+
return new ErrorListDiagnosticProvider(_errorList);
47+
}
48+
}
49+
}

Source/Steroids.CodeQuality.Tests/Steroids.CodeQuality.Tests.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
<HintPath>..\packages\Microsoft.VisualStudio.CoreUtility.15.4.27004\lib\net45\Microsoft.VisualStudio.CoreUtility.dll</HintPath>
6262
<Private>True</Private>
6363
</Reference>
64+
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
65+
<HintPath>..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6070\lib\Microsoft.VisualStudio.OLE.Interop.dll</HintPath>
66+
</Reference>
67+
<Reference Include="Microsoft.VisualStudio.Shell.Framework, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
68+
<HintPath>..\packages\Microsoft.VisualStudio.Shell.Framework.15.4.27004\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll</HintPath>
69+
</Reference>
6470
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
6571
<HintPath>..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
6672
</Reference>
@@ -83,6 +89,9 @@
8389
<HintPath>..\packages\Microsoft.VisualStudio.Text.UI.Wpf.15.4.27004\lib\net45\Microsoft.VisualStudio.Text.UI.Wpf.dll</HintPath>
8490
<Private>True</Private>
8591
</Reference>
92+
<Reference Include="Microsoft.VisualStudio.Utilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
93+
<HintPath>..\packages\Microsoft.VisualStudio.Utilities.15.4.27004\lib\net46\Microsoft.VisualStudio.Utilities.dll</HintPath>
94+
</Reference>
8695
<Reference Include="System" />
8796
<Reference Include="System.AppContext, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
8897
<HintPath>..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll</HintPath>
@@ -189,6 +198,7 @@
189198
</Reference>
190199
</ItemGroup>
191200
<ItemGroup>
201+
<Compile Include="Services\ErrorListDiagnosticProviderTest.cs" />
192202
<Compile Include="ViewModels\CodeQualityHintsViewModelTest.cs" />
193203
<Compile Include="Properties\AssemblyInfo.cs" />
194204
</ItemGroup>

Source/Steroids.CodeQuality.Tests/packages.config

+3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
<package id="Microsoft.CodeAnalysis.EditorFeatures.Text" version="2.4.0" targetFramework="net47" />
99
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="2.4.0" targetFramework="net47" />
1010
<package id="Microsoft.VisualStudio.CoreUtility" version="15.4.27004" targetFramework="net47" />
11+
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net47" />
12+
<package id="Microsoft.VisualStudio.Shell.Framework" version="15.4.27004" targetFramework="net47" />
1113
<package id="Microsoft.VisualStudio.Text.Data" version="15.4.27004" targetFramework="net47" />
1214
<package id="Microsoft.VisualStudio.Text.Logic" version="15.4.27004" targetFramework="net47" />
1315
<package id="Microsoft.VisualStudio.Text.UI" version="15.4.27004" targetFramework="net47" />
1416
<package id="Microsoft.VisualStudio.Text.UI.Wpf" version="15.4.27004" targetFramework="net47" />
17+
<package id="Microsoft.VisualStudio.Utilities" version="15.4.27004" targetFramework="net47" />
1518
<package id="MSTest.TestAdapter" version="1.3.0" targetFramework="net47" />
1619
<package id="MSTest.TestFramework" version="1.3.0" targetFramework="net47" />
1720
<package id="Roslynator.Analyzers" version="1.9.0" targetFramework="net47" developmentDependency="true" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.VisualStudio.Shell.Interop;
3+
using Microsoft.VisualStudio.Shell.TableManager;
4+
using Steroids.Contracts;
5+
6+
namespace Steroids.CodeQuality.Extensions
7+
{
8+
/// <summary>
9+
/// Extensions for <see cref="ITableEntry"/> objects.
10+
/// </summary>
11+
public static class ITableEntryExtensions
12+
{
13+
private const string SuppressionState = "suppressionstate";
14+
private const string NotSuppressed = "Active";
15+
16+
/// <summary>
17+
/// Creates a <see cref="DiagnosticInfo"/> from a <see cref="ITableEntriesHandle"/>.
18+
/// </summary>
19+
/// <param name="entry">The <see cref="ITableEntryHandle"/>.</param>
20+
/// <returns>The created <see cref="DiagnosticInfo"/>.</returns>
21+
public static DiagnosticInfo ToDiagnosticInfo(this ITableEntry entry)
22+
{
23+
if (!entry.TryGetValue(StandardTableKeyNames.ErrorSeverity, out __VSERRORCATEGORY errorCategory))
24+
{
25+
errorCategory = __VSERRORCATEGORY.EC_MESSAGE;
26+
}
27+
28+
entry.TryGetValue(StandardTableKeyNames.DocumentName, out string path);
29+
entry.TryGetValue(StandardTableKeyNames.Text, out string text);
30+
entry.TryGetValue(StandardTableKeyNames.FullText, out string fullText);
31+
entry.TryGetValue(StandardTableKeyNames.ErrorCode, out string errorCode);
32+
entry.TryGetValue(StandardTableKeyNames.HelpLink, out string helpLink);
33+
entry.TryGetValue(StandardTableKeyNames.Line, out int line);
34+
entry.TryGetValue(StandardTableKeyNames.Column, out int column);
35+
entry.TryGetValue(SuppressionState, out string suppressionState);
36+
37+
if (string.IsNullOrWhiteSpace(fullText))
38+
{
39+
fullText = text;
40+
}
41+
42+
var severity = DiagnosticSeverity.Hidden;
43+
switch (errorCategory)
44+
{
45+
case __VSERRORCATEGORY.EC_ERROR:
46+
severity = DiagnosticSeverity.Error;
47+
break;
48+
case __VSERRORCATEGORY.EC_WARNING:
49+
severity = DiagnosticSeverity.Warning;
50+
break;
51+
case __VSERRORCATEGORY.EC_MESSAGE:
52+
severity = DiagnosticSeverity.Info;
53+
break;
54+
}
55+
56+
return new DiagnosticInfo
57+
{
58+
Severity = severity,
59+
Path = path,
60+
Message = fullText,
61+
ErrorCode = errorCode,
62+
HelpUriRaw = helpLink,
63+
Line = line,
64+
Column = column,
65+
IsActive = suppressionState == NotSuppressed
66+
};
67+
}
68+
}
69+
}

Source/Steroids.CodeQuality/Services/ErrorListDiagnosticProvider.cs

+8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010

1111
namespace Steroids.CodeQuality.Services
1212
{
13+
/// <summary>
14+
/// Provides <see cref="DiagnosticInfo"/> by crawling the ErrorList UI directly.
15+
/// </summary>
16+
[Obsolete("Unused, because the \"Build Only\" filter in the error list UI filters in a way we can't get around. Use TableManagerDiagnosticsProvider instead.")]
1317
public class ErrorListDiagnosticProvider : IDiagnosticProvider
1418
{
1519
private const string SuppressionState = "suppressionstate";
1620
private const string NotSuppressed = "Active";
1721

22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="ErrorListDiagnosticProvider"/> class.
24+
/// </summary>
25+
/// <param name="errorList">The <see cref="IErrorList"/>.</param>
1826
public ErrorListDiagnosticProvider(IErrorList errorList)
1927
{
2028
if (errorList == null)

0 commit comments

Comments
 (0)