diff --git a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs index 425a921a1dd22..9def0f584375c 100644 --- a/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs +++ b/src/Features/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationService.cs @@ -25,5 +25,8 @@ public WorkspaceConfigurationService(IGlobalOptionService globalOptions) public WorkspaceConfigurationOptions Options => _lazyOptions ??= _globalOptions.GetWorkspaceConfigurationOptions(); + + internal void Clear() + => _lazyOptions = null; } } diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpSourceGenerators.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpSourceGenerators.cs index 3f0559f503b35..8d149539517d5 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpSourceGenerators.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpSourceGenerators.cs @@ -80,8 +80,15 @@ public static void Main() if (invokeFromSourceGeneratedFile) { + var workspace = await TestServices.Shell.GetComponentModelServiceAsync(HangMitigatingCancellationToken); + + // clear configuration options already read by initialization above, so that the global option update below is effective: + var configurationService = (WorkspaceConfigurationService)workspace.Services.GetRequiredService(); + configurationService.Clear(); + var globalOptions = await TestServices.Shell.GetComponentModelServiceAsync(HangMitigatingCancellationToken); globalOptions.SetGlobalOption(new OptionKey(WorkspaceConfigurationOptionsStorage.EnableOpeningSourceGeneratedFilesInWorkspace, language: null), true); + await TestServices.Editor.GoToDefinitionAsync(HangMitigatingCancellationToken); Assert.Equal($"{HelloWorldGenerator.GeneratedEnglishClassName}.cs {ServicesVSResources.generated_suffix}", await TestServices.Shell.GetActiveWindowCaptionAsync(HangMitigatingCancellationToken)); } diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/StateResetInProcess.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/StateResetInProcess.cs index 56ddb1e2dc80d..cbd64d0769d98 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/StateResetInProcess.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/StateResetInProcess.cs @@ -16,6 +16,7 @@ using Microsoft.VisualStudio.Extensibility.Testing; using Microsoft.VisualStudio.IntegrationTest.Utilities; using Microsoft.VisualStudio.IntegrationTest.Utilities.Input; +using Microsoft.VisualStudio.LanguageServices; using Microsoft.VisualStudio.LanguageServices.Implementation; using Microsoft.VisualStudio.LanguageServices.Telemetry; using Microsoft.VisualStudio.Shell.Interop; @@ -36,6 +37,11 @@ internal partial class StateResetInProcess public async Task ResetGlobalOptionsAsync(CancellationToken cancellationToken) { + // clear configuration options, so that the workspace configuration global option update below is effective: + var workspace = await TestServices.Shell.GetComponentModelServiceAsync(cancellationToken); + var configurationService = (WorkspaceConfigurationService)workspace.Services.GetRequiredService(); + configurationService.Clear(); + var globalOptions = await GetComponentModelServiceAsync(cancellationToken); ResetOption2(globalOptions, FeatureOnOffOptions.NavigateToDecompiledSources); ResetOption2(globalOptions, WorkspaceConfigurationOptionsStorage.EnableOpeningSourceGeneratedFilesInWorkspace);