Skip to content

Commit b2079c8

Browse files
jonsequiturcolombod
authored andcommitted
update System.CommandLine, simplify some code
1 parent 60ec711 commit b2079c8

File tree

12 files changed

+22
-31
lines changed

12 files changed

+22
-31
lines changed

src/Microsoft.DotNet.Interactive.Formatting/Microsoft.DotNet.Interactive.Formatting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ItemGroup>
1919
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" />
2020
<PackageReference Include="microsoft.csharp" Version="4.7.0" />
21-
<PackageReference Include="System.CommandLine.Rendering" Version="0.3.0-alpha.20359.2" />
21+
<PackageReference Include="System.CommandLine.Rendering" Version="0.3.0-alpha.20371.2" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

src/Microsoft.DotNet.Interactive.Jupyter/KernelExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ IEnumerable<IHtmlContent> Summary(ICommand command, double offset)
165165
{
166166
yield return new HtmlString("<pre>");
167167
var level = indentLevel + offset;
168-
for (var i = 0; i < command.Aliases.Count; i++)
168+
foreach (var alias in command.Aliases)
169169
{
170-
yield return span[style: $"text-indent:{level:##.#}em; color:#512bd4"](command.Aliases[i]);
170+
yield return span[style: $"text-indent:{level:##.#}em; color:#512bd4"](alias);
171171

172-
if (i < command.Aliases.Count - 1)
172+
if (level < command.Aliases.Count - 1)
173173
{
174174
yield return span[style: $"text-indent:{level:##.#}em; color:darkgray"](", ");
175175
}

src/Microsoft.DotNet.Interactive.Telemetry/Microsoft.DotNet.Interactive.Telemetry.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
1010
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
1111
<PackageReference Include="Microsoft.Win32.Registry" Version="4.6.0" />
12-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20359.2" />
12+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20371.2" />
1313
</ItemGroup>
1414
</Project>

src/Microsoft.DotNet.Interactive/Commands/SubmitCode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ internal SubmitCode(
3838

3939
public string Code { get; }
4040

41-
// FIX: (SubmitCode) remove SubmissionType
4241
public SubmissionType SubmissionType { get; }
4342

4443
public override string ToString() => $"{nameof(SubmitCode)}: {Code.TruncateForDisplay()}";

src/Microsoft.DotNet.Interactive/CompositeKernel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void AddChooseKernelDirective(
9898
Kernel kernel,
9999
IEnumerable<string> aliases = null)
100100
{
101-
var chooseKernelCommand = kernel.CreateChooseKernelDirective();
101+
var chooseKernelCommand = kernel.ChooseKernelDirective;
102102

103103
if (aliases is {})
104104
{
@@ -108,8 +108,6 @@ private void AddChooseKernelDirective(
108108
}
109109
}
110110

111-
kernel.ChooseKernelDirective = chooseKernelCommand;
112-
113111
AddDirective(chooseKernelCommand);
114112
}
115113

src/Microsoft.DotNet.Interactive/Kernel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public abstract partial class Kernel : IDisposable
3030
private readonly ConcurrentQueue<KernelOperation> _commandQueue =
3131
new ConcurrentQueue<KernelOperation>();
3232
private FrontendEnvironment _frontendEnvironment;
33-
33+
private ChooseKernelDirective _chooseKernelDirective;
34+
3435
protected Kernel(string name)
3536
{
3637
if (string.IsNullOrWhiteSpace(name))
@@ -501,11 +502,11 @@ protected virtual void SetHandlingKernel(
501502

502503
public void Dispose() => _disposables.Dispose();
503504

504-
protected internal virtual ChooseKernelDirective CreateChooseKernelDirective()
505+
protected virtual ChooseKernelDirective CreateChooseKernelDirective()
505506
{
506507
return new ChooseKernelDirective(this);
507508
}
508509

509-
internal ChooseKernelDirective ChooseKernelDirective { get; set; }
510+
internal ChooseKernelDirective ChooseKernelDirective => _chooseKernelDirective ??= CreateChooseKernelDirective();
510511
}
511512
}

src/Microsoft.DotNet.Interactive/KeyValueStoreKernel.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private async Task StoreValueAsync(
9191
}
9292
}
9393

94-
protected internal override ChooseKernelDirective CreateChooseKernelDirective()
94+
protected override ChooseKernelDirective CreateChooseKernelDirective()
9595
{
9696
var nameOption = new Option<string>(
9797
"--name",
@@ -111,11 +111,7 @@ protected internal override ChooseKernelDirective CreateChooseKernelDirective()
111111
{
112112
var filePath = result.Tokens.Single().Value;
113113

114-
var fromUrlResult = result.Parent
115-
.Parent
116-
.Children
117-
.OfType<OptionResult>()
118-
.FirstOrDefault(c => c.Symbol == fromUrlOption);
114+
var fromUrlResult = result.FindResultFor(fromUrlOption);
119115

120116
if (fromUrlResult is {})
121117
{

src/Microsoft.DotNet.Interactive/Microsoft.DotNet.Interactive.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<MicrosoftCodeAnalysisAnalyzersVersion>2.9.6</MicrosoftCodeAnalysisAnalyzersVersion>
1919
<SystemRuntimeLoaderVersion>4.3.0</SystemRuntimeLoaderVersion>
2020
<SystemReactiveVersion>4.3.2</SystemReactiveVersion>
21-
<SystemCommandLineVersion>2.0.0-beta1.20359.2</SystemCommandLineVersion>
21+
<SystemCommandLineVersion>2.0.0-beta1.20371.2</SystemCommandLineVersion>
2222
</PropertyGroup>
2323

2424
<ItemGroup>

src/Microsoft.DotNet.Interactive/Parsing/PolyglotSyntaxParser.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ private bool IsDefinedInRootKernel(string directiveName)
179179

180180
private bool IsChooseKernelDirective(DirectiveToken directiveToken)
181181
{
182-
if (_kernelChooserDirectives is null &&
183-
_subkernelDirectiveParsersByKernelName != null)
182+
if (_kernelChooserDirectives is null)
184183
{
185184
_kernelChooserDirectives = new HashSet<string>(
186185
_rootKernelDirectiveParser

src/Microsoft.DotNet.Interactive/Parsing/SubmissionParser.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,17 @@ internal IDictionary<string, Func<Parser>> GetSubkernelDirectiveParsers()
228228

229229
for (var i = 0; i < compositeKernel.ChildKernels.Count; i++)
230230
{
231-
var kernel = compositeKernel.ChildKernels[i];
231+
var childKernel = compositeKernel.ChildKernels[i];
232232

233-
if (kernel.ChooseKernelDirective is { } chooseKernelDirective)
233+
if (childKernel.ChooseKernelDirective is { } chooseKernelDirective)
234234
{
235-
for (var j = 0; j < chooseKernelDirective.Aliases.Count; j++)
235+
foreach (var alias in chooseKernelDirective.Aliases)
236236
{
237-
var alias = chooseKernelDirective.Aliases[j][2..];
238-
239-
dict.Add(alias, GetParser);
237+
dict.Add(alias[2..], GetParser);
240238
}
241239
}
242240

243-
Parser GetParser() => kernel.SubmissionParser.GetDirectiveParser();
241+
Parser GetParser() => childKernel.SubmissionParser.GetDirectiveParser();
244242
}
245243

246244
return dict;
@@ -294,7 +292,7 @@ public void AddDirective(Command command)
294292

295293
_rootCommand.Add(command);
296294

297-
_directiveParser = null;
295+
ResetParser();
298296
}
299297

300298
internal void ResetParser()

0 commit comments

Comments
 (0)