-
Notifications
You must be signed in to change notification settings - Fork 397
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
add support for clearing variables from HttpKernel #3467
Merged
jonsequitur
merged 2 commits into
dotnet:main
from
jonsequitur:HttpKernel-variable-clearing
Feb 27, 2024
Merged
Changes from all commits
Commits
Show all changes
2 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 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
This file contains 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
This file contains 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,13 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.DotNet.Interactive.Commands; | ||
|
||
namespace Microsoft.DotNet.Interactive.Http; | ||
|
||
public class ClearValues : KernelCommand | ||
{ | ||
public ClearValues(string? targetKernelName = null) : base(targetKernelName) | ||
{ | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -10,11 +10,8 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
|
@@ -24,6 +21,7 @@ namespace Microsoft.DotNet.Interactive.Http; | |
|
||
public class HttpKernel : | ||
Kernel, | ||
IKernelCommandHandler<ClearValues>, | ||
IKernelCommandHandler<RequestValue>, | ||
IKernelCommandHandler<SendValue>, | ||
IKernelCommandHandler<SubmitCode>, | ||
|
@@ -58,6 +56,12 @@ This Kernel is able to execute http requests and display the results. | |
RegisterForDisposal(_client); | ||
} | ||
|
||
public Task HandleAsync(ClearValues command, KernelInvocationContext context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we implement this using explicit interface implementation and avoid the public API similar to what we do for the other commands below? |
||
{ | ||
_variables.Clear(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
Task IKernelCommandHandler<RequestValue>.HandleAsync(RequestValue command, KernelInvocationContext context) | ||
{ | ||
if (_variables.TryGetValue(command.Name, out var value)) | ||
|
13 changes: 13 additions & 0 deletions
13
...nection/SerializationTests.Command_contract_has_not_been_broken.approved.ClearValues.json
This file contains 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,13 @@ | ||
{ | ||
"token": "the-token", | ||
"commandType": "ClearValues", | ||
"command": { | ||
"targetKernelName": null, | ||
"originUri": null, | ||
"destinationUri": null | ||
}, | ||
"routingSlip": [ | ||
"kernel://somelocation/kernelName?tag=arrived", | ||
"kernel://somelocation/kernelName" | ||
] | ||
} |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems generally useful. Any reason why this is not defined in the core
Interactive
assembly?Currently the http editor does not (need to) directly reference the
Interactive.Http
assembly. Adding that reference may not be problematic - but still wanted to double check whether we can move this to the main assembly and avoid the additional dependency.