Esempio n. 1
0
        private async Task LoadFromAssembly(
            FileInfo assemblyFile,
            IKernel kernel,
            KernelInvocationContext context)
        {
            if (assemblyFile == null)
            {
                throw new ArgumentNullException(nameof(assemblyFile));
            }

            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            if (!assemblyFile.Exists)
            {
                throw new ArgumentException($"File {assemblyFile.FullName} doesn't exist", nameof(assemblyFile));
            }

            bool loadExtensions;

            lock (_lock)
            {
                loadExtensions = _loadedAssemblies.Add(AssemblyName.GetAssemblyName(assemblyFile.FullName));
            }

            if (loadExtensions)
            {
                var assembly       = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyFile.FullName);
                var extensionTypes = assembly
                                     .ExportedTypes
                                     .Where(t => t.CanBeInstantiated() && typeof(IKernelExtension).IsAssignableFrom(t))
                                     .ToArray();

                foreach (var extensionType in extensionTypes)
                {
                    var extension = (IKernelExtension)Activator.CreateInstance(extensionType);
                    var display   = Guid.NewGuid().ToString("N");
                    context.Publish(new DisplayedValueProduced(
                                        $"Loading kernel extension {extensionType.Name} from assembly {assemblyFile.FullName}",
                                        context.Command, valueId: display));
                    try
                    {
                        await extension.OnLoadAsync(kernel);

                        context.Publish(new DisplayedValueUpdated(
                                            $"Loaded kernel extension {extensionType.Name} from assembly {assemblyFile.FullName}",
                                            display, context.Command));
                    }
                    catch (Exception e)
                    {
                        context.Publish(new ErrorProduced(
                                            $"Failure loading kernel extension {extensionType.Name} from assembly {assemblyFile.FullName}",
                                            context.Command));
                        context.Fail(new KernelExtensionLoadException(e));
                    }
                }
            }
        }
Esempio n. 2
0
        public async Task LoadFromAssembliesInDirectory(
            DirectoryInfo directory,
            IKernel kernel,
            KernelInvocationContext context)
        {
            if (directory.Exists)
            {
                var extensionDlls = directory
                                    .GetFiles("*.dll", SearchOption.TopDirectoryOnly)
                                    .ToList();

                if (extensionDlls.Count > 0)
                {
                    context.Publish(new DisplayedValueProduced(
                                        $"Loading kernel extensions in directory {directory.FullName}", context.Command,
                                        valueId: Guid.NewGuid().ToString("N")));

                    foreach (var extensionDll in extensionDlls)
                    {
                        await LoadFromAssembly(
                            extensionDll,
                            kernel,
                            context);
                    }

                    context.Publish(new DisplayedValueUpdated(
                                        $"Loaded kernel extensions in directory {directory.FullName}", Guid.NewGuid().ToString("N"), context.Command));
                }
            }
        }
Esempio n. 3
0
        public async Task HandleAsync(
            RequestCompletions command,
            KernelInvocationContext context)
        {
            var completionRequestReceived = new CompletionRequestReceived(command);

            context.Publish(completionRequestReceived);

            var completionList =
                await GetCompletionList(
                    command.Code,
                    SourceUtilities.GetCursorOffsetFromPosition(command.Code, command.LinePosition));

            context.Publish(new CompletionsProduced(completionList, command));
        }
Esempio n. 4
0
        private async Task HandleRequestCompletion(
            RequestCompletion requestCompletion,
            KernelInvocationContext context)
        {
            var completionRequestReceived = new CompletionRequestReceived(requestCompletion);

            context.Publish(completionRequestReceived);

            var completionList =
                await GetCompletionList(
                    requestCompletion.Code,
                    requestCompletion.CursorPosition);

            context.Publish(new CompletionRequestCompleted(completionList, requestCompletion));
        }
