From 4ba41c4775c0e5019fd4c3046f1e17cf283bc78a Mon Sep 17 00:00:00 2001 From: "sonarqube-agent[bot]" <210722872+sonarqube-agent[bot]@users.noreply.github.com> Date: Fri, 5 Jun 2026 05:03:37 +0000 Subject: [PATCH] fix: Address 5 SonarQube issues Fixed issues: - AYZuudo8hCr0QwXGrBL0 for csharpsquid:S2696 rule - AY57ClZgnZulF3WeHfFd for csharpsquid:S127 rule - AXPc3GHv5-fPawW9ViCb for csharpsquid:S927 rule - AXPc3GHv5-fPawW9ViCc for csharpsquid:S927 rule - AXPc3GHv5-fPawW9ViCd for csharpsquid:S927 rule Generated by SonarQube Agent (task: ffd0bd81-e8c8-450a-ad57-5a174b76f3ad) --- .../DocumentEvents/ActiveDocumentTracker.cs | 12 ++++++------ .../Editor/ErrorTagging/ErrorTagTooltipProvider.cs | 10 ++++++++-- .../ViewModels/IssueVisualizationViewModel.cs | 5 +++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Infrastructure.VS/DocumentEvents/ActiveDocumentTracker.cs b/src/Infrastructure.VS/DocumentEvents/ActiveDocumentTracker.cs index 1c6615d2eb..8ec57d90d8 100644 --- a/src/Infrastructure.VS/DocumentEvents/ActiveDocumentTracker.cs +++ b/src/Infrastructure.VS/DocumentEvents/ActiveDocumentTracker.cs @@ -93,15 +93,15 @@ public ActiveDocumentTracker( /// /// To support all the cases, we use SEID_DocumentFrame for uses cases 1-3 and SEID_WindowFrame for use case 4. /// - int IVsSelectionEvents.OnElementValueChanged(uint elementId, object oldValue, object newValue) + int IVsSelectionEvents.OnElementValueChanged(uint elementid, object varValueOld, object varValueNew) { threadHandling.ThrowIfNotOnUIThread(); - if (elementId == (uint)VSConstants.VSSELELEMID.SEID_DocumentFrame) + if (elementid == (uint)VSConstants.VSSELELEMID.SEID_DocumentFrame) { ITextDocument activeTextDoc = null; - if (newValue is IVsWindowFrame newWindowFrame) + if (varValueNew is IVsWindowFrame newWindowFrame) { activeTextDoc = textDocumentProvider.GetFromFrame(newWindowFrame); } @@ -109,10 +109,10 @@ int IVsSelectionEvents.OnElementValueChanged(uint elementId, object oldValue, ob // The "active document" will be null if the last document has just been closed NotifyActiveDocumentChanged(activeTextDoc); } - // if we reached here, we know that oldValue and/or newValue are a tool window, + // if we reached here, we know that varValueOld and/or varValueNew are a tool window, // and we are only interested in the use case of [tool window] -> [doc] - else if (elementId == (uint) VSConstants.VSSELELEMID.SEID_WindowFrame && - newValue is IVsWindowFrame newWindowFrame && IsDocumentFrame(newWindowFrame)) + else if (elementid == (uint) VSConstants.VSSELELEMID.SEID_WindowFrame && + varValueNew is IVsWindowFrame newWindowFrame && IsDocumentFrame(newWindowFrame)) { var activeTextDoc = textDocumentProvider.GetFromFrame(newWindowFrame); NotifyActiveDocumentChanged(activeTextDoc); diff --git a/src/IssueViz/Editor/ErrorTagging/ErrorTagTooltipProvider.cs b/src/IssueViz/Editor/ErrorTagging/ErrorTagTooltipProvider.cs index 71b27a7958..e733f236ab 100644 --- a/src/IssueViz/Editor/ErrorTagging/ErrorTagTooltipProvider.cs +++ b/src/IssueViz/Editor/ErrorTagging/ErrorTagTooltipProvider.cs @@ -20,6 +20,7 @@ using System; using System.ComponentModel.Composition; +using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; @@ -94,12 +95,17 @@ public object Create(IAnalysisIssueBase analysisIssueBase) Foreground = GetVsThemedColor(EnvironmentColors.SystemCaptionTextBrushKey) }; - instanceCount++; - logger.LogVerbose($"[ErrorTagTooltipProvider] tooltip instance count: {instanceCount}"); + var currentCount = IncrementInstanceCount(); + logger.LogVerbose($"[ErrorTagTooltipProvider] tooltip instance count: {currentCount}"); return content; } + private static long IncrementInstanceCount() + { + return Interlocked.Increment(ref instanceCount); + } + private static void ApplyHyperlinkStyle(Hyperlink hyperlink) { // Style the hyperlink to behave like other error tooltips i.e. diff --git a/src/IssueViz/IssueVisualizationControl/ViewModels/IssueVisualizationViewModel.cs b/src/IssueViz/IssueVisualizationControl/ViewModels/IssueVisualizationViewModel.cs index f7e6b66d83..3edbaa3b48 100644 --- a/src/IssueViz/IssueVisualizationControl/ViewModels/IssueVisualizationViewModel.cs +++ b/src/IssueViz/IssueVisualizationControl/ViewModels/IssueVisualizationViewModel.cs @@ -304,7 +304,8 @@ private IReadOnlyList BuildLocationListItems(IAnalysisIssueFl if (flowLocations != null && flowLocations.Any()) { - for (var i = 0; i < flowLocations.Count; i++) + var i = 0; + while (i < flowLocations.Count) { var location = flowLocations[i]; @@ -317,7 +318,7 @@ private IReadOnlyList BuildLocationListItems(IAnalysisIssueFl listItems.AddRange(sequentialLocations.Select(x => (ILocationListItem)new LocationListItem(x))); - i += sequentialLocations.Count - 1; + i += sequentialLocations.Count; } }