Skip to content

Commit

Permalink
Fixup OmniSharp fallback AnalyzerConfigOption updater (#76542)
Browse files Browse the repository at this point in the history
Applies fixups for feedback left on
#75312
  • Loading branch information
JoeRobich authored Dec 20, 2024
2 parents 94fdfbc + e9cb10f commit 98ea496
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,34 @@ internal static bool UpdateOptions(Workspace workspace, OmniSharpEditorConfigOpt

// add o# option values:
var lineFormattingOptions = editorConfigOptions.LineFormattingOptions;
AddOption(FormattingOptions2.UseTabs, lineFormattingOptions.UseTabs, builder);
AddOption(FormattingOptions2.TabSize, lineFormattingOptions.TabSize, builder);
AddOption(FormattingOptions2.IndentationSize, lineFormattingOptions.IndentationSize, builder);
AddOption(FormattingOptions2.NewLine, lineFormattingOptions.NewLine, builder);
AddOption(FormattingOptions2.UseTabs, lineFormattingOptions.UseTabs);
AddOption(FormattingOptions2.TabSize, lineFormattingOptions.TabSize);
AddOption(FormattingOptions2.IndentationSize, lineFormattingOptions.IndentationSize);
AddOption(FormattingOptions2.NewLine, lineFormattingOptions.NewLine);

var implementTypeOptions = editorConfigOptions.ImplementTypeOptions;
AddOption(ImplementTypeOptionsStorage.InsertionBehavior, (ImplementTypeInsertionBehavior)implementTypeOptions.InsertionBehavior, builder);
AddOption(ImplementTypeOptionsStorage.PropertyGenerationBehavior, (ImplementTypePropertyGenerationBehavior)implementTypeOptions.PropertyGenerationBehavior, builder);
AddOption(ImplementTypeOptionsStorage.InsertionBehavior, (ImplementTypeInsertionBehavior)implementTypeOptions.InsertionBehavior);
AddOption(ImplementTypeOptionsStorage.PropertyGenerationBehavior, (ImplementTypePropertyGenerationBehavior)implementTypeOptions.PropertyGenerationBehavior);

var newFallbackOptions = oldFallbackOptions.SetItem(
LanguageNames.CSharp,
StructuredAnalyzerConfigOptions.Create(new DictionaryAnalyzerConfigOptions(builder.ToImmutable())));

var newSolution = oldSolution.WithFallbackAnalyzerOptions(newFallbackOptions);
return workspace.TryApplyChanges(newSolution);

void AddOption<T>(
PerLanguageOption2<T> option,
T value)
{
var configName = option.Definition.ConfigName;
var configValue = option.Definition.Serializer.Serialize(value);
builder[configName] = configValue;
}
}
catch (Exception e) when (FatalError.ReportAndPropagate(e, ErrorSeverity.Diagnostic))
{
throw ExceptionUtilities.Unreachable();
}

static void AddOption<T>(
PerLanguageOption2<T> option,
T value,
ImmutableDictionary<string, string>.Builder builder)
{
var configName = option.Definition.ConfigName;
var configValue = option.Definition.Serializer.Serialize(value);
builder.Add(configName, configValue);
}
}
}

0 comments on commit 98ea496

Please sign in to comment.