Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IManagedHotReloadAgent2 and IManagedHotReloadAgent4 for ProjectHotReloadSession #9555

Merged
merged 27 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
81826bd
implement IManagedHotReloadAgent2
LittleLittleCloud Oct 10, 2024
c93988e
return project full path
LittleLittleCloud Oct 11, 2024
fd6a529
update
LittleLittleCloud Oct 14, 2024
4a9c235
update
LittleLittleCloud Oct 14, 2024
1166c77
implement RestartProject
LittleLittleCloud Oct 17, 2024
5b0435e
Merge branch 'u/implementV2' of https://github.com/LittleLittleCloud/…
LittleLittleCloud Oct 17, 2024
0deb4cb
update debug contract version
LittleLittleCloud Oct 17, 2024
1cc524d
update
LittleLittleCloud Oct 17, 2024
a262c58
bump debugger contract version
LittleLittleCloud Oct 18, 2024
682b3af
revert setup/ProjectSystemSetup/ProjectSystemSetup.csproj
LittleLittleCloud Oct 18, 2024
4d35fc8
add ISolutionBuildManager mock to test
LittleLittleCloud Oct 21, 2024
1026620
return _sessionManager._project
LittleLittleCloud Oct 21, 2024
6910c67
update
LittleLittleCloud Oct 30, 2024
7c4f9cf
dispose event listenr when stop project
LittleLittleCloud Oct 30, 2024
86a6bc3
update
LittleLittleCloud Oct 31, 2024
fea82ec
remove restarting seesion from project system side
LittleLittleCloud Nov 1, 2024
dc2f0d5
Merge branch 'main' into u/implementV2
LittleLittleCloud Nov 11, 2024
e622839
clean up
LittleLittleCloud Nov 12, 2024
07809e9
Merge branch 'u/implementV2' of https://github.com/LittleLittleCloud/…
LittleLittleCloud Nov 12, 2024
cad337f
fix comment
LittleLittleCloud Nov 12, 2024
240c2a5
remove unused subscription listener
LittleLittleCloud Nov 13, 2024
135231a
revert change in solution build manager
LittleLittleCloud Nov 13, 2024
c8bbcbc
make HotReloadState back to private again
LittleLittleCloud Nov 13, 2024
299f64e
fix build error
LittleLittleCloud Nov 13, 2024
54b93b9
Update src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSys…
LittleLittleCloud Nov 14, 2024
31c664e
fix comment
LittleLittleCloud Nov 14, 2024
e89e342
Update src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSys…
LittleLittleCloud Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<VSDebuggerVersion>17.13.0-beta.24561.1</VSDebuggerVersion>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -44,6 +45,8 @@
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.7.37" />
<PackageVersion Include="Microsoft.VisualStudio.ComponentModelHost" Version="17.13.13-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.12.18" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="$(VSDebuggerVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" Version="$(VSDebuggerVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Core" Version="17.13.38047-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Services" Version="17.13.38055-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.DataDesign.Common" Version="17.13.38055-preview.1" />
Expand Down
1 change: 1 addition & 0 deletions setup/ProjectSystemSetup/ProjectSystemSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- Local properties -->
<PropertyGroup>
<_ManagedProjectName>Microsoft.VisualStudio.ProjectSystem.Managed</_ManagedProjectName>
<VSSDKTargetPlatformRegRootSuffix>RoslynDev</VSSDKTargetPlatformRegRootSuffix>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ internal interface ISolutionBuildManager
IVsHierarchy[] GetProjectDependencies(IVsHierarchy hierarchy);

void StartUpdateSpecificProjectConfigurations(IVsHierarchy[] hierarchy, uint[] buildFlags, uint dwFlags);

int StartSimpleUpdateProjectConfiguration(
IVsHierarchy pIVsHierarchyToBuild,
IVsHierarchy? pIVsHierarchyDependent,
string? pszDependentConfigurationCanonicalName,
uint dwFlags,
uint dwDefQueryResults,
int fSuppressUI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public int QueryBuildManagerBusy()
JoinableFactory.Context.VerifyIsOnMainThread();

ErrorHandler.ThrowOnFailure(_vsSolutionBuildManager2.QueryBuildManagerBusy(out int flags));

return flags;
}

