Skip to content

Commit f8a0f44

Browse files
committed
Avoid instantiation Roslyn package via RenamerProjectTreeActionHandler
This code path was instantiating the Roslyn package along this path and causing Launch Profiler to take longer to initialize than it should be. mscorlib.dll!System.Lazy<Microsoft.VisualStudio.ProjectSystem.IProjectTreeActionHandler>.CreateValue() Unknown mscorlib.dll!System.Lazy<Microsoft.VisualStudio.ProjectSystem.IProjectTreeActionHandler>.LazyInitValue() Unknown Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.ProjectTreeActionContext.GetAddNewItemDirectory(Microsoft.VisualStudio.ProjectSystem.IProjectTreeActionHandlerContext context, Microsoft.VisualStudio.ProjectSystem.IProjectTree target) Line 107 C# Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.Designers.PhysicalProjectTreeProvider.GetAddNewItemDirectory(Microsoft.VisualStudio.ProjectSystem.IProjectTree target) Line 550 C# Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.ProjectTreeProviderExtensions.GetRootedAddNewItemDirectory(Microsoft.VisualStudio.ProjectSystem.IProjectTreeProvider provider, Microsoft.VisualStudio.ProjectSystem.IProjectTree target) Unknown Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.SpecialFileProviders.AppDesignerFolderSpecialFileProvider.GetDefaultFileAsync(Microsoft.VisualStudio.ProjectSystem.IProjectTreeProvider provider, Microsoft.VisualStudio.ProjectSystem.IProjectTree root) Unknown Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.SpecialFileProviders.AppDesignerFolderSpecialFileProvider.FindAppDesignerFolderCandidateAsync(Microsoft.VisualStudio.ProjectSystem.IProjectTreeProvider provider, Microsoft.VisualStudio.ProjectSystem.IProjectTree root) Unknown Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.SpecialFileProviders.AppDesignerFolderSpecialFileProvider.FindFileAsync(Microsoft.VisualStudio.ProjectSystem.IProjectTreeProvider provider, Microsoft.VisualStudio.ProjectSystem.IProjectTree root) Unknown Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.SpecialFileProviders.AbstractSpecialFileProvider.FindFileAsync(Microsoft.VisualStudio.ProjectSystem.IProjectTreeProvider provider, Microsoft.VisualStudio.ProjectSystem.IProjectTree root, Microsoft.VisualStudio.ProjectSystem.SpecialFileFlags flags) Unknown [Async] Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.SpecialFileProviders.AbstractSpecialFileProvider.GetFileAsync(Microsoft.VisualStudio.ProjectSystem.SpecialFiles fileId, Microsoft.VisualStudio.ProjectSystem.SpecialFileFlags flags, System.Threading.CancellationToken cancellationToken) Unknown > [Async] Microsoft.VisualStudio.ProjectSystem.Managed.dll!Microsoft.VisualStudio.ProjectSystem.Debug.LaunchSettingsProvider.GetLaunchSettingsFilePathNoCacheAsync() Unknown
1 parent 56654ae commit f8a0f44

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)