deviousasti / fsharp-worksheet

A spreadsheet-like interactive evaluator for F#
https://asti.dynz.net/post/fsharp-worksheet/
50 stars 0 forks source link

Support for nuget? #3

Open srid opened 3 years ago

srid commented 3 years ago

fsx scripts allow specifying deps,

#r "nuget: Feather.Build, 0.1.0-alpha-1"

But fsw errors out:

#r "nuget: Feather.Build, 0.1.0-alpha-1"
FSharp.Compiler.Interactive.Shell+FsiCompilationException: Operation could not be completed due to earlier error
Package manager key 'nuget' was not registered in [C:\Users\srid\.dotnet\tools\.store\fsharp.worksheet\0.2.0\fsharp.worksheet\0.2.0\tools\netcoreapp3.0\any; C:\Users\srid\.dotnet\tools\.store\fsharp.worksheet\0.2.0\fsharp.worksheet\0.2.0\tools\netcoreapp3.0\any\], []. Currently registered:
[...]
Stopped due to error
FSharp.Compiler.Interactive.Shell+FsiCompilationException: Operation could not be completed due to earlier error
The value, namespace, type or module 'Feather' is not defined.
srid commented 3 years ago

Repro: https://github.com/srid/Feather/blob/master/example/example.fsx (might have to change -2 to -1 to get a working version; cf. https://github.com/dotnet/fsharp/issues/3178#issuecomment-811361363)

deviousasti commented 3 years ago

This is because the Package manager is currently dependency injected. And I'm not entirely sure if there will be license issues if I include it.

You can unzip this to the install directory to enable it. FSharp.DependencyManager.zip

I'll try to ship this as part of the nuget package.

srid commented 3 years ago

You can unzip this to the install directory to enable it.

What's the install directory?

deviousasti commented 3 years ago

Usually C:\Users\<user>\.dotnet\tools. Hold on, I'll just patch this,

deviousasti commented 3 years ago

Please try it now (uninstall.ps1 followed by install.ps1) - FParsec does work for me with "#r nuget".

srid commented 3 years ago

This eliminated the first error, but the "Stopped due to error" is still present.

image

You can reproduce this using cd example; fsw example.fsx in the repo I linked above after applying this patch,

diff --git a/example/example.fsx b/example/example.fsx
index c274fbe..a216579 100755
--- a/example/example.fsx
+++ b/example/example.fsx
@@ -1,5 +1,5 @@
 #!/usr/bin/env -S dotnet fsi
-#r "nuget: Feather.Build, 0.1.0-alpha-2"
+#r "nuget: Feather.Build, 0.1.0-alpha-1"
 // Workaround for https://github.com/dotnet/fsharp/issues/3178#issuecomment-811174453
 #r "nuget: Microsoft.Extensions.FileProviders.Physical, 6.0.0-preview.2.21154.6"
deviousasti commented 3 years ago

That's because the package only supports net5.0 and this is built for .net core 3.1. You could try changing the target version in global.json and attempt an install.

srid commented 3 years ago

I actually originally installed it by using net5.0 in global.json. Can't really get it to work.

deviousasti commented 3 years ago

Hi @srid, global.json is just the SDK version - you would also need to change the TFM in FsWorksheet to net5.0. I've updated both and pushed an update.

I've also added support for the fsi configuration object, but you should ideally use Environment.GetCommandLineArgs().

srid commented 3 years ago

Great, there is some progress. I don't see the aforementioned error anymore, but fsw (unlike dotnet fsi which succeeds) fails to resolve some dependencies:

image

Zaid-Ajaj commented 3 years ago

Great, there is some progress. I don't see the aforementioned error anymore, but fsw (unlike dotnet fsi which succeeds) fails to resolve some dependencies:

Could this because this tool not using lest F# compiler services? I see the one used here is 38.0.0 and latest is 39.0.0

deviousasti commented 3 years ago

It's not FCS. FCS 39 breaks a lot of things, so I've deferred upgrading until FCS 40 is out when the breaks are stabilized.

This is a classic assembly binding error. The build was currently using Control.Reactive 4.x, and your nuget package referred to Rx 5.x. So it couldn't late bind a different version of the assembly.

I've updated the package version, so it should work now. Ideally we shouldn't be depending on any other library, so fsw doesn't have any conflicts, but removing the dependency on Control.Reactive will make the code a bit ugly. Most of the usage is in Watch.fs.

If anyone's interested in redefining a few observable combinators let me know.