88using System . Reactive . Disposables ;
99using System . Reactive . Subjects ;
1010using System . Runtime . CompilerServices ;
11+ using System . Text ;
1112using System . Text . Json ;
1213using System . Threading ;
1314using System . Threading . Tasks ;
2425using static Pocket . Logger < Microsoft . DotNet . Interactive . Kernel > ;
2526using CompositeDisposable = System . Reactive . Disposables . CompositeDisposable ;
2627using Disposable = System . Reactive . Disposables . Disposable ;
28+ using static Microsoft . DotNet . Interactive . Formatting . PocketViewTags ;
2729
2830namespace 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 </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