Skip to content

Commit

Permalink
SLVS-1665 Make FileConfigProvider mef-exporting (#5860)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 24, 2024
1 parent 25d7350 commit d4bf8ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ namespace SonarLint.VisualStudio.Integration.UnitTests.CFamily.VcxProject
[TestClass]
public class FileConfigProviderTests
{
[TestMethod]
public void MefCtor_CheckIsExported() =>
MefTestHelpers.CheckTypeCanBeImported<FileConfigProvider, IFileConfigProvider>(
MefTestHelpers.CreateExport<ILogger>());

[TestMethod]
public void MefCtor_CheckIsSingleton() => MefTestHelpers.CheckIsSingletonMefComponent<FileConfigProvider>();

[TestMethod]
public void Get_FileIsNotInSolution_ReturnsNull()
{
var projectItemMock = CreateMockProjectItem("c:\\foo\\SingleFileISense\\xxx.vcxproj");

var testSubject = CreateTestSubject();
var result = testSubject.Get(projectItemMock.Object, "c:\\dummy", new CFamilyAnalyzerOptions());

Expand Down Expand Up @@ -132,7 +140,7 @@ public void Get_FailsToRetrieveFileConfig_Pch_ExceptionNotLogged()
public void Get_SuccessfulConfig_ConfigReturned()
{
var projectItemMock = CreateMockProjectItem("c:\\foo\\xxx.vcxproj");

var testSubject = CreateTestSubject();
var result = testSubject.Get(projectItemMock.Object, "c:\\dummy", new CFamilyAnalyzerOptions());

Expand Down
13 changes: 5 additions & 8 deletions src/Integration.Vsix/CFamily/VcxProject/FileConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using System;
using System.ComponentModel.Composition;
using EnvDTE;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.CFamily.Analysis;
Expand All @@ -31,16 +32,12 @@ internal interface IFileConfigProvider
IFileConfig Get(ProjectItem projectItem, string analyzedFilePath, CFamilyAnalyzerOptions analyzerOptions);
}

internal class FileConfigProvider : IFileConfigProvider
[Export(typeof(IFileConfigProvider))]
[PartCreationPolicy(CreationPolicy.Shared)]
[method: ImportingConstructor]
internal class FileConfigProvider(ILogger logger) : IFileConfigProvider
{
private static readonly NoOpLogger noOpLogger = new NoOpLogger();
private readonly ILogger logger;

public FileConfigProvider(ILogger logger)
{
this.logger = logger;
}


public IFileConfig Get(ProjectItem projectItem, string analyzedFilePath, CFamilyAnalyzerOptions analyzerOptions)
{
Expand Down

0 comments on commit d4bf8ee

Please sign in to comment.