Skip to content

Commit

Permalink
Change docs command to expect Name
Browse files Browse the repository at this point in the history
Previously, when given a numbered arg, from some commands (e.g., `find`), it
would fail to find the docs because the hash associated with the definition was
applied to the `doc`, which then would be incorrect.

This now discards hashes up-front, so it can add the `doc` suffix to the name.

Fixes #3939.
  • Loading branch information
sellout committed May 28, 2024
1 parent 5971142 commit 538f78f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
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 @@ -1760,22 +1760,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 @@ -175,7 +175,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 @@ -993,7 +993,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
18 changes: 1 addition & 17 deletions unison-src/transcripts-using-base/fix3939.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ meh = 9
.> docs 1
⚠️
The following names were not found in the codebase. Check your spelling.
meh.doc#3n6of1k7qmgib9jda9ov1obetubfmladketn40gqifp4pfdea8it6ofa920l1topi2pd32vlsbfu3q41fkbt8coa38akg9eetto09j8
A simple doc.
```



🛑

The transcript failed due to an error in the stanza above. The error is:


⚠️

The following names were not found in the codebase. Check your spelling.
meh.doc#3n6of1k7qmgib9jda9ov1obetubfmladketn40gqifp4pfdea8it6ofa920l1topi2pd32vlsbfu3q41fkbt8coa38akg9eetto09j8

0 comments on commit 538f78f

Please sign in to comment.