Skip to content
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

Docs name #5012

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1758,22 +1758,16 @@ displayI outputLoc hq = do
let ns = UF.addNamesFromTypeCheckedUnisonFile unisonFile names
doDisplay outputLoc ns tm

docsI :: Path.HQSplit' -> Cli ()
docsI :: Name -> Cli ()
docsI src = do
findInScratchfileByName
where
{- Given `docs foo`, we look for docs in 3 places, in this order:
(fileByName) First check the file for `foo.doc`, and if found do `display foo.doc`
(codebaseByName) Lastly check for `foo.doc` in the codebase and if found do `display foo.doc`
-}
hq :: HQ.HashQualified Name
hq =
let hq' :: HQ'.HashQualified Name
hq' = Path.unsafeToName' <$> Name.convert src
in Name.convert hq'

dotDoc :: HQ.HashQualified Name
dotDoc = hq <&> \n -> Name.joinDot n (Name.fromSegment "doc")
dotDoc = Name.convert . Name.joinDot src $ Name.fromSegment "doc"

findInScratchfileByName :: Cli ()
findInScratchfileByName = do
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Codebase/Editor/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ data Input
| -- Display provided definitions.
DisplayI OutputLocation (NonEmpty (HQ.HashQualified Name))
| -- Display docs for provided terms.
DocsI (NonEmpty Path.HQSplit')
DocsI (NonEmpty Name)
| -- other
FindI Bool FindScope [String] -- FindI isVerbose findScope query
| FindShallowI Path'
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ docs =
"`docs` without arguments invokes a search to select which definition to view documentation for, which requires that `fzf` can be found within your PATH."
]
)
$ maybe (Left $ I.help docs) (fmap Input.DocsI . traverse handleHashQualifiedSplit'Arg) . NE.nonEmpty
$ maybe (Left $ I.help docs) (fmap Input.DocsI . traverse handleNameArg) . NE.nonEmpty

api :: InputPattern
api =
Expand Down
12 changes: 12 additions & 0 deletions unison-src/transcripts-using-base/fix3939.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```unison
{{
A simple doc.
}}
meh = 9
```

```ucm
.> add
.> find meh
.> docs 1
```
40 changes: 40 additions & 0 deletions unison-src/transcripts-using-base/fix3939.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
```unison
{{
A simple doc.
}}
meh = 9
```

```ucm

Loading changes detected in scratch.u.

I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:

⍟ These new definitions are ok to `add`:

meh : Nat
meh.doc : Doc2

```
```ucm
.> add

⍟ I've added these definitions:

meh : Nat
meh.doc : Doc2

.> find meh

1. meh : Nat
2. meh.doc : Doc2


.> docs 1

A simple doc.

```