Expand All @@ -108,10 +108,10 @@ public uint QueryBuildManagerBusyEx()
JoinableFactory.Context.VerifyIsOnMainThread();

ErrorHandler.ThrowOnFailure(_vsSolutionBuildManager3.QueryBuildManagerBusyEx(out uint flags));

return flags;
}


public void SaveDocumentsBeforeBuild(IVsHierarchy hierarchy, uint itemId, uint docCookie)
{
Assumes.NotNull(_vsSolutionBuildManager2);
Expand Down Expand Up @@ -168,5 +168,13 @@ public void StartUpdateSpecificProjectConfigurations(IVsHierarchy[] hierarchy, u
dwFlags: dwFlags,
fSuppressUI: 0));
}

public int StartSimpleUpdateProjectConfiguration(IVsHierarchy pIVsHierarchyToBuild, IVsHierarchy? pIVsHierarchyDependent, string? pszDependentConfigurationCanonicalName, uint dwFlags, uint dwDefQueryResults, int fSuppressUI)
{
Assumes.NotNull(_vsSolutionBuildManager2);
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved
JoinableFactory.Context.VerifyIsOnMainThread();

return ErrorHandler.ThrowOnFailure(_vsSolutionBuildManager2.StartSimpleUpdateProjectConfiguration(pIVsHierarchyToBuild, pIVsHierarchyDependent, pszDependentConfigurationCanonicalName, dwFlags, dwDefQueryResults, fSuppressUI));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.VisualStudio.Debugger.Contracts.HotReload;
using Microsoft.VisualStudio.HotReload.Components.DeltaApplier;
using Microsoft.VisualStudio.ProjectSystem.VS.Build;

namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload
{
Expand All @@ -11,16 +12,19 @@ internal class ProjectHotReloadAgent : IProjectHotReloadAgent
private readonly Lazy<IHotReloadAgentManagerClient> _hotReloadAgentManagerClient;
private readonly Lazy<IHotReloadDiagnosticOutputService> _hotReloadDiagnosticOutputService;
private readonly Lazy<IManagedDeltaApplierCreator> _managedDeltaApplierCreator;
private readonly Lazy<ISolutionBuildManager> _solutionBuildManager;
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved

[ImportingConstructor]
public ProjectHotReloadAgent(
Lazy<IHotReloadAgentManagerClient> hotReloadAgentManagerClient,
Lazy<IHotReloadDiagnosticOutputService> hotReloadDiagnosticOutputService,
Lazy<IManagedDeltaApplierCreator> managedDeltaApplierCreator)
Lazy<IManagedDeltaApplierCreator> managedDeltaApplierCreator,
Lazy<ISolutionBuildManager> solutionBuildManager)
{
_hotReloadAgentManagerClient = hotReloadAgentManagerClient;
_hotReloadDiagnosticOutputService = hotReloadDiagnosticOutputService;
_managedDeltaApplierCreator = managedDeltaApplierCreator;
_solutionBuildManager = solutionBuildManager;
}

public IProjectHotReloadSession? CreateHotReloadSession(string id, int variant, string runtimeVersion, IProjectHotReloadSessionCallback callback)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.VisualStudio.Debugger.Contracts.EditAndContinue;
using Microsoft.VisualStudio.Debugger.Contracts.HotReload;
using Microsoft.VisualStudio.HotReload.Components.DeltaApplier;
using Microsoft.VisualStudio.ProjectSystem.VS.Build;
using static Microsoft.VisualStudio.ProjectSystem.VS.HotReload.ProjectHotReloadSessionManager;

namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload
{
internal class ProjectHotReloadSession : IManagedHotReloadAgent, IProjectHotReloadSession, IProjectHotReloadSessionInternal
internal class ProjectHotReloadSession : IManagedHotReloadAgent, IManagedHotReloadAgent2, IManagedHotReloadAgent4, IProjectHotReloadSession, IProjectHotReloadSessionInternal
{
private readonly string _variant;
private readonly string _runtimeVersion;
Expand All @@ -15,6 +18,9 @@ internal class ProjectHotReloadSession : IManagedHotReloadAgent, IProjectHotRelo
private readonly IProjectHotReloadSessionCallback _callback;

private bool _sessionActive;

// This flag is used to identify Debug|NonDebug cases
private bool _isRunningUnderDebugger;
private IDeltaApplier? _deltaApplier;

public ProjectHotReloadSession(
Expand Down Expand Up @@ -99,6 +105,7 @@ public async Task StartSessionAsync(bool runningUnderDebugger, CancellationToken
),
default);
_sessionActive = true;
_isRunningUnderDebugger = runningUnderDebugger;
EnsureDeltaApplierforSession();
}

Expand All @@ -107,7 +114,6 @@ public async Task StopSessionAsync(CancellationToken cancellationToken)
if (_sessionActive)
{
_sessionActive = false;

await _hotReloadAgentManagerClient.Value.AgentTerminatedAsync(this, cancellationToken);
WriteToOutputWindow(
new HotReloadLogMessage(
Expand Down Expand Up @@ -248,10 +254,15 @@ public async ValueTask RestartAsync(CancellationToken cancellationToken)
),
cancellationToken);

await _callback.RestartProjectAsync(cancellationToken);

// TODO: Should we stop the session here? Or does someone else do it?
// TODO: Should we handle rebuilding here? Or do we expect the callback to handle it?
if (_callback is HotReloadState hrs)
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved
{
await hrs.RestartProjectAsync(_isRunningUnderDebugger, cancellationToken);

return;
}

await _callback.RestartProjectAsync(cancellationToken);
}

public async ValueTask StopAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -288,5 +299,25 @@ private void EnsureDeltaApplierforSession()
?? _deltaApplierCreator.Value.CreateManagedDeltaApplier(_runtimeVersion);
}
}

