ionide-vscode-fsharp
ionide-vscode-fsharp copied to clipboard
Feature Request: FSI: Send Line, prefix with "it"
I was practicing a demo and thought of a simple feature that I think could be discussed.
Basically, as I'm giving a demo of F#, I want to show the intermediate states of the data, a line at a time. It would be useful, if the code looks like this:
Seq.initInfinite (fun n -> n * 2)
|> Seq.map (fun n -> n * n)
|> Seq.filter(fun n -> n % 3 = 0)
|> Seq.take 5
|> Seq.map Some
|> Seq.chunkBySize 5
That this feature would, send current line, if it starts with pipe, prefix with "it" and move to the next line, so I can see all the steps one by one with out having to select two lines, then three, then four, ect.
Example results:
Seq.initInfinite (fun n -> n * 2)
- ;;
val it : seq<int> = seq [0; 2; 4; 6; ...]
> it |> Seq.map (fun n -> n * n)
- ;;
val it : seq<int> = seq [0; 4; 16; 36; ...]
> it |> Seq.filter(fun n -> n % 3 = 0)
- ;;
val it : seq<int> = seq [0; 36; 144; 324; ...]
> it |> Seq.take 5
- ;;
val it : seq<int> = seq [0; 36; 144; 324; ...]
> it |> Seq.map Some
- ;;
val it : seq<int option> = seq [Some 0; Some 36; Some 144; Some 324; ...]
> it |> Seq.chunkBySize 5
- ;;
val it : seq<int option []> =
seq [[|Some 0; Some 36; Some 144; Some 324; Some 576|]]
In addition to demos, this could be useful for debugging as well, both at runtime ("Why am I getting the wrong result here?") and at compile time ("Why is the type of this expression not what I expected it to be?). I've sometimes broken out my pipelines into a series of let
statements so that I could see their types in code lenses, but this feature would have also served my needs when I was getting a type error in a long pipeline.
But this just gave me an idea for another feature request: code lens on pipeline steps. I'll open a new issue to track that request.
My general problem with both suggestions is that it is not easy to implement correctly. It's fairly easy to do both features for such simple pipeline chains as your showing, but what if one of the functions in chain has it's own pipeline chain internally? What if we'll have multiple levels? I don't see easy way to make it robust enough, there is lot of edge cases that should be handled.
Maybe it could be done using FCS and manually going through AST. Something that may be worth investing... but not by me. I'd definitely accept PRs for any of those 2 features but it's not something of high priority for me personally.