@@ -17,47 +17,44 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Options;
1717
1818internal static class OmniSharpSolutionAnalyzerConfigOptionsUpdater
1919{
20- internal static void UpdateOptions ( Workspace workspace , OmniSharpEditorConfigOptions editorConfigOptions )
20+ internal static bool UpdateOptions ( Workspace workspace , OmniSharpEditorConfigOptions editorConfigOptions )
2121 {
2222 try
2323 {
24- workspace . SetCurrentSolution ( UpdateOptions , changeKind : WorkspaceChangeKind . SolutionChanged ) ;
24+ var oldSolution = workspace . CurrentSolution ;
25+ var oldFallbackOptions = oldSolution . FallbackAnalyzerOptions ;
26+ oldFallbackOptions . TryGetValue ( LanguageNames . CSharp , out var csharpFallbackOptions ) ;
2527
26- Solution UpdateOptions ( Solution oldSolution )
28+ var builder = ImmutableDictionary . CreateBuilder < string , string > ( AnalyzerConfigOptions . KeyComparer ) ;
29+ if ( csharpFallbackOptions is not null )
2730 {
28- var oldFallbackOptions = oldSolution . FallbackAnalyzerOptions ;
29- oldFallbackOptions . TryGetValue ( LanguageNames . CSharp , out var csharpFallbackOptions ) ;
30-
31- var builder = ImmutableDictionary . CreateBuilder < string , string > ( AnalyzerConfigOptions . KeyComparer ) ;
32- if ( csharpFallbackOptions is not null )
31+ // copy existing option values:
32+ foreach ( var oldKey in csharpFallbackOptions . Keys )
3333 {
34- // copy existing option values:
35- foreach ( var oldKey in csharpFallbackOptions . Keys )
34+ if ( csharpFallbackOptions . TryGetValue ( oldKey , out var oldValue ) )
3635 {
37- if ( csharpFallbackOptions . TryGetValue ( oldKey , out var oldValue ) )
38- {
39- builder . Add ( oldKey , oldValue ) ;
40- }
36+ builder . Add ( oldKey , oldValue ) ;
4137 }
4238 }
39+ }
4340
44- // add o# option values:
45- var lineFormattingOptions = editorConfigOptions . LineFormattingOptions ;
46- AddOption ( FormattingOptions2 . UseTabs , lineFormattingOptions . UseTabs , builder ) ;
47- AddOption ( FormattingOptions2 . TabSize , lineFormattingOptions . TabSize , builder ) ;
48- AddOption ( FormattingOptions2 . IndentationSize , lineFormattingOptions . IndentationSize , builder ) ;
49- AddOption ( FormattingOptions2 . NewLine , lineFormattingOptions . NewLine , builder ) ;
41+ // add o# option values:
42+ var lineFormattingOptions = editorConfigOptions . LineFormattingOptions ;
43+ AddOption ( FormattingOptions2 . UseTabs , lineFormattingOptions . UseTabs , builder ) ;
44+ AddOption ( FormattingOptions2 . TabSize , lineFormattingOptions . TabSize , builder ) ;
45+ AddOption ( FormattingOptions2 . IndentationSize , lineFormattingOptions . IndentationSize , builder ) ;
46+ AddOption ( FormattingOptions2 . NewLine , lineFormattingOptions . NewLine , builder ) ;
5047
51- var implementTypeOptions = editorConfigOptions . ImplementTypeOptions ;
52- AddOption ( ImplementTypeOptionsStorage . InsertionBehavior , ( ImplementTypeInsertionBehavior ) implementTypeOptions . InsertionBehavior , builder ) ;
53- AddOption ( ImplementTypeOptionsStorage . PropertyGenerationBehavior , ( ImplementTypePropertyGenerationBehavior ) implementTypeOptions . PropertyGenerationBehavior , builder ) ;
48+ var implementTypeOptions = editorConfigOptions . ImplementTypeOptions ;
49+ AddOption ( ImplementTypeOptionsStorage . InsertionBehavior , ( ImplementTypeInsertionBehavior ) implementTypeOptions . InsertionBehavior , builder ) ;
50+ AddOption ( ImplementTypeOptionsStorage . PropertyGenerationBehavior , ( ImplementTypePropertyGenerationBehavior ) implementTypeOptions . PropertyGenerationBehavior , builder ) ;
5451
55- var newFallbackOptions = oldFallbackOptions . SetItem (
56- LanguageNames . CSharp ,
57- StructuredAnalyzerConfigOptions . Create ( new DictionaryAnalyzerConfigOptions ( builder . ToImmutable ( ) ) ) ) ;
52+ var newFallbackOptions = oldFallbackOptions . SetItem (
53+ LanguageNames . CSharp ,
54+ StructuredAnalyzerConfigOptions . Create ( new DictionaryAnalyzerConfigOptions ( builder . ToImmutable ( ) ) ) ) ;
5855
59- return oldSolution . WithFallbackAnalyzerOptions ( newFallbackOptions ) ;
60- }
56+ var newSolution = oldSolution . WithFallbackAnalyzerOptions ( newFallbackOptions ) ;
57+ return workspace . TryApplyChanges ( newSolution ) ;
6158 }
6259 catch ( Exception e ) when ( FatalError . ReportAndPropagate ( e , ErrorSeverity . Diagnostic ) )
6360 {
0 commit comments