/// <summary> /// Given a given snippets collection, constructs a new magic command /// that queries callables defined in that snippets collection. /// </summary> public LsMagicMagic(IMagicSymbolResolver resolver, IExecutionEngine engine) : base( "lsmagic", new Documentation { Summary = "Returns a list of all currently available magic commands.", Description = @" This magic command lists all of the magic commands available in the IQ# kernel, as well as those defined in any packages that have been loaded in the current session via the [`%package` magic command](https://docs.microsoft.com/qsharp/api/iqsharp-magic/package). ".Dedent(), Examples = new [] { @" Display the list of available magic commands: ``` In []: %lsmagic Out[]: <detailed list of all available magic commands> ``` ".Dedent(), } }) { this.resolver = resolver; (engine as IQSharpEngine).RegisterDisplayEncoder(new MagicSymbolSummariesToHtmlEncoder()); (engine as IQSharpEngine).RegisterDisplayEncoder(new MagicSymbolSummariesToTextEncoder()); }
/// <summary> /// Given a given snippets collection, constructs a new magic command /// that queries callables defined in that snippets collection. /// </summary> public LsMagicMagic(IMagicSymbolResolver resolver, IExecutionEngine engine, ILogger <LsMagicMagic> logger) : base( "lsmagic", new Microsoft.Jupyter.Core.Documentation { Summary = "Returns a list of all currently available magic commands.", Description = $@" This magic command lists all of the magic commands available in the IQ# kernel, as well as those defined in any packages that have been loaded in the current session via the [`%package` magic command]({KnownUris.ReferenceForMagicCommand("package")}). ".Dedent(), Examples = new [] { @" Display the list of available magic commands: ``` In []: %lsmagic Out[]: <detailed list of all available magic commands> ``` ".Dedent(), } }, logger) { this.resolver = resolver; if (engine is IQSharpEngine iQSharpEngine) { iQSharpEngine.RegisterDisplayEncoder(new MagicSymbolSummariesToHtmlEncoder()); iQSharpEngine.RegisterDisplayEncoder(new MagicSymbolSummariesToTextEncoder()); } else { throw new Exception($"Expected execution engine to be an IQ# engine, but was {engine.GetType()}."); } }
/// <summary> /// The main constructor. It expects an `ISnippets` instance that takes care /// of compiling and keeping track of the code Snippets provided by users. /// </summary> public IQSharpEngine( IShellServer shell, IOptions <KernelContext> context, ILogger <IQSharpEngine> logger, IServiceProvider services, IConfigurationSource configurationSource, PerformanceMonitor performanceMonitor, IShellRouter shellRouter, IEventService eventService, IMagicSymbolResolver magicSymbolResolver, IReferences references ) : base(shell, shellRouter, context, logger, services) { this.performanceMonitor = performanceMonitor; performanceMonitor.Start(); this.Snippets = services.GetService <ISnippets>(); this.SymbolsResolver = services.GetService <ISymbolResolver>(); this.MagicResolver = magicSymbolResolver; this.Workspace = services.GetService <IWorkspace>(); RegisterDisplayEncoder(new IQSharpSymbolToHtmlResultEncoder()); RegisterDisplayEncoder(new IQSharpSymbolToTextResultEncoder()); RegisterDisplayEncoder(new TaskStatusToTextEncoder()); RegisterDisplayEncoder(new StateVectorToHtmlResultEncoder(configurationSource)); RegisterDisplayEncoder(new StateVectorToTextResultEncoder(configurationSource)); RegisterDisplayEncoder(new DataTableToHtmlEncoder()); RegisterDisplayEncoder(new DataTableToTextEncoder()); RegisterDisplayEncoder(new DisplayableExceptionToHtmlEncoder()); RegisterDisplayEncoder(new DisplayableExceptionToTextEncoder()); RegisterDisplayEncoder(new DisplayableHtmlElementEncoder()); RegisterJsonEncoder( JsonConverters.AllConverters .Concat(AzureClient.JsonConverters.AllConverters) .ToArray()); RegisterSymbolResolver(this.SymbolsResolver); RegisterSymbolResolver(this.MagicResolver); RegisterPackageLoadedEvent(services, logger, references); // Handle new shell messages. shellRouter.RegisterHandlers <IQSharpEngine>(); // Report performance after completing startup. performanceMonitor.Report(); logger.LogInformation( "IQ# engine started successfully as process {Process}.", Process.GetCurrentProcess().Id ); eventService?.TriggerServiceInitialized <IExecutionEngine>(this); }
/// <summary> /// Given a given snippets collection, constructs a new magic command /// that queries callables defined in that snippets collection. /// </summary> public LsMagicMagic(IMagicSymbolResolver resolver, IExecutionEngine engine) : base( "lsmagic", new Documentation { Summary = "Returns a list of all currently available magic commands." }) { this.resolver = resolver; (engine as IQSharpEngine).RegisterDisplayEncoder(new MagicSymbolSummariesToHtmlEncoder()); (engine as IQSharpEngine).RegisterDisplayEncoder(new MagicSymbolSummariesToTextEncoder()); }