From 89f69c2f75b7a56c6da415ac86fbbf6752f86f2b Mon Sep 17 00:00:00 2001
From: Georgii Borovinskikh
<117642191+georgii-borovinskikh-sonarsource@users.noreply.github.com>
Date: Wed, 8 Jan 2025 10:17:40 +0100
Subject: [PATCH] SLVS-1620 Remove unused AbsoluteFilePathLocator &
IFolderWorkspaceMonitor (#5937)
---
src/Core/IFolderWorkspaceMonitor.cs | 39 ----
.../Helpers/AbsoluteFilePathLocatorTests.cs | 185 ------------------
.../MefServices/ActiveSolutionTrackerTests.cs | 19 +-
.../Helpers/AbsoluteFilePathLocator.cs | 65 ------
.../MefServices/ActiveSolutionTracker.cs | 12 +-
5 files changed, 2 insertions(+), 318 deletions(-)
delete mode 100644 src/Core/IFolderWorkspaceMonitor.cs
delete mode 100644 src/Integration.UnitTests/Helpers/AbsoluteFilePathLocatorTests.cs
delete mode 100644 src/Integration/Helpers/AbsoluteFilePathLocator.cs
diff --git a/src/Core/IFolderWorkspaceMonitor.cs b/src/Core/IFolderWorkspaceMonitor.cs
deleted file mode 100644
index ce5a2f8a9..000000000
--- a/src/Core/IFolderWorkspaceMonitor.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SonarLint for Visual Studio
- * Copyright (C) 2016-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-
-using System;
-
-namespace SonarLint.VisualStudio.Core
-{
- public interface IFolderWorkspaceMonitor
- {
- ///
- /// The event is raised whenever a folder workspace is initialized by VS to have an underlying VsHierarchy.
- ///
- ///
- /// When a folder is opened, before any file is actually opened, VS does not structure a proper VsHierarchy and DTE.
- /// Only when a file is actually opened that VS initializes it to be "Miscellaneous Files" project.
- /// We need this event since certain parts of our code, i.e. ,
- /// rely on VsHierarchy being initialized by the time they're called.
- ///
- event EventHandler FolderWorkspaceInitialized;
- }
-}
diff --git a/src/Integration.UnitTests/Helpers/AbsoluteFilePathLocatorTests.cs b/src/Integration.UnitTests/Helpers/AbsoluteFilePathLocatorTests.cs
deleted file mode 100644
index 5731f15f4..000000000
--- a/src/Integration.UnitTests/Helpers/AbsoluteFilePathLocatorTests.cs
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * SonarLint for Visual Studio
- * Copyright (C) 2016-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using System;
-using FluentAssertions;
-using Microsoft.VisualStudio;
-using Microsoft.VisualStudio.Shell.Interop;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using SonarLint.VisualStudio.Core;
-using SonarLint.VisualStudio.Infrastructure.VS;
-using SonarLint.VisualStudio.Integration.Helpers;
-using SonarLint.VisualStudio.TestInfrastructure;
-
-namespace SonarLint.VisualStudio.Integration.UnitTests.Helpers
-{
- [TestClass]
- public class AbsoluteFilePathLocatorTests
- {
- [TestMethod]
- public void MefCtor_CheckIsExported()
- => MefTestHelpers.CheckTypeCanBeImported(
- MefTestHelpers.CreateExport());
-
- [TestMethod]
- public void MefCtor_CheckIsSingleton()
- => MefTestHelpers.CheckIsSingletonMefComponent();
-
- [TestMethod]
- public void MefCtor_DoesNotCallAnyServices()
- {
- var serviceOp = new Mock();
-
- _ = CreateTestSubject(serviceOp.Object);
-
- // The MEF constructor should be free-threaded, which it will be if
- // it doesn't make any external calls.
- serviceOp.Invocations.Should().BeEmpty();
- }
-
- [TestMethod]
- public void Locate_RelativePathIsNull_ArgumentNullException()
- {
- var vsUiShell = new Mock();
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- Action act = () => testSubject.Locate(null);
-
- act.Should().ThrowExactly().And.ParamName.Should().Be("relativeFilePath");
- vsUiShell.Invocations.Count.Should().Be(0);
- }
-
- [TestMethod]
- public void Locate_BadHrResult_Null()
- {
- const string relativePath = "some relative path";
- const string absolutePath = "some absolute path";
- var vsUiShell = SetupVsUiShellOpenDocument(relativePath, VSConstants.E_FAIL, absolutePath);
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- var result = testSubject.Locate(relativePath);
- result.Should().BeNull();
-
- vsUiShell.VerifyAll();
- vsUiShell.VerifyNoOtherCalls();
- }
-
- [TestMethod]
- public void Locate_NoMatches_Null()
- {
- const string relativePath = "some relative path";
-
- var vsUiShell = SetupVsUiShellOpenDocument(relativePath, VSConstants.S_OK, null);
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- var result = testSubject.Locate(relativePath);
- result.Should().BeNull();
-
- vsUiShell.VerifyAll();
- vsUiShell.VerifyNoOtherCalls();
- }
-
- [TestMethod]
- public void Locate_HasMatch_MatchReturned()
- {
- const string path = "some relative path";
- const string absolutePath = "some absolute path";
-
- var vsUiShell = SetupVsUiShellOpenDocument(path, VSConstants.S_OK, absolutePath);
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- var result = testSubject.Locate(path);
- result.Should().Be(absolutePath);
-
- vsUiShell.VerifyAll();
- vsUiShell.VerifyNoOtherCalls();
- }
-
- [TestMethod]
- public void Locate_RelativePathStartsWithSlashes_PathTrimmed()
- {
- const string path = "some relative path";
- const string absolutePath = "some absolute path";
-
- var vsUiShell = SetupVsUiShellOpenDocument(path, VSConstants.S_OK, absolutePath);
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- var result = testSubject.Locate("\\some relative path");
- result.Should().Be(absolutePath);
-
- vsUiShell.VerifyAll();
- vsUiShell.VerifyNoOtherCalls();
- }
-
- [TestMethod]
- public void Locate_RelativePathHasForwardSlashes_PathFixedToBackSlashes()
- {
- const string path = "some\\relative\\path";
- const string absolutePath = "some absolute path";
-
- var vsUiShell = SetupVsUiShellOpenDocument(path, VSConstants.S_OK, absolutePath);
-
- var testSubject = CreateTestSubject(CreateServiceOperation(vsUiShell.Object));
-
- var result = testSubject.Locate("/some/relative/path");
- result.Should().Be(absolutePath);
-
- vsUiShell.VerifyAll();
- vsUiShell.VerifyNoOtherCalls();
- }
-
- private IVsUIServiceOperation CreateServiceOperation(IVsUIShellOpenDocument svcToPassToCallback)
- {
- var serviceOp = new Mock();
-
- // Set up the mock to invoke the operation with the supplied VS service
- serviceOp.Setup(x => x.Execute(It.IsAny>()))
- .Returns>(op => op(svcToPassToCallback));
-
- return serviceOp.Object;
- }
-
- private Mock SetupVsUiShellOpenDocument(string relativePath, int hrResult, string absolutePath)
- {
- var vsUiShell = new Mock();
- vsUiShell
- .Setup(x => x.SearchProjectsForRelativePath(
- (uint)__VSRELPATHSEARCHFLAGS.RPS_UseAllSearchStrategies,
- relativePath,
- It.IsAny()))
- .Callback((uint searchFlag, string path, string[] res) =>
- {
- res[0] = absolutePath;
- })
- .Returns(hrResult);
-
- return vsUiShell;
- }
-
- private static AbsoluteFilePathLocator CreateTestSubject(IVsUIServiceOperation serviceOperation)
- => new AbsoluteFilePathLocator(serviceOperation);
- }
-}
diff --git a/src/Integration.UnitTests/MefServices/ActiveSolutionTrackerTests.cs b/src/Integration.UnitTests/MefServices/ActiveSolutionTrackerTests.cs
index f8006a1fe..feadbbb8d 100644
--- a/src/Integration.UnitTests/MefServices/ActiveSolutionTrackerTests.cs
+++ b/src/Integration.UnitTests/MefServices/ActiveSolutionTrackerTests.cs
@@ -112,28 +112,11 @@ public void ActiveSolutionTracker_RaiseEventOnFolderOpen()
args.Should().BeEquivalentTo(new ActiveSolutionChangedEventArgs(true, "name123"));
}
- [TestMethod]
- [DataRow(true)]
- [DataRow(false)]
- public void FolderWorkspaceInitializedEvent_RaiseEventOnProjectOpenedIfFolderWorkspace(bool isFolderWorkspace)
- {
- // Arrange
- int counter = 0;
- var testSubject = CreateTestSubject(isFolderWorkspace);
- testSubject.FolderWorkspaceInitialized += (o, e) => { counter++; };
-
- // Act
- this.solutionMock.SimulateProjectOpen(null);
-
- // Assert
- counter.Should().Be(isFolderWorkspace ? 1 : 0);
- }
-
private ActiveSolutionTracker CreateTestSubject(bool isFolderWorkspace = false)
{
var folderWorkspaceFolder = Substitute.For();
folderWorkspaceFolder.IsFolderWorkspace().Returns(isFolderWorkspace);
-
+
return new ActiveSolutionTracker(serviceProvider, folderWorkspaceFolder, solutionInfoProvider);
}
}
diff --git a/src/Integration/Helpers/AbsoluteFilePathLocator.cs b/src/Integration/Helpers/AbsoluteFilePathLocator.cs
deleted file mode 100644
index 9b98acee9..000000000
--- a/src/Integration/Helpers/AbsoluteFilePathLocator.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SonarLint for Visual Studio
- * Copyright (C) 2016-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using System;
-using System.ComponentModel.Composition;
-using Microsoft.VisualStudio;
-using Microsoft.VisualStudio.Shell.Interop;
-using SonarLint.VisualStudio.Core;
-using SonarLint.VisualStudio.Infrastructure.VS;
-
-namespace SonarLint.VisualStudio.Integration.Helpers
-{
- [Export(typeof(IAbsoluteFilePathLocator))]
- [PartCreationPolicy(CreationPolicy.Shared)]
- internal class AbsoluteFilePathLocator : IAbsoluteFilePathLocator
- {
- private readonly IVsUIServiceOperation vSServiceOperation;
-
- [ImportingConstructor]
- public AbsoluteFilePathLocator(IVsUIServiceOperation vSServiceOperation)
- => this.vSServiceOperation = vSServiceOperation;
-
- public string Locate(string relativeFilePath)
- {
- if (relativeFilePath == null)
- {
- throw new ArgumentNullException(nameof(relativeFilePath));
- }
-
- relativeFilePath = relativeFilePath.Replace("/", "\\");
- relativeFilePath = relativeFilePath.TrimStart('\\');
-
- var result = vSServiceOperation.Execute(vsUiShellOpenDocument =>
- {
- var absoluteFilePaths = new string[1];
-
- var hr = vsUiShellOpenDocument.SearchProjectsForRelativePath(
- (uint)__VSRELPATHSEARCHFLAGS.RPS_UseAllSearchStrategies,
- relativeFilePath,
- absoluteFilePaths);
-
- return hr == VSConstants.S_OK ? absoluteFilePaths[0] : null;
- });
-
- return result;
- }
- }
-}
diff --git a/src/Integration/MefServices/ActiveSolutionTracker.cs b/src/Integration/MefServices/ActiveSolutionTracker.cs
index 8d8965a0b..6fc0b41cf 100644
--- a/src/Integration/MefServices/ActiveSolutionTracker.cs
+++ b/src/Integration/MefServices/ActiveSolutionTracker.cs
@@ -18,22 +18,18 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-using System;
using System.ComponentModel.Composition;
-using System.Diagnostics;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using SonarLint.VisualStudio.Core;
-using SonarLint.VisualStudio.Infrastructure.VS;
using ErrorHandler = Microsoft.VisualStudio.ErrorHandler;
namespace SonarLint.VisualStudio.Integration
{
[Export(typeof(IActiveSolutionTracker))]
- [Export(typeof(IFolderWorkspaceMonitor))]
[PartCreationPolicy(CreationPolicy.Shared)]
- internal sealed class ActiveSolutionTracker : IActiveSolutionTracker, IFolderWorkspaceMonitor, IVsSolutionEvents, IDisposable, IVsSolutionEvents7
+ internal sealed class ActiveSolutionTracker : IActiveSolutionTracker, IVsSolutionEvents, IDisposable, IVsSolutionEvents7
{
private readonly IFolderWorkspaceService folderWorkspaceService;
private readonly ISolutionInfoProvider solutionInfoProvider;
@@ -48,8 +44,6 @@ internal sealed class ActiveSolutionTracker : IActiveSolutionTracker, IFolderWor
///
public event EventHandler ActiveSolutionChanged;
- public event EventHandler FolderWorkspaceInitialized;
-
[ImportingConstructor]
public ActiveSolutionTracker([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IFolderWorkspaceService folderWorkspaceService, ISolutionInfoProvider solutionInfoProvider)
{
@@ -63,10 +57,6 @@ public ActiveSolutionTracker([Import(typeof(SVsServiceProvider))] IServiceProvid
#region IVsSolutionEvents
int IVsSolutionEvents.OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
{
- if (folderWorkspaceService.IsFolderWorkspace())
- {
- FolderWorkspaceInitialized?.Invoke(this, EventArgs.Empty);
- }
return VSConstants.S_OK;
}