Esempio n. 5
0
        public async Task HandleAsync(
            RequestCompletion requestCompletion,
            KernelInvocationContext context)
        {
            var completionRequestReceived = new CompletionRequestReceived(requestCompletion);

            context.Publish(completionRequestReceived);

            var completionList =
                await GetCompletionList(
                    requestCompletion.Code,
                    SourceUtilities.GetCursorOffsetFromPosition(requestCompletion.Code, requestCompletion.Position));

            context.Publish(new CompletionRequestCompleted(completionList, requestCompletion));
        }
        public async Task HandleAsync(RequestHoverText command, KernelInvocationContext context)
        {
            using var _ = new GCPressure(1024 * 1024);

            var document = _workspace.UpdateWorkingDocument(command.Code);
            var text     = await document.GetTextAsync();

            var cursorPosition = text.Lines.GetPosition(command.LinePosition);
            var service        = QuickInfoService.GetService(document);
            var info           = await service.GetQuickInfoAsync(document, cursorPosition);

            if (info == null)
            {
                return;
            }

            var scriptSpanStart      = text.Lines.GetLinePosition(0);
            var linePosSpan          = text.Lines.GetLinePositionSpan(info.Span);
            var correctedLinePosSpan = linePosSpan.SubtractLineOffset(scriptSpanStart);

            context.Publish(
                new HoverTextProduced(
                    command,
                    new[]
            {
                new FormattedValue("text/markdown", info.ToMarkdownString())
            },
                    correctedLinePosSpan));
        }
Esempio n. 7
0
        public void Update(object updatedValue)
        {
            var formatted = new FormattedValue(
                _mimeType,
                updatedValue.ToDisplayString(_mimeType));

            _context.Publish(new DisplayedValueUpdated(updatedValue, _displayId, _context.Command, new[] { formatted }));
        }
Esempio n. 8
0
        public override Task InvokeAsync(KernelInvocationContext context)
        {
            if (context.HandlingKernel is ISupportGetValue supportGetValuesKernel)
            {
                context.Publish(new ValueInfosProduced(supportGetValuesKernel.GetValueInfos(), this));
                return(Task.CompletedTask);
            }

            throw new InvalidOperationException($"Kernel {context.HandlingKernel.Name} doesn't support command {nameof(RequestValueInfos)}");
        }
