From 4face5093739daf4675941d8b472ccd921d9c015 Mon Sep 17 00:00:00 2001 From: Georgii Borovinskikh Date: Thu, 23 Nov 2023 15:44:16 +0100 Subject: [PATCH] Convert SuppressedIssueMatcher to IssueMatcher, return SonarQubeIssue instead of boolean --- .../ClientSuppressionSynchronizerTests.cs | 24 +++++-- .../SuppressedIssueMatcherTests.cs | 62 ++++++++++--------- .../ClientSuppressionSynchronizer.cs | 9 +-- .../SuppressedIssueMatcher.cs | 19 +++--- .../Analysis/IssueConsumerFactoryTests.cs | 5 +- .../Analysis/IssueHandlerTests.cs | 40 ++++++++---- .../Analysis/IssueConsumerFactory.cs | 6 +- .../IssueConsumerFactory_IssueHandler.cs | 14 ++--- 8 files changed, 107 insertions(+), 72 deletions(-) rename src/ConnectedMode.UnitTests/{Suppressions => Synchronization}/SuppressedIssueMatcherTests.cs (78%) rename src/ConnectedMode/{Suppressions => Synchronization}/SuppressedIssueMatcher.cs (86%) diff --git a/src/ConnectedMode.UnitTests/Suppressions/ClientSuppressionSynchronizerTests.cs b/src/ConnectedMode.UnitTests/Suppressions/ClientSuppressionSynchronizerTests.cs index 22ae6c1875..653b7827b7 100644 --- a/src/ConnectedMode.UnitTests/Suppressions/ClientSuppressionSynchronizerTests.cs +++ b/src/ConnectedMode.UnitTests/Suppressions/ClientSuppressionSynchronizerTests.cs @@ -21,10 +21,13 @@ using System; using System.Collections.Generic; using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; +using SonarLint.VisualStudio.ConnectedMode.UnitTests.Helpers; using SonarLint.VisualStudio.Core.Suppressions; using SonarLint.VisualStudio.IssueVisualization.Editor.LocationTagging; using SonarLint.VisualStudio.IssueVisualization.Models; using SonarLint.VisualStudio.TestInfrastructure; +using SonarQube.Client.Models; namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Suppressions { @@ -36,7 +39,7 @@ public void MefCtor_CheckIsExported() { MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport(), - MefTestHelpers.CreateExport()); + MefTestHelpers.CreateExport()); } [TestMethod] @@ -184,13 +187,26 @@ private static IIssueLocationStoreAggregator CreateIssueStore(IEnumerable(); + var suppressedIssuesMatcher = new Mock(); foreach (var match in matches) { - suppressedIssuesMatcher.Setup(x => x.SuppressionExists(match)).Returns(true); + suppressedIssuesMatcher + .Setup(x => x.Match(match)) + .Returns(new SonarQubeIssue(default, + default, + default, + default, + default, + default, + true, // suppressed issue + default, + default, + default, + default, + default)); } return suppressedIssuesMatcher.Object; diff --git a/src/ConnectedMode.UnitTests/Suppressions/SuppressedIssueMatcherTests.cs b/src/ConnectedMode.UnitTests/Synchronization/SuppressedIssueMatcherTests.cs similarity index 78% rename from src/ConnectedMode.UnitTests/Suppressions/SuppressedIssueMatcherTests.cs rename to src/ConnectedMode.UnitTests/Synchronization/SuppressedIssueMatcherTests.cs index 0ccd22be87..f250d0eab0 100644 --- a/src/ConnectedMode.UnitTests/Suppressions/SuppressedIssueMatcherTests.cs +++ b/src/ConnectedMode.UnitTests/Synchronization/SuppressedIssueMatcherTests.cs @@ -20,11 +20,12 @@ using System; using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.Core.Suppressions; using SonarLint.VisualStudio.TestInfrastructure; using SonarQube.Client.Models; -namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Suppressions +namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Synchronization { [TestClass] public class SuppressedIssueMatcherTests @@ -42,14 +43,14 @@ public void TestInitialize() [TestMethod] public void MefCtor_CheckIsExported() { - MefTestHelpers.CheckTypeCanBeImported( + MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport()); } [TestMethod] public void MatchExists_NullIssue_Throws() { - Action act = () => testSubject.SuppressionExists(null); + Action act = () => testSubject.Match(null); act.Should().ThrowExactly().And.ParamName.Should().Be("issue"); } @@ -65,10 +66,11 @@ public void MatchExists_NullIssue_Throws() public void MatchExists_LocalNonFileIssue_SingleServerIssue(string serverRuleId, int? serverIssueLine, string serverHash, bool expectedResult) { var issueToMatch = CreateIssueToMatch("CorrectRuleId", 1, "CorrectHash"); - ConfigureServerIssues(CreateServerIssue(serverRuleId, serverIssueLine, serverHash, isSuppressed: true)); + var serverIssue = CreateServerIssue(serverRuleId, serverIssueLine, serverHash); + ConfigureServerIssues(serverIssue); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().Be(expectedResult); + testSubject.Match(issueToMatch).Should().Be(expectedResult ? serverIssue : null); } [DataTestMethod] @@ -81,10 +83,11 @@ public void MatchExists_LocalFileIssue_SingleServerIssue(string serverRuleId, in { // File issues have line number of 0 and an empty hash var issueToMatch = CreateIssueToMatch("CorrectRuleId", null, null); - ConfigureServerIssues(CreateServerIssue(serverRuleId, serverIssueLine, serverHash, expectedResult)); + var serverIssue = CreateServerIssue(serverRuleId, serverIssueLine, serverHash); + ConfigureServerIssues(serverIssue); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().Be(expectedResult); + testSubject.Match(issueToMatch).Should().Be(expectedResult ? serverIssue : null); } [TestMethod] @@ -95,39 +98,41 @@ public void MatchExists_NoServerIssues_ReturnsFalse() ConfigureServerIssues(Array.Empty()); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().BeFalse(); + testSubject.Match(issueToMatch).Should().BeNull(); } [DataTestMethod] - [DataRow("aaa", 222, "aaa hash", true)] - [DataRow("bbb", 333, "bbb hash", true)] - [DataRow("ccc", 444, "ccc hash", true)] - [DataRow("xxx", 111, "xxx hash", false)] - public void MatchExists_MultipleServerIssues(string localRuleId, int localIssueLine, string localHash, bool expectedResult) + [DataRow("aaa", 222, "aaa hash", 0)] + [DataRow("bbb", 333, "bbb hash", 1)] + [DataRow("ccc", 444, "ccc hash", 2)] + [DataRow("xxx", 111, "xxx hash", -1)] + public void MatchExists_MultipleServerIssues(string localRuleId, int localIssueLine, string localHash, int expectedServerIssue) { // Arrange var issueToMatch = CreateIssueToMatch(localRuleId, localIssueLine, localHash); - ConfigureServerIssues( - CreateServerIssue("aaa", 222, "aaa hash", isSuppressed: true), - CreateServerIssue("bbb", 333, "bbb hash", isSuppressed: true), - CreateServerIssue("ccc", 444, "ccc hash", isSuppressed: true)); + var serverIssues = new []{CreateServerIssue("aaa", 222, "aaa hash"), + CreateServerIssue("bbb", 333, "bbb hash"), + CreateServerIssue("ccc", 444, "ccc hash")}; + + ConfigureServerIssues(serverIssues); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().Be(expectedResult); + testSubject.Match(issueToMatch).Should().Be(expectedServerIssue >= 0 ? serverIssues[expectedServerIssue] : null); } [DataTestMethod] - [DataRow("CorrectRuleId", null, null, true, true)] - [DataRow("CorrectRuleId", null, null, false, false)] - public void MatchExists_ResultDependsOnSuppressionState(string serverRuleId, int? serverIssueLine, string serverHash, bool isSuppressed, bool expectedResult) + [DataRow("CorrectRuleId", null, null, true)] + [DataRow("CorrectRuleId", null, null, false)] + public void MatchExists_ResultDependsOnSuppressionState(string serverRuleId, int? serverIssueLine, string serverHash, bool expectedResult) { // File issues have line number of 0 and an empty hash var issueToMatch = CreateIssueToMatch("CorrectRuleId", null, null); - ConfigureServerIssues(CreateServerIssue(serverRuleId, serverIssueLine, serverHash, isSuppressed)); + var serverIssue = CreateServerIssue(serverRuleId, serverIssueLine, serverHash); + ConfigureServerIssues(serverIssue); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().Be(expectedResult); + testSubject.Match(issueToMatch).Should().Be(serverIssue); } [TestMethod] @@ -157,10 +162,11 @@ public void SuppressionExists_CheckFileComparisons(string serverFilePath, string { var issueToMatch = CreateIssueToMatch("111", 0, "hash", filePath: localFilePath); - ConfigureServerIssues(CreateServerIssue("111", 0, "hash", true, filePath: serverFilePath)); + var serverIssue = CreateServerIssue("111", 0, "hash", filePath: serverFilePath); + ConfigureServerIssues(serverIssue); // Act and assert - testSubject.SuppressionExists(issueToMatch).Should().Be(expected); + testSubject.Match(issueToMatch).Should().Be(expected ? serverIssue : null); } private IFilterableIssue CreateIssueToMatch(string ruleId, int? startLine, string lineHash, @@ -173,18 +179,16 @@ private IFilterableIssue CreateIssueToMatch(string ruleId, int? startLine, strin FilePath = filePath }; - private SonarQubeIssue CreateServerIssue(string ruleId, int? startLine, string lineHash, bool isSuppressed, + private SonarQubeIssue CreateServerIssue(string ruleId, int? startLine, string lineHash, string filePath = null) { - var sonarQubeIssue = new SonarQubeIssue(null, filePath, lineHash, null, null, ruleId, false, SonarQubeIssueSeverity.Info, + var sonarQubeIssue = new SonarQubeIssue(null, filePath, lineHash, null, null, ruleId, default, SonarQubeIssueSeverity.Info, DateTimeOffset.MinValue, DateTimeOffset.MinValue, startLine.HasValue ? new IssueTextRange(startLine.Value, 1, 1, 1) : null, flows: null); - sonarQubeIssue.IsResolved = isSuppressed; - return sonarQubeIssue; } diff --git a/src/ConnectedMode/Suppressions/ClientSuppressionSynchronizer.cs b/src/ConnectedMode/Suppressions/ClientSuppressionSynchronizer.cs index 5df75f6995..7fc5d086de 100644 --- a/src/ConnectedMode/Suppressions/ClientSuppressionSynchronizer.cs +++ b/src/ConnectedMode/Suppressions/ClientSuppressionSynchronizer.cs @@ -23,6 +23,7 @@ using SonarLint.VisualStudio.IssueVisualization.Models; using System.Collections.Generic; using System; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.IssueVisualization.Editor.LocationTagging; namespace SonarLint.VisualStudio.ConnectedMode.Suppressions @@ -32,15 +33,15 @@ namespace SonarLint.VisualStudio.ConnectedMode.Suppressions internal class ClientSuppressionSynchronizer : IClientSuppressionSynchronizer { private readonly IIssueLocationStoreAggregator issuesStore; - private readonly ISuppressedIssueMatcher suppressedIssueMatcher; + private readonly IIssueMatcher issueMatcher; public event EventHandler LocalSuppressionsChanged; [ImportingConstructor] - public ClientSuppressionSynchronizer(IIssueLocationStoreAggregator issuesStore, ISuppressedIssueMatcher suppressedIssueMatcher) + public ClientSuppressionSynchronizer(IIssueLocationStoreAggregator issuesStore, IIssueMatcher issueMatcher) { this.issuesStore = issuesStore; - this.suppressedIssueMatcher = suppressedIssueMatcher; + this.issueMatcher = issueMatcher; } public void SynchronizeSuppressedIssues() @@ -54,7 +55,7 @@ public void SynchronizeSuppressedIssues() var issueViz = issue as IAnalysisIssueVisualization; // If the object was matched then it is suppressed on the server - var newIsSuppressedValue = suppressedIssueMatcher.SuppressionExists(issueViz); + var newIsSuppressedValue = issueMatcher.Match(issueViz)?.IsResolved ?? false; if (issueViz.IsSuppressed != newIsSuppressedValue) { diff --git a/src/ConnectedMode/Suppressions/SuppressedIssueMatcher.cs b/src/ConnectedMode/Synchronization/SuppressedIssueMatcher.cs similarity index 86% rename from src/ConnectedMode/Suppressions/SuppressedIssueMatcher.cs rename to src/ConnectedMode/Synchronization/SuppressedIssueMatcher.cs index db520f3593..381aad0d2b 100644 --- a/src/ConnectedMode/Suppressions/SuppressedIssueMatcher.cs +++ b/src/ConnectedMode/Synchronization/SuppressedIssueMatcher.cs @@ -21,19 +21,20 @@ using System; using System.ComponentModel.Composition; using System.Linq; +using SonarLint.VisualStudio.ConnectedMode.Suppressions; using SonarLint.VisualStudio.Core.Helpers; using SonarLint.VisualStudio.Core.Suppressions; using SonarQube.Client.Models; -namespace SonarLint.VisualStudio.ConnectedMode.Suppressions +namespace SonarLint.VisualStudio.ConnectedMode.Synchronization { - public interface ISuppressedIssueMatcher + public interface IIssueMatcher { - bool SuppressionExists(IFilterableIssue issue); - } + SonarQubeIssue Match(IFilterableIssue issue); + } - [Export(typeof(ISuppressedIssueMatcher))] - public class SuppressedIssueMatcher : ISuppressedIssueMatcher + [Export(typeof(IIssueMatcher))] + public class SuppressedIssueMatcher : IIssueMatcher { private readonly IServerIssuesStore serverIssuesStore; @@ -43,7 +44,7 @@ public SuppressedIssueMatcher(IServerIssuesStore serverIssuesStore) this.serverIssuesStore = serverIssuesStore; } - public bool SuppressionExists(IFilterableIssue issue) + public SonarQubeIssue Match(IFilterableIssue issue) { if (issue == null) { @@ -62,9 +63,7 @@ public bool SuppressionExists(IFilterableIssue issue) var serverIssues = serverIssuesStore.Get(); // Try to find an issue with the same ID and either the same line number or some line hash - bool isSuppressed = serverIssues.Any(s => s.IsResolved && IsMatch(issue, s)); - - return isSuppressed; + return serverIssues.FirstOrDefault(s => IsMatch(issue, s)); } private static bool IsMatch(IFilterableIssue issue, SonarQubeIssue serverIssue) diff --git a/src/Integration.Vsix.UnitTests/Analysis/IssueConsumerFactoryTests.cs b/src/Integration.Vsix.UnitTests/Analysis/IssueConsumerFactoryTests.cs index aa6311402d..d9393c5fd7 100644 --- a/src/Integration.Vsix.UnitTests/Analysis/IssueConsumerFactoryTests.cs +++ b/src/Integration.Vsix.UnitTests/Analysis/IssueConsumerFactoryTests.cs @@ -25,6 +25,7 @@ using Moq; using SonarLint.VisualStudio.Core.Analysis; using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.Integration.Vsix; using SonarLint.VisualStudio.Integration.Vsix.Analysis; using SonarLint.VisualStudio.IssueVisualization.Models; @@ -40,7 +41,7 @@ public class IssueConsumerFactoryTests public void MefCtor_CheckIsExported() { MefTestHelpers.CheckTypeCanBeImported( - MefTestHelpers.CreateExport(), + MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport()); } @@ -48,7 +49,7 @@ public void MefCtor_CheckIsExported() [TestMethod] public void Create_InitializedIssueConsumerReturned() { - var testSubject = new IssueConsumerFactory(Mock.Of(), Mock.Of(), Mock.Of()); + var testSubject = new IssueConsumerFactory(Mock.Of(), Mock.Of(), Mock.Of()); IIssuesSnapshot publishedSnaphot = null; var consumer = testSubject.Create(CreateValidTextDocument("file.txt"), "project name", Guid.NewGuid(), x => { publishedSnaphot = x; }); diff --git a/src/Integration.Vsix.UnitTests/Analysis/IssueHandlerTests.cs b/src/Integration.Vsix.UnitTests/Analysis/IssueHandlerTests.cs index 2dce1d89f0..f3ae5a6820 100644 --- a/src/Integration.Vsix.UnitTests/Analysis/IssueHandlerTests.cs +++ b/src/Integration.Vsix.UnitTests/Analysis/IssueHandlerTests.cs @@ -26,13 +26,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.Text; using Moq; -using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.Core.Analysis; using SonarLint.VisualStudio.Integration.Vsix; using SonarLint.VisualStudio.Integration.Vsix.Analysis; using SonarLint.VisualStudio.TestInfrastructure; using SonarLint.VisualStudio.IssueVisualization.Models; using SonarLint.VisualStudio.IssueVisualization.Security.Hotspots; +using SonarQube.Client.Models; using static SonarLint.VisualStudio.Integration.Vsix.Analysis.IssueConsumerFactory; using static SonarLint.VisualStudio.Integration.Vsix.Analysis.IssueConsumerFactory.IssueHandler; @@ -41,6 +42,19 @@ namespace SonarLint.VisualStudio.Integration.UnitTests.Analysis [TestClass] public class IssueHandlerTests { + private static readonly SonarQubeIssue SuppressedSonarQubeIssue = new SonarQubeIssue(default, + default, + default, + default, + default, + default, + true, // suppressed issue + default, + default, + default, + default, + default); + [TestMethod] public void HandleNewIssues_UpdatedSnapshotAndHotspotStoreHaveExpectedValues() { @@ -97,9 +111,9 @@ public void HandleNewIssues_IssuesGetMatchesIsCalled() }; var notificationHandler = new SnapshotChangeHandler(); - var suppressedIssueMatcher = new Mock(); + var issueMatcher = new Mock(); - var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged, suppressedIssueMatcher.Object); + var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged, issueMatcher.Object); // Act testSubject.HandleNewIssues(inputIssues); @@ -108,7 +122,7 @@ public void HandleNewIssues_IssuesGetMatchesIsCalled() foreach (var issue in inputIssues) { - suppressedIssueMatcher.Verify(x => x.SuppressionExists(issue), Times.Once()); + issueMatcher.Verify(x => x.Match(issue), Times.Once()); } notificationHandler.InvocationCount.Should().Be(1); @@ -203,12 +217,12 @@ public void HandleNewIssues_SomeSuppressedIssues_IssuesGetMarkedCorrectly() var issue4 = CreateIssue("xxx4", startLine: 4, endLine: 4); var issues = new[] { issue1, issue2, issue3, issue4 }; - var suppressedIssueMatcher = new Mock(); - suppressedIssueMatcher.Setup(x => x.SuppressionExists(issue1)).Returns(true); - suppressedIssueMatcher.Setup(x => x.SuppressionExists(issue4)).Returns(true); + var suppressedIssueMatcher = new Mock(); + suppressedIssueMatcher.Setup(x => x.Match(issue1)).Returns(SuppressedSonarQubeIssue); + suppressedIssueMatcher.Setup(x => x.Match(issue4)).Returns(SuppressedSonarQubeIssue); var notificationHandler = new SnapshotChangeHandler(); - var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged, suppressedIssueMatcher: suppressedIssueMatcher.Object); + var testSubject = CreateTestSubject(notificationHandler.OnSnapshotChanged, issueMatcher: suppressedIssueMatcher.Object); // Act testSubject.HandleNewIssues(issues); @@ -304,12 +318,12 @@ private static ITextDocument CreateValidTextDocument(string filePath) } private static IssueHandler CreateTestSubject(SnapshotChangedHandler notificationHandler, - ISuppressedIssueMatcher suppressedIssueMatcher = null, + IIssueMatcher issueMatcher = null, TranslateSpans translator = null, ITextDocument textDocument = null, ILocalHotspotsStoreUpdater localHotspotsStoreUpdater = null) => CreateTestSubject(notificationHandler, "any project name", Guid.NewGuid(), - suppressedIssueMatcher, translator, textDocument, localHotspotsStoreUpdater); + issueMatcher, translator, textDocument, localHotspotsStoreUpdater); private static IssueHandler CreateTestSubject(SnapshotChangedHandler notificationHandler, string projectName, @@ -320,12 +334,12 @@ private static IssueHandler CreateTestSubject(SnapshotChangedHandler notificatio private static IssueHandler CreateTestSubject(SnapshotChangedHandler notificationHandler, string projectName, Guid projectGuid, - ISuppressedIssueMatcher suppressedIssueMatcher = null, + IIssueMatcher issueMatcher = null, TranslateSpans translator = null, ITextDocument textDocument = null, ILocalHotspotsStoreUpdater localHotspotsStoreUpdater = null) { - suppressedIssueMatcher ??= Mock.Of(); + issueMatcher ??= Mock.Of(); translator ??= PassthroughSpanTranslator; textDocument ??= CreateValidTextDocument("any"); @@ -333,7 +347,7 @@ private static IssueHandler CreateTestSubject(SnapshotChangedHandler notificatio textDocument, projectName, projectGuid, - suppressedIssueMatcher, + issueMatcher, notificationHandler, localHotspotsStoreUpdater ?? Mock.Of(), // Override the un-testable "TranslateSpans" behaviour diff --git a/src/Integration.Vsix/Analysis/IssueConsumerFactory.cs b/src/Integration.Vsix/Analysis/IssueConsumerFactory.cs index b94caf288f..41814b4dbe 100644 --- a/src/Integration.Vsix/Analysis/IssueConsumerFactory.cs +++ b/src/Integration.Vsix/Analysis/IssueConsumerFactory.cs @@ -21,7 +21,7 @@ using System; using System.ComponentModel.Composition; using Microsoft.VisualStudio.Text; -using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.Core.Analysis; using SonarLint.VisualStudio.IssueVisualization.Models; using SonarLint.VisualStudio.IssueVisualization.Security.Hotspots; @@ -50,12 +50,12 @@ internal interface IIssueConsumerFactory [PartCreationPolicy(CreationPolicy.Shared)] internal partial class IssueConsumerFactory : IIssueConsumerFactory { - private readonly ISuppressedIssueMatcher suppressedIssueMatcher; + private readonly IIssueMatcher suppressedIssueMatcher; private readonly IAnalysisIssueVisualizationConverter converter; private readonly ILocalHotspotsStoreUpdater localHotspotsStore; [ImportingConstructor] - internal IssueConsumerFactory(ISuppressedIssueMatcher suppressedIssueMatcher, IAnalysisIssueVisualizationConverter converter, ILocalHotspotsStoreUpdater localHotspotsStore) + internal IssueConsumerFactory(IIssueMatcher suppressedIssueMatcher, IAnalysisIssueVisualizationConverter converter, ILocalHotspotsStoreUpdater localHotspotsStore) { this.suppressedIssueMatcher = suppressedIssueMatcher; this.converter = converter; diff --git a/src/Integration.Vsix/Analysis/IssueConsumerFactory_IssueHandler.cs b/src/Integration.Vsix/Analysis/IssueConsumerFactory_IssueHandler.cs index b9f47731fe..088fec461a 100644 --- a/src/Integration.Vsix/Analysis/IssueConsumerFactory_IssueHandler.cs +++ b/src/Integration.Vsix/Analysis/IssueConsumerFactory_IssueHandler.cs @@ -22,7 +22,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.Text; -using SonarLint.VisualStudio.ConnectedMode.Suppressions; +using SonarLint.VisualStudio.ConnectedMode.Synchronization; using SonarLint.VisualStudio.Core.Analysis; using SonarLint.VisualStudio.IssueVisualization.Models; using SonarLint.VisualStudio.IssueVisualization.Security.Hotspots; @@ -41,7 +41,7 @@ internal class IssueHandler private readonly ITextDocument textDocument; private readonly string projectName; private readonly Guid projectGuid; - private readonly ISuppressedIssueMatcher suppressedIssueMatcher; + private readonly IIssueMatcher suppressedIssueMatcher; private readonly SnapshotChangedHandler onSnapshotChanged; private readonly ILocalHotspotsStoreUpdater localHotspotsStore; @@ -50,7 +50,7 @@ internal class IssueHandler public IssueHandler(ITextDocument textDocument, string projectName, Guid projectGuid, - ISuppressedIssueMatcher suppressedIssueMatcher, + IIssueMatcher suppressedIssueMatcher, SnapshotChangedHandler onSnapshotChanged, ILocalHotspotsStoreUpdater localHotspotsStore) : this (textDocument, projectName, projectGuid, suppressedIssueMatcher, onSnapshotChanged, localHotspotsStore, DoTranslateSpans) @@ -60,7 +60,7 @@ public IssueHandler(ITextDocument textDocument, internal /* for testing */ IssueHandler(ITextDocument textDocument, string projectName, Guid projectGuid, - ISuppressedIssueMatcher suppressedIssueMatcher, + IIssueMatcher suppressedIssueMatcher, SnapshotChangedHandler onSnapshotChanged, ILocalHotspotsStoreUpdater localHotspotsStore, TranslateSpans translateSpans) @@ -77,7 +77,7 @@ public IssueHandler(ITextDocument textDocument, internal /* for testing */ void HandleNewIssues(IEnumerable issues) { - MarkSuppressedIssues(issues); + MatchServerIssues(issues); // The text buffer might have changed since the analysis was triggered, so translate // all issues to the current snapshot. @@ -99,11 +99,11 @@ public IssueHandler(ITextDocument textDocument, onSnapshotChanged(newSnapshot); } - private void MarkSuppressedIssues(IEnumerable issues) + private void MatchServerIssues(IEnumerable issues) { foreach (var issue in issues) { - issue.IsSuppressed = suppressedIssueMatcher.SuppressionExists(issue); + issue.IsSuppressed = suppressedIssueMatcher.Match(issue)?.IsResolved ?? false; } }