Skip to content

Commit 7ab4622

Browse files
authored
Merge pull request #8898 from davkean/dev/davkean/LazyWorkspace
Avoid instantiating Roslyn package via RenamerProjectTreeActionHandler
2 parents 56654ae + f8a0f44 commit 7ab4622

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/RenamerProjectTreeActionHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ internal partial class RenamerProjectTreeActionHandler : ProjectTreeActionHandle
3131
private readonly IUserNotificationServices _userNotificationServices;
3232
private readonly IWaitIndicator _waitService;
3333
private readonly IRoslynServices _roslynServices;
34-
private readonly Workspace _workspace;
34+
private readonly Lazy<Workspace> _workspace;
3535
private readonly IVsService<SVsOperationProgress, IVsOperationProgressStatusService> _operationProgressService;
3636
private readonly IVsService<SVsSettingsPersistenceManager, ISettingsManager> _settingsManagerService;
3737

3838
[ImportingConstructor]
3939
public RenamerProjectTreeActionHandler(
4040
UnconfiguredProject unconfiguredProject,
4141
IUnconfiguredProjectVsServices projectVsServices,
42-
[Import(typeof(VisualStudioWorkspace))] Workspace workspace,
42+
[Import(typeof(VisualStudioWorkspace))]Lazy<Workspace> workspace,
4343
IEnvironmentOptions environmentOptions,
4444
IUserNotificationServices userNotificationServices,
4545
IRoslynServices roslynServices,
@@ -155,7 +155,7 @@ private async Task<Solution> PublishLatestSolutionAsync(CancellationToken cancel
155155
await stageStatus.WaitForCompletionAsync().WithCancellation(cancellationToken);
156156

157157
// The result of that wait, is basically a "new" published Solution, so grab it
158-
return _workspace.CurrentSolution;
158+
return _workspace.Value.CurrentSolution;
159159
}
160160

161161
private static async Task<(bool, Renamer.RenameDocumentActionSet?)> GetRenameSymbolsActionsAsync(CodeAnalysis.Project project, string? oldFilePath, string newFileWithExtension)
@@ -220,7 +220,7 @@ protected virtual async Task<bool> IsAutomationFunctionAsync()
220220
}
221221

222222
private CodeAnalysis.Project? GetCurrentProject() =>
223-
_workspace.CurrentSolution.Projects.FirstOrDefault(proj => StringComparers.Paths.Equals(proj.FilePath, _projectVsServices.Project.FullPath));
223+
_workspace.Value.CurrentSolution.Projects.FirstOrDefault(proj => StringComparers.Paths.Equals(proj.FilePath, _projectVsServices.Project.FullPath));
224224

225225
private static CodeAnalysis.Document GetDocument(CodeAnalysis.Project project, string? filePath) =>
226226
project.Documents.FirstOrDefault(d => StringComparers.Paths.Equals(d.FilePath, filePath));

tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Rename/RenamerTestsBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal class TestRenamerProjectTreeActionHandler : RenamerProjectTreeActionHan
5050
public TestRenamerProjectTreeActionHandler(
5151
UnconfiguredProject unconfiguredProject,
5252
IUnconfiguredProjectVsServices projectVsServices,
53-
[Import(typeof(VisualStudioWorkspace))] Workspace workspace,
53+
[Import(typeof(VisualStudioWorkspace))]Lazy<Workspace> workspace,
5454
IEnvironmentOptions environmentOptions,
5555
IUserNotificationServices userNotificationServices,
5656
IRoslynServices roslynServices,
@@ -108,7 +108,7 @@ internal async Task RenameAsync(string sourceCode, string oldFilePath, string ne
108108

109109
var renamer = new TestRenamerProjectTreeActionHandler(unconfiguredProject,
110110
projectServices,
111-
ws,
111+
new Lazy<Workspace>(() => ws),
112112
environmentOptionsFactory,
113113
userNotificationServices,
114114
roslynServices,

0 commit comments

Comments
 (0)