public ValueTask<int?> GetTargetLocalProcessIdAsync(CancellationToken cancellationToken)
{
if (_callback is HotReloadState hotReloadState)
{
return new ValueTask<int?>(hotReloadState.Process?.Id);
}

return new ValueTask<int?>();
}

public ValueTask<string?> GetProjectFullPathAsync(CancellationToken cancellationToken)
{
if (_callback is HotReloadState hrs)
{
return new ValueTask<string?>(hrs.Project?.FullPath);
}

return new ValueTask<string?>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Debugger.Contracts.HotReload;
using Microsoft.VisualStudio.HotReload.Components.DeltaApplier;
using Microsoft.VisualStudio.ProjectSystem.Debug;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.ProjectSystem.VS.Build;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;

namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload
Expand All @@ -19,6 +23,8 @@ internal class ProjectHotReloadSessionManager : OnceInitializedOnceDisposedAsync
private readonly Lazy<IProjectHotReloadAgent> _projectHotReloadAgent;
private readonly Lazy<IHotReloadDiagnosticOutputService> _hotReloadDiagnosticOutputService;
private readonly Lazy<IProjectHotReloadNotificationService> _projectHotReloadNotificationService;
private readonly Lazy<ISolutionBuildManager> _solutionBuildManager;
private readonly IProjectThreadingService _projectThreadingService;

// Protect the state from concurrent access. For example, our Process.Exited event
// handler may run on one thread while we're still setting up the session on
Expand All @@ -39,15 +45,18 @@ public ProjectHotReloadSessionManager(
IActiveDebugFrameworkServices activeDebugFrameworkServices,
Lazy<IProjectHotReloadAgent> projectHotReloadAgent,
Lazy<IHotReloadDiagnosticOutputService> hotReloadDiagnosticOutputService,
Lazy<IProjectHotReloadNotificationService> projectHotReloadNotificationService)
Lazy<IProjectHotReloadNotificationService> projectHotReloadNotificationService,
Lazy<ISolutionBuildManager> solutionBuilderManager)
: base(threadingService.JoinableTaskContext)
{
_project = project;
_projectThreadingService = threadingService;
_projectFaultHandlerService = projectFaultHandlerService;
_activeDebugFrameworkServices = activeDebugFrameworkServices;
_projectHotReloadAgent = projectHotReloadAgent;
_hotReloadDiagnosticOutputService = hotReloadDiagnosticOutputService;
_projectHotReloadNotificationService = projectHotReloadNotificationService;
_solutionBuildManager = solutionBuilderManager;

_semaphore = ReentrantSemaphore.Create(
initialCount: 1,
Expand Down Expand Up @@ -352,10 +361,29 @@ private async Task OnProcessExitedAsync(HotReloadState hotReloadState)
return null;
}

private static Task<bool> RestartProjectAsync(HotReloadState hotReloadState, CancellationToken cancellationToken)
private async Task<bool> RestartProjectAsync(
HotReloadState hotReloadState,
bool isRunningUnderDebug,
CancellationToken cancellationToken)
{
// TODO: Support restarting the project.
return TaskResult.False;
Assumes.NotNull(_project.Services.HostObject);
await _projectThreadingService.SwitchToUIThread();

// Step 1: Debug or NonDebug?
uint dbgLaunchFlag = isRunningUnderDebug ? (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_LAUNCHDEBUG : (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_LAUNCH;

// Step 2: Build and Launch Debug
var projectVsHierarchy = (IVsHierarchy)_project.Services.HostObject;

var result = _solutionBuildManager.Value.StartSimpleUpdateProjectConfiguration(
pIVsHierarchyToBuild: projectVsHierarchy,
pIVsHierarchyDependent: null,
pszDependentConfigurationCanonicalName: null,
dwFlags: (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD | dbgLaunchFlag,
dwDefQueryResults: (uint)VSSOLNBUILDQUERYRESULTS.VSSBQR_SAVEBEFOREBUILD_QUERY_YES,
fSuppressUI: 0);

return result == HResult.OK;
}

private static Task OnAfterChangesAppliedAsync(HotReloadState hotReloadState, CancellationToken cancellationToken)
Expand Down Expand Up @@ -449,24 +477,25 @@ async Task ApplyHotReloadUpdateInternalAsync()
}
}

private class HotReloadState : IProjectHotReloadSessionCallback
internal class HotReloadState : IProjectHotReloadSessionCallback
{
private readonly ProjectHotReloadSessionManager _sessionManager;

public Process? Process { get; set; }
public IProjectHotReloadSession? Session { get; set; }

// TODO: Support restarting the session.
public bool SupportsRestart => false;
public ProjectHotReloadSessionManager SessionManager { get; }
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved

public bool SupportsRestart => true;

public UnconfiguredProject? Project => SessionManager._project;

public HotReloadState(ProjectHotReloadSessionManager sessionManager)
{
_sessionManager = sessionManager;
SessionManager = sessionManager;
}

internal void OnProcessExited(object sender, EventArgs e)
{
_sessionManager.OnProcessExited(this);
SessionManager.OnProcessExited(this);
}

public Task OnAfterChangesAppliedAsync(CancellationToken cancellationToken)
Expand All @@ -476,12 +505,17 @@ public Task OnAfterChangesAppliedAsync(CancellationToken cancellationToken)

public Task<bool> StopProjectAsync(CancellationToken cancellationToken)
{
return _sessionManager.StopProjectAsync(this, cancellationToken).AsTask();
return SessionManager.StopProjectAsync(this, cancellationToken).AsTask();
}

public Task<bool> RestartProjectAsync(CancellationToken cancellationToken)
{
return ProjectHotReloadSessionManager.RestartProjectAsync(this, cancellationToken);
return Task.FromResult(false);
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved
}

public Task<bool> RestartProjectAsync(bool isRunningUnderDebug, CancellationToken cancellationToken)
{
return SessionManager.RestartProjectAsync(this, isRunningUnderDebug, cancellationToken);
}

public IDeltaApplier? GetDeltaApplier()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.VisualStudio.ProjectSystem.Debug;
using Microsoft.VisualStudio.ProjectSystem.VS.Build;

namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload
{
Expand Down Expand Up @@ -176,7 +177,8 @@ private static ProjectHotReloadSessionManager CreateHotReloadSessionManager(Conf
activeDebugFrameworkServices,
new Lazy<IProjectHotReloadAgent>(() => IProjectHotReloadAgentFactory.Create()),
new Lazy<IHotReloadDiagnosticOutputService>(() => IHotReloadDiagnosticOutputServiceFactory.Create(outputServiceCallback)),
new Lazy<IProjectHotReloadNotificationService>(() => IProjectHotReloadNotificationServiceFactory.Create()));
new Lazy<IProjectHotReloadNotificationService>(() => IProjectHotReloadNotificationServiceFactory.Create()),
new Lazy<ISolutionBuildManager>(() => ISolutionBuildManagerFactory.Create(null, null, false, false)));

return manager;
}
Expand Down
Loading