Skip to content

Commit

Permalink
misc. code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Sep 19, 2024
1 parent cf9998d commit f1f4d3b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<FixtureTestSelector>
<FixtureName>Microsoft.DotNet.Interactive.ExtensionLab.Tests.DataFrameTypeGeneratorTests</FixtureName>
</FixtureTestSelector>
<FixtureTestSelector>
<FixtureName>Microsoft.DotNet.Interactive.ExtensionLab.Tests.InspectTests</FixtureName>
</FixtureTestSelector>
</IgnoredTests>
</Settings>
</ProjectConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
<FixtureTestSelector>
<FixtureName>Microsoft.DotNet.Interactive.PowerShell.Tests.SecretManagerTests</FixtureName>
</FixtureTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.GetCorrectProfilePaths</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.PowerShell_get_history_should_work</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.PowerShell_progress_sends_updated_display_values</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.PowerShell_token_variables_work</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.TryGetVariable_unwraps_PowerShell_object("$x = New-Object -TypeName System.IO.FileInfo -ArgumentList c:\\temp\\some.txt", "System.IO.FileInfo")</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.PowerShell.Tests.PowerShellKernelTests.When_code_produces_errors_then_the_command_fails</TestName>
</NamedTestSelector>
</IgnoredTests>
</Settings>
</ProjectConfiguration>
22 changes: 6 additions & 16 deletions src/Microsoft.DotNet.Interactive/Connection/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,15 @@ public static CommandOrEvent DeserializeCommandOrEvent(JsonElement jsonObject)
var kernelCommandEnvelope = KernelCommandEnvelope.Deserialize(jsonObject);
return new CommandOrEvent(kernelCommandEnvelope.Command);
}
}

private static bool IsEventEnvelope(JsonElement jsonObject)
{
if (jsonObject.TryGetProperty("eventType", out var eventType))
static bool IsEventEnvelope(JsonElement jsonObject)
{
return !string.IsNullOrWhiteSpace(eventType.GetString());
}

return false;
}
if (jsonObject.TryGetProperty("eventType", out var eventType))
{
return !string.IsNullOrWhiteSpace(eventType.GetString());
}

private static bool IsCommandEnvelope(JsonElement jsonObject)
{
if (jsonObject.TryGetProperty("commandType", out var commandType))
{
return !string.IsNullOrWhiteSpace(commandType.GetString());
return false;
}

return false;
}
}
28 changes: 14 additions & 14 deletions src/Microsoft.DotNet.Interactive/Kernel.Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ private static async Task<string> GetInputAsync(

public static void CSS(string content) =>
// From https://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript
Javascript($@"
var css = `{content}`,
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
if (style.styleSheet){{
// This is required for IE8 and below.
style.styleSheet.cssText = css;
}} else {{
style.appendChild(document.createTextNode(css));
}}");
Javascript($$"""
var css = `{{content}}`,
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
""");

public static void Javascript(string scriptContent)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DotNet.Interactive/KernelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static IEnumerable<Kernel> FindKernels(this Kernel kernel, Func<Kernel, b
{
CompositeKernel c => predicate(c) ? new[] { kernel }.Concat(c.ChildKernels.Where(predicate)) : c.ChildKernels.Where(predicate),
_ when predicate(kernel) => new[] { kernel },
_ => Enumerable.Empty<Kernel>()
_ => []
};
}

Expand Down
15 changes: 0 additions & 15 deletions src/Microsoft.DotNet.Interactive/KernelScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ public async Task IdleAsync()
await currentlyRunning.TaskCompletionSource.Task;
}

// FIX: (IdleAsync)
Log.Info($"{nameof(IdleAsync)}: SignalAndWait on thread {Thread.CurrentThread.ManagedThreadId} with {_childOperationsBarrier.ParticipantCount} participants, {_childOperationsBarrier.ParticipantsRemaining} remaining");

switch (_childOperationsBarrier.ParticipantCount)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}

try
{
_childOperationsBarrier.SignalAndWait();
Expand Down
9 changes: 3 additions & 6 deletions src/polyglot-notebooks-vscode-common/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ export async function activate(context: vscode.ExtensionContext) {
const environmentVariables = { ...polyglotConfig.get<{ [key: string]: string }>('kernelEnvironmentVariables'), 'DOTNET_CLI_CULTURE': getCurrentCulture(), 'DOTNET_CLI_UI_LANGUAGE': getCurrentCulture() };

const processStart = processArguments(argsTemplate, workingDirectory, DotNetPathManager.getDotNetPath(), launchOptions!.workingDirectory, environmentVariables);
let notification = {
displayError: async (message: string) => { await vscode.window.showErrorMessage(message, { modal: false }); },
displayInfo: async (message: string) => { await vscode.window.showInformationMessage(message, { modal: false }); },
};

const channel = new StdioDotnetInteractiveChannel(notebookUri.toString(), processStart, diagnosticsChannel, (pid, code, signal) => {
clientMapper.closeClient(notebookUri, false);
});
Expand All @@ -170,15 +167,15 @@ export async function activate(context: vscode.ExtensionContext) {
return vscode.env.language;
}


function configureKernel(compositeKernel: CompositeKernel, notebookUri: vscodeLike.Uri) {
compositeKernel.setDefaultTargetKernelNameForCommand(commandsAndEvents.RequestInputType, compositeKernel.name);
compositeKernel.setDefaultTargetKernelNameForCommand(commandsAndEvents.SendEditableCodeType, compositeKernel.name);
compositeKernel.kernelInfo.description = `This Kernel is provided by the .NET Interactive Extension.
This allows adding new cells to the notebook and prompting user for input.`;

compositeKernel.registerCommandHandler({
commandType: commandsAndEvents.RequestInputType, handle: async (commandInvocation) => {
commandType: commandsAndEvents.RequestInputType,
handle: async (commandInvocation) => {
const requestInput = <commandsAndEvents.RequestInput>commandInvocation.commandEnvelope.command;
const prompt = requestInput.prompt;
const password = requestInput.isPassword;
Expand Down

0 comments on commit f1f4d3b

Please sign in to comment.