-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Hot Reload watch service #51967
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
Merged
Merged
Hot Reload watch service #51967
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/Features/Core/Portable/ExternalAccess/Watch/Api/WatchHotReloadService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // 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 file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Immutable; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Diagnostics; | ||
| using Microsoft.CodeAnalysis.EditAndContinue; | ||
| using Microsoft.CodeAnalysis.Host; | ||
| using Microsoft.CodeAnalysis.Text; | ||
| using Microsoft.VisualStudio.Debugger.Contracts.EditAndContinue; | ||
| using Roslyn.Utilities; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.ExternalAccess.Watch.Api | ||
| { | ||
| internal sealed class WatchHotReloadService | ||
| { | ||
| private sealed class DebuggerService : IManagedEditAndContinueDebuggerService | ||
| { | ||
| public static readonly DebuggerService Instance = new(); | ||
|
|
||
| public Task<ImmutableArray<ManagedActiveStatementDebugInfo>> GetActiveStatementsAsync(CancellationToken cancellationToken) | ||
| => Task.FromResult(ImmutableArray<ManagedActiveStatementDebugInfo>.Empty); | ||
|
|
||
| public Task<ManagedEditAndContinueAvailability> GetAvailabilityAsync(Guid module, CancellationToken cancellationToken) | ||
| => Task.FromResult(new ManagedEditAndContinueAvailability(ManagedEditAndContinueAvailabilityStatus.Available)); | ||
|
|
||
| public Task PrepareModuleForUpdateAsync(Guid module, CancellationToken cancellationToken) | ||
| => Task.CompletedTask; | ||
| } | ||
|
|
||
| public readonly struct Update | ||
| { | ||
| public readonly Guid ModuleId; | ||
| public readonly ImmutableArray<byte> ILDelta; | ||
| public readonly ImmutableArray<byte> MetadataDelta; | ||
| public readonly ImmutableArray<byte> PdbDelta; | ||
|
|
||
| public Update(Guid moduleId, ImmutableArray<byte> ilDelta, ImmutableArray<byte> metadataDelta, ImmutableArray<byte> pdbDelta) | ||
| { | ||
| ModuleId = moduleId; | ||
| ILDelta = ilDelta; | ||
| MetadataDelta = metadataDelta; | ||
| PdbDelta = pdbDelta; | ||
| } | ||
| } | ||
|
|
||
| private static readonly SolutionActiveStatementSpanProvider s_solutionActiveStatementSpanProvider = | ||
| (_, _) => ValueTaskFactory.FromResult(ImmutableArray<TextSpan>.Empty); | ||
|
|
||
| private readonly IEditAndContinueWorkspaceService _encService; | ||
|
|
||
| public WatchHotReloadService(HostWorkspaceServices services) | ||
| => _encService = services.GetRequiredService<IEditAndContinueWorkspaceService>(); | ||
|
|
||
| /// <summary> | ||
| /// Starts the watcher. | ||
| /// </summary> | ||
| /// <param name="solution">Solution that represents sources that match the built binaries on disk.</param> | ||
| /// <param name="cancellationToken">Cancellation token.</param> | ||
| /// <returns></returns> | ||
| public async Task StartSessionAsync(Solution solution, CancellationToken cancellationToken) | ||
| => await _encService.StartDebuggingSessionAsync(solution, captureMatchingDocuments: true, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| public async Task<(ImmutableArray<Update> updates, ImmutableArray<DiagnosticData> diagnostics)> EmitSolutionUpdateAsync(Solution solution, CancellationToken cancellationToken) | ||
| { | ||
| _encService.StartEditSession(DebuggerService.Instance, out _); | ||
|
|
||
| var (updates, diagnostics) = await _encService.EmitSolutionUpdateAsync(solution, s_solutionActiveStatementSpanProvider, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (updates.Status == ManagedModuleUpdateStatus.Ready) | ||
| { | ||
| _encService.CommitSolutionUpdate(); | ||
| } | ||
|
|
||
| _encService.EndEditSession(out _); | ||
|
|
||
| if (updates.Status == ManagedModuleUpdateStatus.Blocked) | ||
| { | ||
| return default; | ||
| } | ||
|
|
||
| return (updates.Updates.SelectAsArray(update => new Update(update.Module, update.ILDelta, update.MetadataDelta, update.PdbDelta)), diagnostics); | ||
| } | ||
|
|
||
| public void EndSession() | ||
| => _encService.EndDebuggingSession(out _); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.