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:
parent
44ac20a4ce
commit
34f78994d1
1 changed files with 20 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue