Skip to content

Commit 2cf96a3

Browse files
deprecate cd, up; add find-in (#4883)
* deprecate `cd`, `up`, hide `reset-root`, add `find-in`, hides unimplemented `update.builtins` Co-authored-by: Chris Penner <christopher.penner@gmail.com>
1 parent 61c5beb commit 2cf96a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+306
-347
lines changed

parser-typechecker/src/Unison/Codebase/Path.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Unison.Codebase.Path
2424
prefix,
2525
unprefix,
2626
prefixName,
27+
prefixName2,
2728
unprefixName,
2829
HQSplit,
2930
Split,
@@ -192,6 +193,11 @@ prefix (Absolute (Path prefix)) = \case
192193
AbsolutePath' abs -> unabsolute abs
193194
RelativePath' rel -> Path $ prefix <> toSeq (unrelative rel)
194195

196+
prefix2 :: Path -> Path' -> Path
197+
prefix2 (Path prefix) = \case
198+
AbsolutePath' abs -> unabsolute abs
199+
RelativePath' rel -> Path $ prefix <> toSeq (unrelative rel)
200+
195201
-- | Finds the longest shared path prefix of two paths.
196202
-- Returns (shared prefix, path to first location from shared prefix, path to second location from shared prefix)
197203
--
@@ -273,6 +279,9 @@ unprefixName prefix = toName . unprefix prefix . fromName'
273279
prefixName :: Absolute -> Name -> Name
274280
prefixName p n = fromMaybe n . toName . prefix p . fromName' $ n
275281

282+
prefixName2 :: Path -> Name -> Name
283+
prefixName2 p n = fromMaybe n . toName . prefix2 p . fromName' $ n
284+
276285
singleton :: NameSegment -> Path
277286
singleton n = fromList [n]
278287

scripts/check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ true \
66
&& stack exec transcripts \
77
&& stack exec unison transcript unison-src/transcripts-round-trip/main.md \
88
&& stack exec unison transcript unison-src/transcripts-manual/rewrites.md \
9-
&& stack exec integration-tests
9+
&& stack exec cli-integration-tests

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,24 +1429,28 @@ handleFindI ::
14291429
Cli ()
14301430
handleFindI isVerbose fscope ws input = do
14311431
Cli.Env {codebase} <- ask
1432-
currentBranch0 <- Cli.getCurrentBranch0
1433-
(pped, names) <- case fscope of
1434-
FindLocal -> do
1435-
let names = Branch.toNames (Branch.withoutLib currentBranch0)
1432+
(pped, names, searchRoot, branch0) <- case fscope of
1433+
FindLocal p -> do
1434+
searchRoot <- Cli.resolvePath p
1435+
branch0 <- Cli.getBranch0At searchRoot
1436+
let names = Branch.toNames (Branch.withoutLib branch0)
14361437
-- Don't exclude anything from the pretty printer, since the type signatures we print for
14371438
-- results may contain things in lib.
14381439
pped <- Cli.currentPrettyPrintEnvDecl
1439-
pure (pped, names)
1440-
FindLocalAndDeps -> do
1441-
let names = Branch.toNames (Branch.withoutTransitiveLibs currentBranch0)
1440+
pure (pped, names, Just p, branch0)
1441+
FindLocalAndDeps p -> do
1442+
searchRoot <- Cli.resolvePath p
1443+
branch0 <- Cli.getBranch0At searchRoot
1444+
let names = Branch.toNames (Branch.withoutTransitiveLibs branch0)
14421445
-- Don't exclude anything from the pretty printer, since the type signatures we print for
14431446
-- results may contain things in lib.
14441447
pped <- Cli.currentPrettyPrintEnvDecl
1445-
pure (pped, names)
1448+
pure (pped, names, Just p, branch0)
14461449
FindGlobal -> do
14471450
globalNames <- Names.makeAbsolute . Branch.toNames <$> Cli.getRootBranch0
14481451
pped <- Cli.prettyPrintEnvDeclFromNames globalNames
1449-
pure (pped, globalNames)
1452+
currentBranch0 <- Cli.getCurrentBranch0
1453+
pure (pped, globalNames, Nothing, currentBranch0)
14501454
let suffixifiedPPE = PPED.suffixifiedPPE pped
14511455
let getResults :: Names -> Cli [SearchResult]
14521456
getResults names =
@@ -1455,7 +1459,7 @@ handleFindI isVerbose fscope ws input = do
14551459
-- type query
14561460
":" : ws -> do
14571461
typ <- parseSearchType (show input) (unwords ws)
1458-
let keepNamed = Set.intersection (Branch.deepReferents currentBranch0)
1462+
let keepNamed = Set.intersection (Branch.deepReferents branch0)
14591463
(noExactTypeMatches, matches) <- do
14601464
Cli.runTransaction do
14611465
matches <- keepNamed <$> Codebase.termsOfType codebase typ
@@ -1481,16 +1485,16 @@ handleFindI isVerbose fscope ws input = do
14811485
(mapMaybe (HQ.parseTextWith anythingBeforeHash . Text.pack) qs)
14821486
pure $ uniqueBy SR.toReferent srs
14831487
let respondResults results = do
1484-
Cli.setNumberedArgs $ fmap searchResultToHQString results
1488+
Cli.setNumberedArgs $ fmap (searchResultToHQString searchRoot) results
14851489
results' <- Cli.runTransaction (Backend.loadSearchResults codebase results)
14861490
Cli.respond $ ListOfDefinitions fscope suffixifiedPPE isVerbose results'
14871491
results <- getResults names
14881492
case (results, fscope) of
1489-
([], FindLocal) -> do
1493+
([], FindLocal {}) -> do
14901494
Cli.respond FindNoLocalMatches
14911495
-- We've already searched everything else, so now we search JUST the
14921496
-- names in lib.
1493-
let mayOnlyLibBranch = currentBranch0 & Branch.children %%~ \cs -> Map.singleton NameSegment.libSegment <$> Map.lookup NameSegment.libSegment cs
1497+
let mayOnlyLibBranch = branch0 & Branch.children %%~ \cs -> Map.singleton NameSegment.libSegment <$> Map.lookup NameSegment.libSegment cs
14941498
case mayOnlyLibBranch of
14951499
Nothing -> respondResults []
14961500
Just onlyLibBranch -> do
@@ -1804,11 +1808,14 @@ confirmedCommand i = do
18041808
pure $ Just i == (loopState ^. #lastInput)
18051809

18061810
-- | restores the full hash to these search results, for _numberedArgs purposes
1807-
searchResultToHQString :: SearchResult -> String
1808-
searchResultToHQString = \case
1809-
SR.Tm' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify n r
1810-
SR.Tp' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify n (Referent.Ref r)
1811+
searchResultToHQString :: Maybe Path -> SearchResult -> String
1812+
searchResultToHQString oprefix = \case
1813+
SR.Tm' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify (addPrefix <$> n) r
1814+
SR.Tp' n r _ -> Text.unpack $ HQ.toText $ HQ.requalify (addPrefix <$> n) (Referent.Ref r)
18111815
_ -> error "impossible match failure"
1816+
where
1817+
addPrefix :: Name -> Name
1818+
addPrefix = maybe id Path.prefixName2 oprefix
18121819

18131820
-- return `name` and `name.<everything>...`
18141821
_searchBranchPrefix :: Branch m -> Name -> [SearchResult]

unison-cli/src/Unison/Codebase/Editor/Input.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Data.These (These)
3535
import U.Codebase.HashTags (CausalHash)
3636
import Unison.Codebase.Branch.Merge qualified as Branch
3737
import Unison.Codebase.Editor.RemoteRepo (ReadRemoteNamespace, WriteGitRepo, WriteRemoteNamespace)
38-
import Unison.Codebase.Path (Path')
38+
import Unison.Codebase.Path (Path, Path')
3939
import Unison.Codebase.Path qualified as Path
4040
import Unison.Codebase.Path.Parse qualified as Path
4141
import Unison.Codebase.PushBehavior (PushBehavior)
@@ -313,8 +313,8 @@ data OutputLocation
313313
deriving (Eq, Show)
314314

315315
data FindScope
316-
= FindLocal
317-
| FindLocalAndDeps
316+
= FindLocal Path
317+
| FindLocalAndDeps Path
318318
| FindGlobal
319319
deriving stock (Eq, Show)
320320

unison-cli/src/Unison/CommandLine/InputPatterns.hs

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ updateBuiltins =
124124
InputPattern
125125
"builtins.update"
126126
[]
127-
I.Visible
127+
I.Hidden
128128
[]
129129
( "Adds all the builtins that are missing from this namespace, "
130130
<> "and deprecate the ones that don't exist in this version of Unison."
@@ -531,7 +531,7 @@ sfind :: InputPattern
531531
sfind =
532532
InputPattern "rewrite.find" ["sfind"] I.Visible [("rewrite-rule definition", Required, definitionQueryArg)] msg parse
533533
where
534-
parse [q] = Input.StructuredFindI Input.FindLocal <$> parseHashQualifiedName q
534+
parse [q] = Input.StructuredFindI (Input.FindLocal Path.empty) <$> parseHashQualifiedName q
535535
parse _ = Left "expected exactly one argument"
536536
msg =
537537
P.lines
@@ -589,40 +589,76 @@ sfindReplace =
589589
]
590590

591591
find :: InputPattern
592-
find = find' "find" Input.FindLocal
592+
find = find' "find" (Input.FindLocal Path.empty)
593593

594594
findAll :: InputPattern
595-
findAll = find' "find.all" Input.FindLocalAndDeps
595+
findAll = find' "find.all" (Input.FindLocalAndDeps Path.empty)
596596

597597
findGlobal :: InputPattern
598598
findGlobal = find' "find.global" Input.FindGlobal
599599

600+
findIn, findInAll :: InputPattern
601+
findIn = findIn' "find-in" Input.FindLocal
602+
findInAll = findIn' "find-in.all" Input.FindLocalAndDeps
603+
604+
findIn' :: String -> (Path.Path -> Input.FindScope) -> InputPattern
605+
findIn' cmd mkfscope =
606+
InputPattern
607+
cmd
608+
[]
609+
I.Visible
610+
[("namespace", Required, namespaceArg), ("query", ZeroPlus, exactDefinitionArg)]
611+
findHelp
612+
\case
613+
p : args -> first P.text do
614+
p <- Path.parsePath p
615+
pure (Input.FindI False (mkfscope p) args)
616+
_ -> Left findHelp
617+
618+
findHelp :: P.Pretty CT.ColorText
619+
findHelp =
620+
( P.wrapColumn2
621+
[ ("`find`", "lists all definitions in the current namespace."),
622+
( "`find foo`",
623+
"lists all definitions with a name similar to 'foo' in the current "
624+
<> "namespace (excluding those under 'lib')."
625+
),
626+
( "`find foo bar`",
627+
"lists all definitions with a name similar to 'foo' or 'bar' in the "
628+
<> "current namespace (excluding those under 'lib')."
629+
),
630+
( "`find-in namespace`",
631+
"lists all definitions in the specified subnamespace."
632+
),
633+
( "`find-in namespace foo bar`",
634+
"lists all definitions with a name similar to 'foo' or 'bar' in the "
635+
<> "specified subnamespace."
636+
),
637+
( "find.all foo",
638+
"lists all definitions with a name similar to 'foo' in the current "
639+
<> "namespace (including one level of 'lib')."
640+
),
641+
( "`find-in.all namespace`",
642+
"lists all definitions in the specified subnamespace (including one level of its 'lib')."
643+
),
644+
( "`find-in.all namespace foo bar`",
645+
"lists all definitions with a name similar to 'foo' or 'bar' in the "
646+
<> "specified subnamespace (including one level of its 'lib')."
647+
),
648+
( "find.global foo",
649+
"lists all definitions with a name similar to 'foo' in any namespace"
650+
)
651+
]
652+
)
653+
600654
find' :: String -> Input.FindScope -> InputPattern
601655
find' cmd fscope =
602656
InputPattern
603657
cmd
604658
[]
605659
I.Visible
606660
[("query", ZeroPlus, exactDefinitionArg)]
607-
( P.wrapColumn2
608-
[ ("`find`", "lists all definitions in the current namespace."),
609-
( "`find foo`",
610-
"lists all definitions with a name similar to 'foo' in the current "
611-
<> "namespace (excluding those under 'lib')."
612-
),
613-
( "`find foo bar`",
614-
"lists all definitions with a name similar to 'foo' or 'bar' in the "
615-
<> "current namespace (excluding those under 'lib')."
616-
),
617-
( "find.all foo",
618-
"lists all definitions with a name similar to 'foo' in the current "
619-
<> "namespace (including one level of 'lib')."
620-
),
621-
( "find.global foo",
622-
"lists all definitions with a name similar to 'foo' in any namespace"
623-
)
624-
]
625-
)
661+
findHelp
626662
(pure . Input.FindI False fscope)
627663

628664
findShallow :: InputPattern
@@ -656,7 +692,7 @@ findVerbose =
656692
( "`find.verbose` searches for definitions like `find`, but includes hashes "
657693
<> "and aliases in the results."
658694
)
659-
(pure . Input.FindI True Input.FindLocal)
695+
(pure . Input.FindI True (Input.FindLocal Path.empty))
660696

661697
findVerboseAll :: InputPattern
662698
findVerboseAll =
@@ -668,7 +704,7 @@ findVerboseAll =
668704
( "`find.all.verbose` searches for definitions like `find.all`, but includes hashes "
669705
<> "and aliases in the results."
670706
)
671-
(pure . Input.FindI True Input.FindLocalAndDeps)
707+
(pure . Input.FindI True (Input.FindLocalAndDeps Path.empty))
672708

673709
findPatch :: InputPattern
674710
findPatch =
@@ -968,11 +1004,11 @@ aliasMany =
9681004
up :: InputPattern
9691005
up =
9701006
InputPattern
971-
"up"
1007+
"deprecated.up"
9721008
[]
973-
I.Visible
1009+
I.Hidden
9741010
[]
975-
(P.wrapColumn2 [(makeExample up [], "move current path up one level")])
1011+
(P.wrapColumn2 [(makeExample up [], "move current path up one level (deprecated)")])
9761012
( \case
9771013
[] -> Right Input.UpI
9781014
_ -> Left (I.help up)
@@ -981,12 +1017,12 @@ up =
9811017
cd :: InputPattern
9821018
cd =
9831019
InputPattern
984-
"namespace"
985-
["cd", "j"]
1020+
"deprecated.cd"
1021+
["deprecated.namespace"]
9861022
I.Visible
9871023
[("namespace", Required, namespaceArg)]
9881024
( P.lines
989-
[ "Moves your perspective to a different namespace.",
1025+
[ "Moves your perspective to a different namespace. Deprecated for now because too many important things depend on your perspective selection.",
9901026
"",
9911027
P.wrapColumn2
9921028
[ ( makeExample cd ["foo.bar"],
@@ -1020,7 +1056,7 @@ back =
10201056
[]
10211057
( P.wrapColumn2
10221058
[ ( makeExample back [],
1023-
"undoes the last" <> makeExample' cd <> "command."
1059+
"undoes the last" <> makeExample' projectSwitch <> "command."
10241060
)
10251061
]
10261062
)
@@ -1233,15 +1269,18 @@ resetRoot =
12331269
InputPattern
12341270
"reset-root"
12351271
[]
1236-
I.Visible
1272+
I.Hidden
12371273
[("namespace or hash to reset to", Required, namespaceArg)]
1238-
( P.wrapColumn2
1239-
[ ( makeExample resetRoot [".foo"],
1240-
"Reset the root namespace (along with its history) to that of the `.foo` namespace."
1241-
),
1242-
( makeExample resetRoot ["#9dndk3kbsk13nbpeu"],
1243-
"Reset the root namespace (along with its history) to that of the namespace with hash `#9dndk3kbsk13nbpeu`."
1244-
)
1274+
( P.lines
1275+
[ "Deprecated because it's incompatible with projects. ⚠️ Warning, this command can cause codebase corruption.",
1276+
P.wrapColumn2
1277+
[ ( makeExample resetRoot [".foo"],
1278+
"Reset the root namespace (along with its history) to that of the `.foo` namespace. Deprecated"
1279+
),
1280+
( makeExample resetRoot ["#9dndk3kbsk13nbpeu"],
1281+
"Reset the root namespace (along with its history) to that of the namespace with hash `#9dndk3kbsk13nbpeu`."
1282+
)
1283+
]
12451284
]
12461285
)
12471286
\case
@@ -2982,7 +3021,9 @@ validInputs =
29823021
editNamespace,
29833022
execute,
29843023
find,
3024+
findIn,
29853025
findAll,
3026+
findInAll,
29863027
findGlobal,
29873028
findPatch,
29883029
findShallow,

unison-cli/src/Unison/CommandLine/OutputMessages.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ notifyUser dir = \case
971971
pure . P.warnCallout . P.lines $
972972
[ "Are you sure you want to clear away everything?",
973973
"You could use "
974-
<> IP.makeExample' IP.cd
975-
<> " to switch to a new namespace instead."
974+
<> IP.makeExample' IP.projectCreate
975+
<> " to switch to a new project instead."
976976
]
977977
DeleteBranchConfirmation _uniqueDeletions -> error "todo"
978978
-- let

unison-src/transcripts-using-base/_base.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ transcripts which contain less boilerplate.
1212
```ucm:hide
1313
.> builtins.merge
1414
.> builtins.mergeio
15-
.> cd builtin
1615
.> load unison-src/transcripts-using-base/base.u
1716
.> add
1817
```
@@ -55,4 +54,3 @@ testAutoClean _ =
5554
.> add
5655
.> io.test testAutoClean
5756
```
58-

unison-src/transcripts-using-base/binary-encoding-nats.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
```ucm:hide
33
.> builtins.merge
44
.> builtins.mergeio
5-
.> cd builtin
65
.> load unison-src/transcripts-using-base/base.u
76
.> add
87
.> find

0 commit comments

Comments
 (0)