Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 72f0404

Browse files
committed
add summary of all options to magic command hover text
1 parent db6b261 commit 72f0404

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

src/Microsoft.DotNet.Interactive.Tests/LanguageServices/HoverTextTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public async Task hover_request_returns_expected_result(Language language, strin
6666
}
6767

6868
[Theory]
69-
[InlineData("#!s$$et --value", "Sets a value in the current kernel")]
70-
[InlineData("#!set --valu$$e", "The value to be set")]
71-
[InlineData("#!connect sign$$alr --kernel-name blah", "Connects to a kernel using SignalR")]
69+
[InlineData("#!s$$et --value", "Sets a value in the current kernel*--name*--value*")]
70+
[InlineData("#!set --valu$$e", "The value to be set*")]
71+
[InlineData("#!connect sign$$alr --kernel-name blah", "Connects to a kernel using SignalR*")]
7272
public async Task hover_request_returns_expected_result_for_magic_commands(
7373
string markupCode,
7474
string expectedContent)
@@ -89,7 +89,7 @@ public async Task hover_request_returns_expected_result_for_magic_commands(
8989
.Which
9090
.Value
9191
.Should()
92-
.Contain(expectedContent);
92+
.Match(expectedContent);
9393
}
9494

9595
[Theory]

src/Microsoft.DotNet.Interactive/Kernel.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reactive.Disposables;
99
using System.Reactive.Subjects;
1010
using System.Runtime.CompilerServices;
11+
using System.Text;
1112
using System.Text.Json;
1213
using System.Threading;
1314
using System.Threading.Tasks;
@@ -24,6 +25,7 @@
2425
using static Pocket.Logger<Microsoft.DotNet.Interactive.Kernel>;
2526
using CompositeDisposable = System.Reactive.Disposables.CompositeDisposable;
2627
using Disposable = System.Reactive.Disposables.Disposable;
28+
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;
2729

2830
namespace Microsoft.DotNet.Interactive;
2931

@@ -771,13 +773,14 @@ private Task PublishDirectiveHoverTextAsync(
771773
case DirectiveNameNode { Parent: DirectiveSubcommandNode subcommandNode }:
772774
if (subcommandNode.TryGetSubcommand(out var subcommandDirective))
773775
{
774-
hoverText = subcommandDirective.Description;
776+
hoverText = BuildHoverText(subcommandDirective);
775777
}
776778

777779
break;
778780

779781
case DirectiveNameNode _:
780-
hoverText = directive.Description;
782+
hoverText = BuildHoverText(directive);
783+
781784
break;
782785

783786
case DirectiveParameterNameNode directiveParameterNameNode:
@@ -795,18 +798,63 @@ private Task PublishDirectiveHoverTextAsync(
795798
var linePosition = new LinePosition(command.LinePosition.Line, command.LinePosition.Character);
796799

797800
var linePositionSpan = new LinePositionSpan(
798-
linePosition,
801+
linePosition,
799802
linePosition);
800803

801804
context.Publish(
802805
new HoverTextProduced(
803806
command,
804807
[new FormattedValue("text/markdown", hoverText)],
805-
linePositionSpan ));
808+
linePositionSpan));
806809
}
807810
}
808811

809812
return Task.CompletedTask;
813+
814+
static string BuildHoverText(KernelDirective directive)
815+
{
816+
var sb = new StringBuilder();
817+
818+
sb.AppendLine(directive.Description);
819+
820+
if (directive.Parameters.Any())
821+
{
822+
sb.AppendLine();
823+
824+
sb.AppendLine("| <span>Parameter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> | Description |");
825+
sb.AppendLine("| :---- | :---- |");
826+
827+
foreach (var parameter in directive.Parameters.OrderByDescending(p => p.Required).ThenBy(p => p.Name))
828+
{
829+
WriteParameterRow(sb, parameter);
830+
}
831+
}
832+
833+
return sb.ToString();
834+
}
835+
836+
static void WriteParameterRow(StringBuilder sb, KernelDirectiveParameter parameter)
837+
{
838+
sb.Append("|");
839+
840+
sb.Append("*");
841+
if (parameter.Required)
842+
{
843+
sb.Append("*");
844+
}
845+
sb.Append(parameter.Name);
846+
sb.Append("*");
847+
if (parameter.Required)
848+
{
849+
sb.Append("*");
850+
}
851+
852+
sb.Append("|");
853+
854+
sb.Append(parameter.Description);
855+
856+
sb.AppendLine("|");
857+
}
810858
}
811859

812860
private void TrySetHandler(

0 commit comments

Comments
 (0)