diff --git a/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb b/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb index 8ebc28eb5e830..96808a907ff22 100644 --- a/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb +++ b/src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb @@ -72,6 +72,7 @@ public partial class GeneratedClass : IInterface { } , host:=host, renameTo:="A", sourceGenerator:=New GeneratorThatImplementsInterfaceMethod()) + End Using End Sub diff --git a/src/EditorFeatures/Test2/Rename/RenameEngineResult.vb b/src/EditorFeatures/Test2/Rename/RenameEngineResult.vb index f0aa89b965adf..7cc7b5cb35379 100644 --- a/src/EditorFeatures/Test2/Rename/RenameEngineResult.vb +++ b/src/EditorFeatures/Test2/Rename/RenameEngineResult.vb @@ -6,8 +6,10 @@ Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.CodeActions +Imports Microsoft.CodeAnalysis.CodeCleanup Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Host +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Remote.Testing Imports Microsoft.CodeAnalysis.Rename Imports Microsoft.CodeAnalysis.Rename.ConflictEngine @@ -55,24 +57,18 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename host As RenameTestHost, Optional renameOptions As SymbolRenameOptions = Nothing, Optional expectFailure As Boolean = False, - Optional sourceGenerator As ISourceGenerator = Nothing, - Optional executionPreference As SourceGeneratorExecutionPreference = SourceGeneratorExecutionPreference.Automatic) As RenameEngineResult + Optional sourceGenerator As ISourceGenerator = Nothing) As RenameEngineResult Dim composition = EditorTestCompositions.EditorFeatures.AddParts( GetType(NoCompilationContentTypeLanguageService), GetType(NoCompilationContentTypeDefinitions), - GetType(WorkspaceTestLogger), - GetType(TestWorkspaceConfigurationService)) + GetType(WorkspaceTestLogger)) If host = RenameTestHost.OutOfProcess_SingleCall OrElse host = RenameTestHost.OutOfProcess_SplitCall Then composition = composition.WithTestHostParts(TestHost.OutOfProcess) End If Dim workspace = TestWorkspace.CreateWorkspace(workspaceXml, composition:=composition) - - Dim configService = workspace.ExportProvider.GetExportedValue(Of TestWorkspaceConfigurationService) - configService.Options = New WorkspaceConfigurationOptions(SourceGeneratorExecution:=executionPreference) - workspace.Services.SolutionServices.SetWorkspaceTestOutput(helper) If sourceGenerator IsNot Nothing Then diff --git a/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb b/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb index 19f53caf23725..e6b3540352073 100644 --- a/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb +++ b/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb @@ -10,8 +10,10 @@ Imports Microsoft.CodeAnalysis.Editor.Implementation.RenameTracking Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.UnitTests.RenameTracking Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Shared.TestHooks +Imports Microsoft.CodeAnalysis.Rename Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions Imports Microsoft.VisualStudio.Text @@ -20,10 +22,10 @@ Imports Microsoft.VisualStudio.Text.Tagging Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename Friend Module RenameTestHelpers + Private ReadOnly s_composition As TestComposition = EditorTestCompositions.EditorFeaturesWpf.AddParts( GetType(MockDocumentNavigationServiceFactory), - GetType(MockPreviewDialogService), - GetType(TestWorkspaceConfigurationService)) + GetType(MockPreviewDialogService)) Private Function GetSessionInfo(workspace As EditorTestWorkspace) As (document As Document, textSpan As TextSpan) Dim hostdoc = workspace.DocumentWithCursor diff --git a/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb b/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb index 19ecabcdd2cd3..c86ff38b884bf 100644 --- a/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb +++ b/src/EditorFeatures/Test2/Rename/RenameViewModelTests.vb @@ -6,7 +6,6 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.Implementation.InlineRename Imports Microsoft.CodeAnalysis.Editor.InlineRename Imports Microsoft.CodeAnalysis.Editor.[Shared].Utilities -Imports Microsoft.CodeAnalysis.Host Imports Microsoft.CodeAnalysis.InlineRename Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.[Shared].TestHooks @@ -548,8 +547,8 @@ class D : B Optional renameFile As Boolean = False, Optional resolvableConflictText As String = Nothing, Optional unresolvableConflictText As String = Nothing, - Optional severity As RenameDashboardSeverity = RenameDashboardSeverity.None, - Optional executionPreference As SourceGeneratorExecutionPreference = SourceGeneratorExecutionPreference.Automatic) As Task + Optional severity As RenameDashboardSeverity = RenameDashboardSeverity.None + ) As Tasks.Task Using workspace = CreateWorkspaceWithWaiter(test, host) Dim globalOptions = workspace.GetService(Of IGlobalOptionService)() @@ -558,9 +557,6 @@ class D : B globalOptions.SetGlobalOption(InlineRenameSessionOptionsStorage.RenameInComments, renameInComments) globalOptions.SetGlobalOption(InlineRenameSessionOptionsStorage.RenameFile, renameFile) - Dim configService = workspace.ExportProvider.GetExportedValue(Of TestWorkspaceConfigurationService) - configService.Options = New WorkspaceConfigurationOptions(SourceGeneratorExecution:=executionPreference) - Dim cursorDocument = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue) Dim cursorPosition = cursorDocument.CursorPosition.Value diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs index 3c7925cb46cb2..e348b99f6d13a 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs @@ -9,7 +9,6 @@ using System.Runtime.InteropServices; using System.Text.Json; using Microsoft.CodeAnalysis.Contracts.Telemetry; -using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.LanguageServer; using Microsoft.CodeAnalysis.LanguageServer.BrokeredServices; using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; @@ -17,7 +16,6 @@ using Microsoft.CodeAnalysis.LanguageServer.Logging; using Microsoft.CodeAnalysis.LanguageServer.Services; using Microsoft.CodeAnalysis.LanguageServer.StarredSuggestions; -using Microsoft.CodeAnalysis.Options; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Console; using Roslyn.Utilities; @@ -85,11 +83,6 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation using var exportProvider = await ExportProviderBuilder.CreateExportProviderAsync(extensionManager, assemblyLoader, serverConfiguration.DevKitDependencyPath, loggerFactory); - // LSP server doesn't have the pieces yet to support 'balanced' mode for source-generators. Hardcode us to - // 'automatic' for now. - var globalOptionService = exportProvider.GetExportedValue(); - globalOptionService.SetGlobalOption(WorkspaceConfigurationOptionsStorage.SourceGeneratorExecution, SourceGeneratorExecutionPreference.Automatic); - // The log file directory passed to us by VSCode might not exist yet, though its parent directory is guaranteed to exist. Directory.CreateDirectory(serverConfiguration.ExtensionLogDirectory); diff --git a/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs b/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs index 514450460e7f3..773b736d0cb20 100644 --- a/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs +++ b/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs @@ -50,5 +50,5 @@ public static WorkspaceConfigurationOptions GetWorkspaceConfigurationOptions(thi SourceGeneratorExecutionPreferenceUtilities.GetEditorConfigString)); public static readonly Option2 SourceGeneratorExecutionBalancedFeatureFlag = new( - "dotnet_source_generator_execution_balanced_feature_flag", true); + "dotnet_source_generator_execution_balanced_feature_flag", false); } diff --git a/src/VisualStudio/Core/Test/SolutionExplorer/SourceGeneratorItemTests.vb b/src/VisualStudio/Core/Test/SolutionExplorer/SourceGeneratorItemTests.vb index 74145221a2051..75edd90c0dd42 100644 --- a/src/VisualStudio/Core/Test/SolutionExplorer/SourceGeneratorItemTests.vb +++ b/src/VisualStudio/Core/Test/SolutionExplorer/SourceGeneratorItemTests.vb @@ -5,8 +5,7 @@ Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities -Imports Microsoft.CodeAnalysis.Editor.UnitTests -Imports Microsoft.CodeAnalysis.Host +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Shared.TestHooks Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.Text @@ -123,9 +122,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer End Using End Function - - Friend Async Function ChangeToRemoveAllGeneratedDocumentsUpdatesListCorrectly( - preference As SourceGeneratorExecutionPreference) As Task + + Public Async Function ChangeToRemoveAllGeneratedDocumentsUpdatesListCorrectly() As Task Dim workspaceXml = @@ -133,13 +131,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer - Using workspace = EditorTestWorkspace.Create( - workspaceXml, - composition:=EditorTestCompositions.EditorFeatures.AddParts(GetType(TestWorkspaceConfigurationService))) - - Dim configService = workspace.ExportProvider.GetExportedValue(Of TestWorkspaceConfigurationService) - configService.Options = New WorkspaceConfigurationOptions(SourceGeneratorExecution:=preference) - + Using workspace = EditorTestWorkspace.Create(workspaceXml) Dim projectId = workspace.Projects.Single().Id Dim source = CreateItemSourceForAnalyzerReference(workspace, projectId) Dim generatorItem = Assert.IsAssignableFrom(Of SourceGeneratorItem)(Assert.Single(source.Items)) @@ -155,31 +147,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer Await WaitForGeneratorsAndItemSourcesAsync(workspace) - ' In balanced-mode the SG file won't go away until a save/build happens. - If preference = SourceGeneratorExecutionPreference.Automatic Then - Assert.IsType(Of NoSourceGeneratedFilesPlaceholderItem)(Assert.Single(generatorFilesItemSource.Items)) - Else - Assert.IsType(Of SourceGeneratedFileItem)(Assert.Single(generatorFilesItemSource.Items)) - End If + Assert.IsType(Of NoSourceGeneratedFilesPlaceholderItem)(Assert.Single(generatorFilesItemSource.Items)) End Using End Function - - Friend Async Function AddingAGeneratedDocumentUpdatesListCorrectly( - preference As SourceGeneratorExecutionPreference) As Task + + Public Async Function AddingAGeneratedDocumentUpdatesListCorrectly() As Task Dim workspaceXml = - Using workspace = EditorTestWorkspace.Create( - workspaceXml, - composition:=EditorTestCompositions.EditorFeatures.AddParts(GetType(TestWorkspaceConfigurationService))) - - Dim configService = workspace.ExportProvider.GetExportedValue(Of TestWorkspaceConfigurationService) - configService.Options = New WorkspaceConfigurationOptions(SourceGeneratorExecution:=preference) - + Using workspace = EditorTestWorkspace.Create(workspaceXml) Dim projectId = workspace.Projects.Single().Id Dim source = CreateItemSourceForAnalyzerReference(workspace, projectId) Dim generatorItem = Assert.IsAssignableFrom(Of SourceGeneratorItem)(Assert.Single(source.Items)) @@ -199,12 +179,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer Await WaitForGeneratorsAndItemSourcesAsync(workspace) - ' In balanced-mode the SG file won't be created until a save/build happens. - If preference = SourceGeneratorExecutionPreference.Automatic Then - Assert.IsType(Of SourceGeneratedFileItem)(Assert.Single(generatorFilesItemSource.Items)) - Else - Assert.IsType(Of NoSourceGeneratedFilesPlaceholderItem)(Assert.Single(generatorFilesItemSource.Items)) - End If + Assert.IsType(Of SourceGeneratedFileItem)(Assert.Single(generatorFilesItemSource.Items)) ' Add a second item and see if it updates correctly again workspace.OnAdditionalDocumentAdded( @@ -213,12 +188,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer "Test2.txt")) Await WaitForGeneratorsAndItemSourcesAsync(workspace) - - If preference = SourceGeneratorExecutionPreference.Automatic Then - Assert.Equal(2, generatorFilesItemSource.Items.Cast(Of SourceGeneratedFileItem)().Count()) - Else - Assert.Equal(1, generatorFilesItemSource.Items.Cast(Of NoSourceGeneratedFilesPlaceholderItem)().Count()) - End If + Assert.Equal(2, generatorFilesItemSource.Items.Cast(Of SourceGeneratedFileItem)().Count()) End Using End Function diff --git a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs index c4b6d2b96349c..a454f7215ff29 100644 --- a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs +++ b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs @@ -535,8 +535,6 @@ private async Task OnBatchScopeDisposedMaybeAsync(bool useAsync) var additionalDocumentsToOpen = new List<(DocumentId documentId, SourceTextContainer textContainer)>(); var analyzerConfigDocumentsToOpen = new List<(DocumentId documentId, SourceTextContainer textContainer)>(); - var hasAnalyzerChanges = _analyzersAddedInBatch.Count > 0 || _analyzersRemovedInBatch.Count > 0; - await _projectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybeAsync(useAsync, solutionChanges => { _sourceFiles.UpdateSolutionForBatch( @@ -668,21 +666,25 @@ await _projectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybeAsync(useAsyn }).ConfigureAwait(false); foreach (var (documentId, textContainer) in documentsToOpen) + { await _projectSystemProjectFactory.ApplyChangeToWorkspaceMaybeAsync(useAsync, w => w.OnDocumentOpened(documentId, textContainer)).ConfigureAwait(false); + } foreach (var (documentId, textContainer) in additionalDocumentsToOpen) + { await _projectSystemProjectFactory.ApplyChangeToWorkspaceMaybeAsync(useAsync, w => w.OnAdditionalDocumentOpened(documentId, textContainer)).ConfigureAwait(false); + } foreach (var (documentId, textContainer) in analyzerConfigDocumentsToOpen) + { await _projectSystemProjectFactory.ApplyChangeToWorkspaceMaybeAsync(useAsync, w => w.OnAnalyzerConfigDocumentOpened(documentId, textContainer)).ConfigureAwait(false); + } // Give the host the opportunity to check if those files are open if (documentFileNamesAdded.Count > 0) + { await _projectSystemProjectFactory.RaiseOnDocumentsAddedMaybeAsync(useAsync, documentFileNamesAdded.ToImmutable()).ConfigureAwait(false); - - // If we added or removed analyzers, then re-run all generators to bring them up to date. - if (hasAnalyzerChanges) - _projectSystemProjectFactory.Workspace.EnqueueUpdateSourceGeneratorVersion(projectId: null, forceRegeneration: true); + } } } diff --git a/src/Workspaces/CoreTestUtilities/Workspaces/TestWorkspaceConfigurationService.cs b/src/Workspaces/CoreTestUtilities/Workspaces/TestWorkspaceConfigurationService.cs index c19eed238124a..9915049dc04bb 100644 --- a/src/Workspaces/CoreTestUtilities/Workspaces/TestWorkspaceConfigurationService.cs +++ b/src/Workspaces/CoreTestUtilities/Workspaces/TestWorkspaceConfigurationService.cs @@ -4,16 +4,24 @@ using System; using System.Composition; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -namespace Roslyn.Test.Utilities; - -[Export, Shared, PartNotDiscoverable] -[ExportWorkspaceService(typeof(IWorkspaceConfigurationService), ServiceLayer.Test)] -[method: ImportingConstructor] -[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class TestWorkspaceConfigurationService() : IWorkspaceConfigurationService +namespace Roslyn.Test.Utilities { - public WorkspaceConfigurationOptions Options { get; set; } + [Export] + [ExportWorkspaceService(typeof(IWorkspaceConfigurationService), ServiceLayer.Test)] + [Shared] + [PartNotDiscoverable] + internal sealed class TestWorkspaceConfigurationService : IWorkspaceConfigurationService + { + public WorkspaceConfigurationOptions Options { get; set; } + + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public TestWorkspaceConfigurationService() + { + } + } }