Esempio n. 9
0
        public async Task HandleAsync(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            // Acknowledge that we received the request.
            context.Publish(new CodeSubmissionReceived(submitCode));

            string code = submitCode.Code;

            // Test is the code we got is actually able to run.
            if (IsCompleteSubmission(code, out ParseError[] parseErrors))
Esempio n. 10
0
        public override Task InvokeAsync(KernelInvocationContext context)
        {
            context.Publish(
                new DisplayedValueProduced(
                    null,
                    this,
                    formattedValues: new[] { FormattedValue },
                    valueId: ValueId));

            return(Task.CompletedTask);
        }
Esempio n. 11
0
 internal static void PublishStreamRecord(
     object output,
     KernelInvocationContext context,
     IKernelCommand command)
 {
     context.Publish(
         new DisplayedValueProduced(
             output,
             command,
             FormattedValue.FromObject(output)));
 }
Esempio n. 12
0
        public async Task HandleAsync(
            RequestDiagnostics command,
            KernelInvocationContext context)
        {
            var document      = _workspace.UpdateWorkingDocument(command.Code);
            var semanticModel = await document.GetSemanticModelAsync();

            var diagnostics = semanticModel.GetDiagnostics();

            context.Publish(new DiagnosticsProduced(diagnostics.Select(Diagnostic.FromCodeAnalysisDiagnostic), command));
        }
Esempio n. 13
0
        protected override async Task HandleSubmitCode(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            // Acknowledge that we received the request.
            context.Publish(new CodeSubmissionReceived(submitCode));

            string     code = submitCode.Code;
            PowerShell pwsh = _lazyPwsh.Value;

            // Test is the code we got is actually able to run.
            if (IsCompleteSubmission(code, out ParseError[] parseErrors))
Esempio n. 14
0
        public override Task InvokeAsync(KernelInvocationContext context)
        {
            context.Publish(
                new DisplayedValueUpdated(
                    Value,
                    valueId: ValueId,
                    command: this,
                    formattedValues: new[] { FormattedValue }
                    ));

            return(Task.CompletedTask);
        }
        public override Task InvokeAsync(KernelInvocationContext context)
        {
            var currentWorkingDir = Directory.GetCurrentDirectory();

            if (!currentWorkingDir.Equals(WorkingDirectory, StringComparison.Ordinal))
            {
                Directory.SetCurrentDirectory(WorkingDirectory);

                context.Publish(new WorkingDirectoryChanged(WorkingDirectory, this));
            }

            return(Handler(this, context));
        }
Esempio n. 16
0
        public async Task HandleAsync(OpenProject command, KernelInvocationContext context)
        {
            var package = await CreateConsoleWorkspacePackage();

            _workspaceServer = new RoslynWorkspaceServer(package);

            var extractor = new BufferFromRegionExtractor();

            _workspace = extractor.Extract(command.Project.Files.Select(f => new Protocol.File(f.RelativeFilePath, f.Content)).ToArray());

            context.Publish(new ProjectOpened(command, _workspace.Buffers.GroupBy(b => b.Id.FileName)
                                              .OrderBy(g => g.Key).Select(g => new ProjectItem(g.Key, g.Select(r => r.Id.RegionName).Where(r => r != null).OrderBy(r => r).ToList())).ToList()));
        }
Esempio n. 17
0
        public void Update(object updatedValue)
        {
            var formatted = new FormattedValue(
                _mimeType,
                updatedValue.ToDisplayString(_mimeType));

            if (KernelInvocationContext.Current?.Command is SubmitCode)
            {
                _context = KernelInvocationContext.Current;
            }

            _context.Publish(new DisplayedValueUpdated(updatedValue, _displayId, _context.Command, new[] { formatted }));
        }
Esempio n. 18
0
        private Task HandleCancelCurrentCommand(
            CancelCurrentCommand cancelCurrentCommand,
            KernelInvocationContext context)
        {
            var reply = new CurrentCommandCancelled(cancelCurrentCommand);

            lock (_cancellationSourceLock)
            {
                _cancellationSource.Cancel();
                _cancellationSource = new CancellationTokenSource();
            }

            context.Publish(reply);

            return(Task.CompletedTask);
        }
Esempio n. 19
0
        private void PublishError(
            string error,
            KernelInvocationContext context,
            IKernelCommand command)
        {
            var formattedValues = new List <FormattedValue>
            {
                new FormattedValue(
                    PlainTextFormatter.MimeType, error)
            };

            context.Publish(
                new StandardErrorValueProduced(
                    error,
                    command,
                    formattedValues));
        }
Esempio n. 20
0
        private void PublishOutput(
            string output,
            KernelInvocationContext context,
            IKernelCommand command)
        {
            var formattedValues = new List <FormattedValue>
            {
                new FormattedValue(
                    PlainTextFormatter.MimeType, output)
            };

            context.Publish(
                new StandardOutputValueProduced(
                    output,
                    command,
                    formattedValues));
        }
Esempio n. 21
0
        private void Inspect(OptimizationLevel configuration, SourceCodeKind kind, Platform platform, KernelInvocationContext context)
        {
            if (!(context.Command is SubmitCode))
            {
                return;
            }

            var command = context.Command as SubmitCode;

            // TODO: Is there a proper way of cleaning up code from the magic commands?
            var code = Regex.Replace(command.Code, $"#!{INSPECT_COMMAND}(.*)", "");

            var options = new InspectionOptions
            {
                CompilationLanguage   = InspectionOptions.LanguageVersion.CSHARP_PREVIEW,
                DecompilationLanguage = InspectionOptions.LanguageVersion.CSHARP_PREVIEW,
                Kind = kind,
                OptimizationLevel = configuration,
                Platform          = Platform.AnyCpu
            };

            var inspect = Inspector.Inspector.Create(options);

            var result = inspect.Compile(code);

            if (!result.IsSuccess)
            {
                var diagnostics = string.Join('\n', result.CompilationDiagnostics);
                context.Fail(message: $"Uh-oh, something went wrong:\n {diagnostics}");
                return;
            }

            var htmlResults = RenderResultInTabs(result.CSharpDecompilation, result.ILDecompilation, result.JitDecompilation);

            context.Publish(
                new DisplayedValueProduced(
                    htmlResults,
                    context.Command,
                    new[]
            {
                new FormattedValue("text/html", htmlResults.ToString())
            }));
        }
Esempio n. 22
0
        protected override Task HandleSubmitCode(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            CancellationTokenSource cancellationSource;

            lock (_cancellationSourceLock)
            {
                cancellationSource = _cancellationSource;
            }

            // Acknowledge that we received the request.
            var codeSubmissionReceived = new CodeSubmissionReceived(submitCode);

            context.Publish(codeSubmissionReceived);

            // Test is the code we got is actually able to run.
            var code = submitCode.Code;

            if (IsCompleteSubmission(code, out ParseError[] parseErrors))
Esempio n. 23
0
        public async Task HandleAsync(SubmitCode submitCode, KernelInvocationContext context)
        {
            var codeSubmissionReceived = new CodeSubmissionReceived(submitCode);

            context.Publish(codeSubmissionReceived);

            var code       = submitCode.Code;
            var isComplete = await IsCompleteSubmissionAsync(submitCode.Code);

            if (isComplete)
            {
                context.Publish(new CompleteCodeSubmissionReceived(submitCode));
            }
            else
            {
                context.Publish(new IncompleteCodeSubmissionReceived(submitCode));
            }

            if (submitCode.SubmissionType == SubmissionType.Diagnose)
            {
                return;
            }

            Exception exception = null;
            string    message   = null;

            if (!context.CancellationToken.IsCancellationRequested)
            {
                try
                {
                    await RunAsync(
                        code,
                        context.CancellationToken,
                        e =>
                    {
                        exception = e;
                        return(true);
                    });
                }
                catch (CompilationErrorException cpe)
                {
                    exception = new CodeSubmissionCompilationErrorException(cpe);
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }

            if (!context.CancellationToken.IsCancellationRequested)
            {
                var diagnostics = ImmutableArray <CodeAnalysis.Diagnostic> .Empty;

                // Check for a compilation failure
                if (exception is CodeSubmissionCompilationErrorException compilationError &&
                    compilationError.InnerException is CompilationErrorException innerCompilationException)
                {
                    diagnostics = innerCompilationException.Diagnostics;
                    // In the case of an error the diagnostics get attached to both the
                    // DiagnosticsProduced and CommandFailed events.
                    message =
                        string.Join(Environment.NewLine,
                                    innerCompilationException.Diagnostics.Select(d => d.ToString()) ?? Enumerable.Empty <string>());
                }
                else
                {
                    diagnostics = ScriptState?.Script.GetCompilation().GetDiagnostics() ?? ImmutableArray <CodeAnalysis.Diagnostic> .Empty;
                }

                // Publish the compilation diagnostics. This doesn't include the exception.
                var kernelDiagnostics = diagnostics.Select(Diagnostic.FromCodeAnalysisDiagnostic).ToImmutableArray();

                var formattedDiagnostics =
                    diagnostics
                    .Select(d => d.ToString())
                    .Select(text => new FormattedValue(PlainTextFormatter.MimeType, text))
                    .ToImmutableArray();

                context.Publish(new DiagnosticsProduced(kernelDiagnostics, submitCode, formattedDiagnostics));

                // Report the compilation failure or exception
                if (exception != null)
                {
                    context.Fail(exception, message);
                }
                else
                {
                    if (ScriptState != null && HasReturnValue)
                    {
                        var formattedValues = FormattedValue.FromObject(ScriptState.ReturnValue);
                        context.Publish(
                            new ReturnValueProduced(
                                ScriptState.ReturnValue,
                                submitCode,
                                formattedValues));
                    }
                }
            }
Esempio n. 24
0
        protected override async Task HandleSubmitCode(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            var codeSubmissionReceived = new CodeSubmissionReceived(submitCode);

            context.Publish(codeSubmissionReceived);

            var code       = submitCode.Code;
            var isComplete = await IsCompleteSubmissionAsync(submitCode.Code);

            if (isComplete)
            {
                context.Publish(new CompleteCodeSubmissionReceived(submitCode));
            }
            else
            {
                context.Publish(new IncompleteCodeSubmissionReceived(submitCode));
            }

            if (submitCode.SubmissionType == SubmissionType.Diagnose)
            {
                return;
            }

            Exception exception = null;

            if (!context.CancellationToken.IsCancellationRequested)
            {
                ScriptOptions = ScriptOptions.WithMetadataResolver(
                    ScriptMetadataResolver.Default.WithBaseDirectory(
                        Directory.GetCurrentDirectory()));

                try
                {
                    if (ScriptState == null)
                    {
                        ScriptState = await CSharpScript.RunAsync(
                            code,
                            ScriptOptions,
                            cancellationToken : context.CancellationToken)
                                      .UntilCancelled(context.CancellationToken);
                    }
                    else
                    {
                        ScriptState = await ScriptState.ContinueWithAsync(
                            code,
                            ScriptOptions,
                            catchException : e =>
                        {
                            exception = e;
                            return(true);
                        },
                            cancellationToken : context.CancellationToken)
                                      .UntilCancelled(context.CancellationToken);
                    }
                }
                catch (CompilationErrorException cpe)
                {
                    exception = new CodeSubmissionCompilationErrorException(cpe);
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }

            if (!context.CancellationToken.IsCancellationRequested)
            {
                if (exception != null)
                {
                    string message = null;

                    if (exception is CodeSubmissionCompilationErrorException compilationError)
                    {
                        message =
                            string.Join(Environment.NewLine,
                                        (compilationError.InnerException as CompilationErrorException)?.Diagnostics.Select(d => d.ToString()) ?? Enumerable.Empty <string>());
                    }

                    context.Fail(exception, message);
                }
                else
                {
                    if (ScriptState != null && HasReturnValue)
                    {
                        var formattedValues = FormattedValue.FromObject(ScriptState.ReturnValue);
                        context.Publish(
                            new ReturnValueProduced(
                                ScriptState.ReturnValue,
                                submitCode,
                                formattedValues));
                    }
                }
            }
            else
            {
                context.Fail(null, "Command cancelled");
            }
        }
Esempio n. 25
0
        public static void PublishHoverPlainTextResponse(this KernelInvocationContext context, RequestHoverText command, string content, LinePositionSpan linePositionSpan)
        {
            var response = new HoverPlainTextProduced(command, content, linePositionSpan);

            context.Publish(response);
        }
Esempio n. 26
0
        private async Task HandleSubmitCode(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            CancellationTokenSource cancellationSource;

            lock (_cancellationSourceLock)
            {
                cancellationSource = _cancellationSource;
            }

            var codeSubmissionReceived = new CodeSubmissionReceived(submitCode);

            context.Publish(codeSubmissionReceived);

            var code       = submitCode.Code;
            var isComplete = await IsCompleteSubmissionAsync(submitCode.Code);

            if (isComplete)
            {
                context.Publish(new CompleteCodeSubmissionReceived(submitCode));
            }
            else
            {
                context.Publish(new IncompleteCodeSubmissionReceived(submitCode));
            }

            if (submitCode.SubmissionType == SubmissionType.Diagnose)
            {
                return;
            }

            Exception exception = null;

            using var console = await ConsoleOutput.Capture();

            using (console.SubscribeToStandardOutput(std => PublishOutput(std, context, submitCode)))
                using (console.SubscribeToStandardError(std => PublishError(std, context, submitCode)))
                {
                    if (!cancellationSource.IsCancellationRequested)
                    {
                        try
                        {
                            if (ScriptState == null)
                            {
                                ScriptState = await CSharpScript.RunAsync(
                                    code,
                                    ScriptOptions,
                                    cancellationToken : cancellationSource.Token)
                                              .UntilCancelled(cancellationSource.Token);
                            }
                            else
                            {
                                ScriptState = await ScriptState.ContinueWithAsync(
                                    code,
                                    ScriptOptions,
                                    catchException :  e =>
                                {
                                    exception = e;
                                    return(true);
                                },
                                    cancellationToken : cancellationSource.Token)
                                              .UntilCancelled(cancellationSource.Token);
                            }
                        }
                        catch (CompilationErrorException cpe)
                        {
                            exception = new CodeSubmissionCompilationErrorException(cpe);
                        }
                        catch (Exception e)
                        {
                            exception = e;
                        }
                    }
                }

            if (!cancellationSource.IsCancellationRequested)
            {
                if (exception != null)
                {
                    string message = null;

                    if (exception is CodeSubmissionCompilationErrorException compilationError)
                    {
                        message =
                            string.Join(Environment.NewLine,
                                        (compilationError.InnerException as CompilationErrorException)?.Diagnostics.Select(d => d.ToString()) ?? Enumerable.Empty <string>());
                    }

                    context.Publish(new CommandFailed(exception, submitCode, message));
                }
                else
                {
                    if (ScriptState != null && HasReturnValue)
                    {
                        var formattedValues = FormattedValue.FromObject(ScriptState.ReturnValue);
                        context.Publish(
                            new ReturnValueProduced(
                                ScriptState.ReturnValue,
                                submitCode,
                                formattedValues));
                    }

                    context.Complete();
                }
            }
            else
            {
                context.Publish(new CommandFailed(null, submitCode, "Command cancelled"));
            }
        }
Esempio n. 27
0
 public override Task InvokeAsync(KernelInvocationContext context)
 {
     Directory.SetCurrentDirectory(WorkingDirectory.FullName);
     context.Publish(new WorkingDirectoryChanged(WorkingDirectory, this));
     return(Task.CompletedTask);
 }
Esempio n. 28
0
        protected override async Task HandleSubmitCode(
            SubmitCode submitCode,
            KernelInvocationContext context)
        {
            var codeSubmissionReceived = new CodeSubmissionReceived(submitCode);

            context.Publish(codeSubmissionReceived);

            var code       = submitCode.Code;
            var isComplete = await IsCompleteSubmissionAsync(submitCode.Code);

            if (isComplete)
            {
                context.Publish(new CompleteCodeSubmissionReceived(submitCode));
            }
            else
            {
                context.Publish(new IncompleteCodeSubmissionReceived(submitCode));
            }

            if (submitCode.SubmissionType == SubmissionType.Diagnose)
            {
                return;
            }

            Exception exception = null;

            if (!context.CancellationToken.IsCancellationRequested)
            {
                try
                {
                    await RunAsync(
                        code,
                        context.CancellationToken,
                        e =>
                    {
                        exception = e;
                        return(true);
                    });
                }
                catch (CompilationErrorException cpe)
                {
                    exception = new CodeSubmissionCompilationErrorException(cpe);
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }

            if (!context.CancellationToken.IsCancellationRequested)
            {
                if (exception != null)
                {
                    string message = null;

                    if (exception is CodeSubmissionCompilationErrorException compilationError)
                    {
                        message =
                            string.Join(Environment.NewLine,
                                        (compilationError.InnerException as CompilationErrorException)?.Diagnostics.Select(d => d.ToString()) ?? Enumerable.Empty <string>());
                    }

                    context.Fail(exception, message);
                }
                else
                {
                    if (ScriptState != null && HasReturnValue)
                    {
                        var formattedValues = FormattedValue.FromObject(ScriptState.ReturnValue);
                        context.Publish(
                            new ReturnValueProduced(
                                ScriptState.ReturnValue,
                                submitCode,
                                formattedValues));
                    }
                }
            }
            else
            {
                context.Fail(null, "Command cancelled");
            }
        }
        public static void PublishHoverTextResponse(this KernelInvocationContext context, RequestHoverText command, IReadOnlyCollection <FormattedValue> content, LinePositionSpan?linePositionSpan = null)
        {
            var response = new HoverTextProduced(command, content, linePositionSpan);

            context.Publish(response);
        }
        private async Task LoadFromAssembly(
            FileInfo assemblyFile,
            Kernel kernel,
            KernelInvocationContext context)
        {
            if (assemblyFile is null)
            {
                throw new ArgumentNullException(nameof(assemblyFile));
            }

            if (kernel is null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            if (!assemblyFile.Exists)
            {
                throw new ArgumentException($"File {assemblyFile.FullName} doesn't exist", nameof(assemblyFile));
            }

            bool loadExtensions;

            lock (_lock)
            {
                loadExtensions = _loadedAssemblies.Add(AssemblyName.GetAssemblyName(assemblyFile.FullName));
            }

            if (loadExtensions)
            {
                var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyFile.FullName);

                var extensionTypes = assembly
                                     .ExportedTypes
                                     .Where(t => t.CanBeInstantiated() && typeof(IKernelExtension).IsAssignableFrom(t))
                                     .ToArray();

                if (extensionTypes.Any())
                {
                    context.DisplayAs($"Loading extensions from `{assemblyFile.Name}`", "text/markdown");
                }

                foreach (var extensionType in extensionTypes)
                {
                    var extension = (IKernelExtension)Activator.CreateInstance(extensionType);

                    try
                    {
                        await extension.OnLoadAsync(kernel);

                        context.Publish(new KernelExtensionLoaded(extension, context.Command));
                    }
                    catch (Exception e)
                    {
                        context.Publish(new ErrorProduced(
                                            $"Failed to load kernel extension \"{extensionType.Name}\" from assembly {assemblyFile.FullName}",
                                            context.Command));

                        context.Fail(context.Command, new KernelExtensionLoadException(e));
                    }
                }
            }
        }