diff --git a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs index eaf1bd6a6..f24886bc9 100644 --- a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs +++ b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs @@ -314,14 +314,13 @@ public void AddOptFromProperties(string input, string output, string cmd) cmdBuilder.AddOptFromProperties(settingsMock.Object); cmdBuilder.GetFullCmd().Should().Be(cmd); - cmdBuilder.HeaderFileLang.Should().Be(""); } [TestMethod] - [DataRow("Default", "cpp")] - [DataRow("CompileAsC", "c")] - [DataRow("CompileAsCpp", "cpp")] - public void HeaderFileLang(string compileAs, string lang) + [DataRow("Default", "")] + [DataRow("CompileAsC", "/TC ")] + [DataRow("CompileAsCpp", "/TP ")] + public void HeaderFileLang(string compileAs, string cmd) { var cmdBuilder = new CmdBuilder(true); var settingsMock = new Mock(); @@ -329,8 +328,7 @@ public void HeaderFileLang(string compileAs, string lang) cmdBuilder.AddOptFromProperties(settingsMock.Object); - cmdBuilder.GetFullCmd().Should().Be(""); - cmdBuilder.HeaderFileLang.Should().Be(lang); + cmdBuilder.GetFullCmd().Should().Be(cmd); } [TestMethod] @@ -391,7 +389,6 @@ public void PCHUse() cmdBuilder.AddOptFromProperties(settingsMock.Object); cmdBuilder.GetFullCmd().Should().Be("/Yc\"C:\\pch.h\" "); - cmdBuilder.HeaderFileLang.Should().Be(""); } [TestMethod] diff --git a/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs b/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs index be9ff0e45..7f3434592 100644 --- a/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs +++ b/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs @@ -139,7 +139,6 @@ public void TryGet_Full_Cmd() // Assert request.Should().NotBeNull(); Assert.AreEqual("\"C:\\path\\cl.exe\" /permissive- /std:c++17 /EHsc /arch:AVX512 /MT /RTCu /Zp8 /TP /DA \"c:\\dummy\\file.cpp\"", request.CDCommand); - Assert.AreEqual("", request.HeaderFileLanguage); Assert.AreEqual("C:\\path\\includeDir1;C:\\path\\includeDir2;C:\\path\\includeDir3;", request.EnvInclude); Assert.AreEqual("c:\\dummy\\file.cpp", request.CDFile); Assert.AreEqual("c:\\foo", request.CDDirectory); @@ -175,7 +174,7 @@ public void TryGet_HeaderFileOptions_ReturnsValidConfig() // Assert request.Should().NotBeNull(); Assert.AreEqual("\"C:\\path\\cl.exe\" /Yu\"pch.h\" /FI\"pch.h\" /EHsc /RTCu \"c:\\dummy\\file.h\"", request.CDCommand); - Assert.AreEqual("cpp", request.HeaderFileLanguage); + Assert.AreEqual("c:\\dummy\\file.h", request.CDFile); // Arrange projectItemConfig.FileConfigProperties["CompileAs"] = "CompileAsC"; @@ -185,8 +184,18 @@ public void TryGet_HeaderFileOptions_ReturnsValidConfig() request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h"); // Assert - Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu \"c:\\dummy\\file.h\"", request.CDCommand); - Assert.AreEqual("c", request.HeaderFileLanguage); + Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TC \"c:\\dummy\\file.h\"", request.CDCommand); + Assert.AreEqual("c:\\dummy\\file.h", request.CDFile); + + // Arrange + projectItemConfig.FileConfigProperties["CompileAs"] = "CompileAsCpp"; + + // Act + request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h"); + + // Assert + Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TP \"c:\\dummy\\file.h\"", request.CDCommand); + Assert.AreEqual("c:\\dummy\\file.h", request.CDFile); } [TestMethod] diff --git a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs index 5774d6170..fda75c0b4 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs @@ -39,7 +39,6 @@ internal class CmdBuilder StringBuilder Cmd { get; set; } = new StringBuilder(); bool IsHeader { get; set; } - public string HeaderFileLang { get; set; } = ""; public CmdBuilder(bool isHeader) { @@ -167,14 +166,7 @@ internal void AddOptFromProperties(IVCRulePropertyStorage properties) AddCmdOpt(ConvertStructMemberAlignment(structMemberAlignment)); var compileAs = properties.GetEvaluatedPropertyValue("CompileAs"); - if (IsHeader) - { - HeaderFileLang = (compileAs == "CompileAsC") ? "c" : "cpp"; - } - else - { - AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs)); - } + AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs)); // Additional options var additionalOptions = properties.GetEvaluatedPropertyValue("AdditionalOptions"); diff --git a/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs b/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs index cdb23dbef..93e11de61 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs @@ -45,6 +45,7 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri // Not supported return null; } + CmdBuilder cmdBuilder = new CmdBuilder(vcFile.ItemType == "ClInclude"); var compilerPath = vcConfig.GetEvaluatedPropertyValue("ClCompilerPath"); @@ -76,7 +77,6 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri CDCommand = cmdBuilder.GetFullCmd(), CDFile = absoluteFilePath, EnvInclude = envINCLUDE, - HeaderFileLanguage = cmdBuilder.HeaderFileLang, }; } @@ -134,7 +134,7 @@ private static IVCRulePropertyStorage GetVcFileSettings(ILogger logger, string a public string CDCommand { get; set; } public string CDFile { get; set; } public string EnvInclude { get; set; } - public string HeaderFileLanguage { get; set; } + #endregion } diff --git a/src/Integration.Vsix/CFamily/VcxProject/IFileConfig.cs b/src/Integration.Vsix/CFamily/VcxProject/IFileConfig.cs index 2f956be6a..874cfe1c3 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/IFileConfig.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/IFileConfig.cs @@ -26,6 +26,5 @@ internal interface IFileConfig string CDCommand { get; } string CDFile { get; } string EnvInclude { get; } - string HeaderFileLanguage { get; } } }