Skip to content

Opening namespace/module after referencing nuget package doesn't work on a kernel extension #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PawelStadnicki opened this issue Apr 27, 2021 · 3 comments
Labels
Area-Packages and Extensions Related to acquiring and using packages and extensions bug Something isn't working

Comments

@PawelStadnicki
Copy link

PawelStadnicki commented Apr 27, 2021

I have F# kernel extension in which (among other requirements) I want to reference nuget packages (to avoid doing it in the editor and disturbing users from proper value) AND open namespaces.

My OnLoadAsync method contains following code piece :

let code = 
    [
        "#r nuget:Feliz"
        "open Feliz"
    ] |> String.concat Environment.NewLine
    
    kernel.VisitSubkernelsAndSelf(
        function
        | :? FSharpKernel as fs  -> 

            fs.SendAsync(SubmitCode (code,"fsharp")) 
                        |> Async.AwaitTask 
                        |> Async.RunSynchronously
        | _ -> ()
    )

Package loads successfully but it fails upon opening namespaces/modules:

Error: input.fsx (2,6)-(2,11) typecheck error The namespace or module 'Feliz' is not defined.

Exactly the same code inserted into cell works fine:

r# nuget:Feliz
open Feliz

Is this kernel extension limitation/ by design ? I suspect rather that it is more kernel context operation involved that I may use in a wrong way

@jonsequitur
Copy link
Contributor

This code is intended to work. I debugged it and it looks like the submission parser is splitting this into two commands "#r nuget:Feliz" and "open Feliz" (which is expected) but then the second is incorrectly getting routed to the C# kernel. You should be able to work around this by sending each of these separately to the F# kernel.

(Unrelated, the .Wait() call makes me a little nervous. I don't think you should see a deadlock because we're not using a SynchronizationContext but I tend to avoid this as a matter of habit.)

@jonsequitur jonsequitur added the Area-Packages and Extensions Related to acquiring and using packages and extensions label Apr 27, 2021
@PawelStadnicki
Copy link
Author

PawelStadnicki commented Apr 27, 2021

You should be able to work around this by sending each of these separately to the F# kernel.

I've tried many variations, sending them separately, directly via F# kernel or by SubmitCode (code,"fsharp") with the same result

(Unrelated, the .Wait() call makes me a little nervous.

thanks, yes, there will my proper async handler, but first I wanted to test the results immediately as choosing valid async approach in F# is not that simple as in C# but as a matter of habit suggestion I corrected it into

fs.SendAsync(SubmitCode (code,"fsharp")) 
    |> Async.AwaitTask 
    |> Async.RunSynchronously

@PawelStadnicki
Copy link
Author

Closing as it seems to work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Packages and Extensions Related to acquiring and using packages and extensions bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants