@@ -1429,30 +1429,28 @@ handleFindI ::
14291429 Cli ()
14301430handleFindI 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- FindLocalSubnamespace p -> do
1441- path <- Cli. resolvePath p
1442- branch0 <- Cli. getBranch0At path
1443- let names = Branch. toNames branch0
1444- pped <- Cli. currentPrettyPrintEnvDecl
1445- pure (pped, names)
1446- FindLocalAndDeps -> do
1447- 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)
14481445 -- Don't exclude anything from the pretty printer, since the type signatures we print for
14491446 -- results may contain things in lib.
14501447 pped <- Cli. currentPrettyPrintEnvDecl
1451- pure (pped, names)
1448+ pure (pped, names, Just p, branch0 )
14521449 FindGlobal -> do
14531450 globalNames <- Names. makeAbsolute . Branch. toNames <$> Cli. getRootBranch0
14541451 pped <- Cli. prettyPrintEnvDeclFromNames globalNames
1455- pure (pped, globalNames)
1452+ currentBranch0 <- Cli. getCurrentBranch0
1453+ pure (pped, globalNames, Nothing , currentBranch0)
14561454 let suffixifiedPPE = PPED. suffixifiedPPE pped
14571455 let getResults :: Names -> Cli [SearchResult ]
14581456 getResults names =
@@ -1461,7 +1459,7 @@ handleFindI isVerbose fscope ws input = do
14611459 -- type query
14621460 " :" : ws -> do
14631461 typ <- parseSearchType (show input) (unwords ws)
1464- let keepNamed = Set. intersection (Branch. deepReferents currentBranch0 )
1462+ let keepNamed = Set. intersection (Branch. deepReferents branch0 )
14651463 (noExactTypeMatches, matches) <- do
14661464 Cli. runTransaction do
14671465 matches <- keepNamed <$> Codebase. termsOfType codebase typ
@@ -1487,16 +1485,16 @@ handleFindI isVerbose fscope ws input = do
14871485 (mapMaybe (HQ. parseTextWith anythingBeforeHash . Text. pack) qs)
14881486 pure $ uniqueBy SR. toReferent srs
14891487 let respondResults results = do
1490- Cli. setNumberedArgs $ fmap searchResultToHQString results
1488+ Cli. setNumberedArgs $ fmap ( searchResultToHQString searchRoot) results
14911489 results' <- Cli. runTransaction (Backend. loadSearchResults codebase results)
14921490 Cli. respond $ ListOfDefinitions fscope suffixifiedPPE isVerbose results'
14931491 results <- getResults names
14941492 case (results, fscope) of
1495- ([] , FindLocal ) -> do
1493+ ([] , FindLocal {} ) -> do
14961494 Cli. respond FindNoLocalMatches
14971495 -- We've already searched everything else, so now we search JUST the
14981496 -- names in lib.
1499- 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
15001498 case mayOnlyLibBranch of
15011499 Nothing -> respondResults []
15021500 Just onlyLibBranch -> do
@@ -1810,11 +1808,14 @@ confirmedCommand i = do
18101808 pure $ Just i == (loopState ^. # lastInput)
18111809
18121810-- | restores the full hash to these search results, for _numberedArgs purposes
1813- searchResultToHQString :: SearchResult -> String
1814- searchResultToHQString = \ case
1815- SR. Tm' n r _ -> Text. unpack $ HQ. toText $ HQ. requalify n r
1816- 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)
18171815 _ -> error " impossible match failure"
1816+ where
1817+ addPrefix :: Name -> Name
1818+ addPrefix = maybe id Path. prefixName2 oprefix
18181819
18191820-- return `name` and `name.<everything>...`
18201821_searchBranchPrefix :: Branch m -> Name -> [SearchResult ]
0 commit comments