Infer the analyzer languageId from compilerName

Simplifies using a different compiler since you only have
to set one value if the the compiler is known to dotnet-compile
This commit is contained in:
Andy Gocke 2016-01-29 21:07:02 -08:00
parent 44ac20a4ce
commit 34f78994d1

View file

@ -26,12 +26,29 @@ namespace Microsoft.DotNet.Tools.Compiler
return compilerName;
}
private static readonly KeyValuePair<string, string>[] s_compilerNameToLanguageId =
{
new KeyValuePair<string, string>("csc", "cs"),
new KeyValuePair<string, string>("vbc", "vb"),
new KeyValuePair<string, string>("fsc", "fs")
};
public static string ResolveLanguageId(ProjectContext context)
{
var languageId = context.ProjectFile.AnalyzerOptions?.LanguageId;
languageId = languageId ?? "cs";
if (languageId == null)
{
var compilerName = ResolveCompilerName(context);
foreach (var kvp in s_compilerNameToLanguageId)
{
if (kvp.Key == compilerName)
{
languageId = kvp.Value;
}
}
}
return languageId;
}