@@ -113,9 +113,13 @@ private async Task HandleNonSelectionAsync(
113113 GetExistingMemberInfo (
114114 containingType , out var hasEquals , out var hasGetHashCode ) ;
115115
116+ var globalOptions = document . Project . Solution . Services . GetService < ILegacyGlobalOptionsWorkspaceService > ( ) ;
117+ if ( globalOptions == null )
118+ return ;
119+
116120 var actions = await CreateActionsAsync (
117121 document , typeDeclaration , containingType , viableMembers , fallbackOptions ,
118- hasEquals , hasGetHashCode , withDialog : true , cancellationToken ) . ConfigureAwait ( false ) ;
122+ hasEquals , hasGetHashCode , withDialog : true , globalOptions , cancellationToken ) . ConfigureAwait ( false ) ;
119123
120124 context . RegisterRefactorings ( actions , textSpan ) ;
121125 }
@@ -190,7 +194,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateEqualsAndGetHashCodeFromMe
190194
191195 return await CreateActionsAsync (
192196 document , typeDeclaration , info . ContainingType , info . SelectedMembers , fallbackOptions ,
193- hasEquals , hasGetHashCode , withDialog : false , cancellationToken ) . ConfigureAwait ( false ) ;
197+ hasEquals , hasGetHashCode , withDialog : false , globalOptions : null , cancellationToken ) . ConfigureAwait ( false ) ;
194198 }
195199 }
196200
@@ -201,7 +205,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateEqualsAndGetHashCodeFromMe
201205 private async Task < ImmutableArray < CodeAction > > CreateActionsAsync (
202206 Document document , SyntaxNode typeDeclaration , INamedTypeSymbol containingType , ImmutableArray < ISymbol > selectedMembers ,
203207 CleanCodeGenerationOptionsProvider fallbackOptions ,
204- bool hasEquals , bool hasGetHashCode , bool withDialog , CancellationToken cancellationToken )
208+ bool hasEquals , bool hasGetHashCode , bool withDialog , ILegacyGlobalOptionsWorkspaceService ? globalOptions , CancellationToken cancellationToken )
205209 {
206210 using var _ = ArrayBuilder < Task < CodeAction > > . GetInstance ( out var tasks ) ;
207211
@@ -215,42 +219,50 @@ private async Task<ImmutableArray<CodeAction>> CreateActionsAsync(
215219 // the user would need to bother just generating that member without also
216220 // generating 'Equals' as well.
217221 tasks . Add ( CreateCodeActionAsync (
218- document , typeDeclaration , containingType , selectedMembers , fallbackOptions ,
222+ document , typeDeclaration , containingType , selectedMembers , fallbackOptions , globalOptions ,
219223 generateEquals : true , generateGetHashCode : false , withDialog , cancellationToken ) ) ;
220224 tasks . Add ( CreateCodeActionAsync (
221- document , typeDeclaration , containingType , selectedMembers , fallbackOptions ,
225+ document , typeDeclaration , containingType , selectedMembers , fallbackOptions , globalOptions ,
222226 generateEquals : true , generateGetHashCode : true , withDialog , cancellationToken ) ) ;
223227 }
224228 else if ( ! hasEquals )
225229 {
226230 tasks . Add ( CreateCodeActionAsync (
227- document , typeDeclaration , containingType , selectedMembers , fallbackOptions ,
231+ document , typeDeclaration , containingType , selectedMembers , fallbackOptions , globalOptions ,
228232 generateEquals : true , generateGetHashCode : false , withDialog , cancellationToken ) ) ;
229233 }
230234 else if ( ! hasGetHashCode )
231235 {
232236 tasks . Add ( CreateCodeActionAsync (
233- document , typeDeclaration , containingType , selectedMembers , fallbackOptions ,
237+ document , typeDeclaration , containingType , selectedMembers , fallbackOptions , globalOptions ,
234238 generateEquals : false , generateGetHashCode : true , withDialog , cancellationToken ) ) ;
235239 }
236240
237241 var codeActions = await Task . WhenAll ( tasks ) . ConfigureAwait ( false ) ;
238242 return codeActions . ToImmutableArray ( ) ;
243+
239244 }
240245
241246 private Task < CodeAction > CreateCodeActionAsync (
242247 Document document , SyntaxNode typeDeclaration , INamedTypeSymbol containingType , ImmutableArray < ISymbol > members ,
243- CleanCodeGenerationOptionsProvider fallbackOptions ,
248+ CleanCodeGenerationOptionsProvider fallbackOptions , ILegacyGlobalOptionsWorkspaceService ? globalOptions ,
244249 bool generateEquals , bool generateGetHashCode , bool withDialog , CancellationToken cancellationToken )
245250 {
246- return withDialog
247- ? CreateCodeActionWithDialogAsync ( document , typeDeclaration , containingType , members , fallbackOptions , generateEquals , generateGetHashCode , cancellationToken )
248- : CreateCodeActionWithoutDialogAsync ( document , typeDeclaration , containingType , members , fallbackOptions , generateEquals , generateGetHashCode , cancellationToken ) ;
251+ if ( withDialog )
252+ {
253+ // We can't create dialog code action if globalOptions is null
254+ Contract . ThrowIfNull ( globalOptions ) ;
255+ return CreateCodeActionWithDialogAsync ( document , typeDeclaration , containingType , members , fallbackOptions , globalOptions , generateEquals , generateGetHashCode , cancellationToken ) ;
256+ }
257+ else
258+ {
259+ return CreateCodeActionWithoutDialogAsync ( document , typeDeclaration , containingType , members , fallbackOptions , generateEquals , generateGetHashCode , cancellationToken ) ;
260+ }
249261 }
250262
251263 private async Task < CodeAction > CreateCodeActionWithDialogAsync (
252264 Document document , SyntaxNode typeDeclaration , INamedTypeSymbol containingType , ImmutableArray < ISymbol > members ,
253- CleanCodeGenerationOptionsProvider fallbackOptions ,
265+ CleanCodeGenerationOptionsProvider fallbackOptions , ILegacyGlobalOptionsWorkspaceService globalOptions ,
254266 bool generateEquals , bool generateGetHashCode , CancellationToken cancellationToken )
255267 {
256268 var semanticModel = await document . GetRequiredSemanticModelAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
@@ -259,7 +271,6 @@ private async Task<CodeAction> CreateCodeActionWithDialogAsync(
259271
260272 if ( CanImplementIEquatable ( semanticModel , containingType , out var equatableTypeOpt ) )
261273 {
262- var globalOptions = document . Project . Solution . Services . GetRequiredService < ILegacyGlobalOptionsWorkspaceService > ( ) ;
263274 var value = globalOptions . GetGenerateEqualsAndGetHashCodeFromMembersImplementIEquatable ( document . Project . Language ) ;
264275
265276 var displayName = equatableTypeOpt . ToDisplayString ( new SymbolDisplayFormat (
@@ -274,7 +285,6 @@ private async Task<CodeAction> CreateCodeActionWithDialogAsync(
274285
275286 if ( ! HasOperators ( containingType ) )
276287 {
277- var globalOptions = document . Project . Solution . Services . GetRequiredService < ILegacyGlobalOptionsWorkspaceService > ( ) ;
278288 var value = globalOptions . GetGenerateEqualsAndGetHashCodeFromMembersGenerateOperators ( document . Project . Language ) ;
279289
280290 pickMembersOptions . Add ( new PickMembersOption (
0 commit comments