Skip to content

Commit

Permalink
Merge pull request #3 from dawedawe/h_wo_q
Browse files Browse the repository at this point in the history
h on raw expressions
  • Loading branch information
dawedawe authored Jan 20, 2024
2 parents 1447b5d + 4791e90 commit cfe7079
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.0.0] - 2024-01-20

### Changed

* Made `h expr` just work without the need for quotation wrapping.

## [0.2.0] - 2024-01-16

### Fixed
Expand Down
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Fsih
====

Fsih provides you with the `h` and `H.H` functions, meant to be used in the F# REPL [fsi](https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/).
Fsih provides you with the `h` function, meant to be used in the F# REPL [fsi](https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/).
It's modeled after the `h` function in the Elixir [iex](https://hexdocs.pm/iex/1.16.0/IEx.html) REPL.

To use it, just start an fsi session with `dotnet fsi`.
Expand All @@ -11,9 +11,9 @@ Load the package and open the namespace:
open Fsih;;
```

Apply h to any expression wrapped in an FSharp [quotation](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/code-quotations) to get its documentation:
Apply h to any expression to get its documentation:
```fsharp
h <@ fst @>;;
h fst;;
```

```
Expand All @@ -31,24 +31,3 @@ fst ("first", 2) // Evaluates to "first"
Full name: Microsoft.FSharp.Core.Operators.fst
Assembly: FSharp.Core.dll
```

Or apply H.H to any expression directly to get its documentation:
```fsharp
H.H fst;;
```

```
Description:
Return the first element of a tuple, fst (a,b) = a.
Parameters:
- tuple: The input tuple.
Returns:
The first value.
Examples:
fst ("first", 2) // Evaluates to "first"
Full name: Microsoft.FSharp.Core.Operators.fst
Assembly: FSharp.Core.dll
```
14 changes: 7 additions & 7 deletions src/Fsih.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ let expressions =
[<Theory>]
[<MemberData(nameof (expressions))>]
let ``fetching and parsing docs works for expressions`` ((expr, fullName): (Expr * string)) =
let doc = tryGetDocumentation expr
let doc = Quoted.tryGetDocumentation expr

match doc with
| None -> Assert.False(true, sprintf "no docs for %s" fullName)
| Some d -> Assert.Equal(fullName, d.FullName)

[<Fact>]
let ``full info is as expected for Seq.splitInto`` () =
let doc = tryGetDocumentation <@ Seq.splitInto @>
let doc = Quoted.tryGetDocumentation <@ Seq.splitInto @>

match doc with
| Some { Summary = summary
Expand Down Expand Up @@ -88,7 +88,7 @@ let ``full info is as expected for Seq.splitInto`` () =

[<Fact>]
let ``returns is as expected for HashIdentity.FromFunctions`` () =
let doc = tryGetDocumentation <@ HashIdentity.FromFunctions @>
let doc = Quoted.tryGetDocumentation <@ HashIdentity.FromFunctions @>

match doc with
| Some { Returns = Some returns } ->
Expand All @@ -101,7 +101,7 @@ let ``returns is as expected for HashIdentity.FromFunctions`` () =

[<Fact>]
let ``remarks is as expected for List.reduce`` () =
let doc = tryGetDocumentation <@ List.reduce @>
let doc = Quoted.tryGetDocumentation <@ List.reduce @>

match doc with
| Some { Remarks = Some remarks } -> Assert.Equal("Raises System.ArgumentException if list is empty", remarks)
Expand All @@ -110,7 +110,7 @@ let ``remarks is as expected for List.reduce`` () =

[<Fact>]
let ``summary is as expected for Array.sortDescending`` () =
let doc = tryGetDocumentation <@ Array.sortDescending @>
let doc = Quoted.tryGetDocumentation <@ Array.sortDescending @>

match doc with
| Some { Summary = summary } ->
Expand All @@ -122,8 +122,8 @@ let ``summary is as expected for Array.sortDescending`` () =

[<Fact>]
let ``ReflectedDefinition works as expected`` () =
let docReflected = H.TryGetDocumentation(id)
let docQuoted = tryGetDocumentation <@ id @>
let docReflected = TryGetDocumentation(id)
let docQuoted = Quoted.tryGetDocumentation <@ id @>

match docReflected, docQuoted with
| Some r, Some q -> Assert.True((r = q))
Expand Down
35 changes: 18 additions & 17 deletions src/Fsih/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,29 @@ module Logic =
open Expr
open Parser

let tryGetDocumentation expr =
match exprNames expr with
| Some(xmlPath, assembly, modName, implName, sourceName) ->
helpText xmlPath assembly modName implName sourceName
| _ -> None

let h (expr: Quotations.Expr) =
match tryGetDocumentation expr with
| None -> printfn "unable to get documentation"
| Some d -> d.Print()

module Quoted =
let tryGetDocumentation expr =
match exprNames expr with
| Some(xmlPath, assembly, modName, implName, sourceName) ->
helpText xmlPath assembly modName implName sourceName
| _ -> None

let h (expr: Quotations.Expr) =
match tryGetDocumentation expr with
| None -> printfn "unable to get documentation"
| Some d -> d.Print()

[<AutoOpen>]
type H() =
static member H([<ReflectedDefinition>] expr: Quotations.Expr<_>) = h expr
static member TryGetDocumentation([<ReflectedDefinition>] expr: Quotations.Expr<_>) = tryGetDocumentation expr
static member h([<ReflectedDefinition>] expr: Quotations.Expr<_>) = Quoted.h expr

static member TryGetDocumentation([<ReflectedDefinition>] expr: Quotations.Expr<_>) =
Quoted.tryGetDocumentation expr

module Program =

[<EntryPoint>]
let main _argv =
// h <@ id @>
// H.H id
h <@ List.map @>
H.H List.map
h id

0

0 comments on commit cfe7079

Please sign in to comment.