-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4579 from unisonweb/cp/remove-global-names-again
Scope all commands to current namespace (no global fallbacks for names or PPE)
- Loading branch information
Showing
97 changed files
with
936 additions
and
3,502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,15 @@ | ||
-- | Utilities that have to do with constructing names objects. | ||
module Unison.Cli.NamesUtils | ||
( basicParseNames, | ||
basicPrettyPrintNamesA, | ||
displayNames, | ||
getBasicPrettyPrintNames, | ||
makePrintNamesFromLabeled', | ||
makeShadowedPrintNamesFromHQ, | ||
( currentNames, | ||
) | ||
where | ||
|
||
import Unison.Cli.Monad (Cli) | ||
import Unison.Cli.MonadUtils qualified as Cli | ||
import Unison.Codebase.Path (Path) | ||
import Unison.Codebase.Path qualified as Path | ||
import Unison.Cli.MonadUtils (getCurrentBranch0) | ||
import Unison.Codebase.Branch.Names qualified as Branch | ||
import Unison.Names (Names) | ||
import Unison.NamesWithHistory qualified as Names | ||
import Unison.Server.Backend qualified as Backend | ||
import Unison.UnisonFile (TypecheckedUnisonFile) | ||
import Unison.UnisonFile.Names qualified as UF | ||
import Unison.Var (Var) | ||
|
||
basicParseNames :: Cli Names | ||
basicParseNames = | ||
fst <$> basicNames' Backend.Within | ||
|
||
basicPrettyPrintNamesA :: Cli Names | ||
basicPrettyPrintNamesA = snd <$> basicNames' Backend.AllNames | ||
|
||
-- implementation detail of basicParseNames and basicPrettyPrintNames | ||
basicNames' :: (Path -> Backend.NameScoping) -> Cli (Names, Names) | ||
basicNames' nameScoping = do | ||
root' <- Cli.getRootBranch | ||
currentPath' <- Cli.getCurrentPath | ||
let (parse, pretty, _local) = Backend.namesForBranch root' (nameScoping $ Path.unabsolute currentPath') | ||
pure (parse, pretty) | ||
|
||
-- | Produce a `Names` needed to display all the hashes used in the given file. | ||
displayNames :: | ||
(Var v) => | ||
TypecheckedUnisonFile v a -> | ||
Cli Names | ||
displayNames unisonFile = | ||
-- voodoo | ||
makeShadowedPrintNamesFromLabeled | ||
(UF.typecheckedToNames unisonFile) | ||
|
||
getBasicPrettyPrintNames :: Cli Names | ||
getBasicPrettyPrintNames = do | ||
rootBranch <- Cli.getRootBranch | ||
currentPath <- Cli.getCurrentPath | ||
pure (Backend.prettyNamesForBranch rootBranch (Backend.AllNames (Path.unabsolute currentPath))) | ||
|
||
makePrintNamesFromLabeled' :: Cli Names | ||
makePrintNamesFromLabeled' = | ||
basicPrettyPrintNamesA | ||
|
||
makeShadowedPrintNamesFromHQ :: Names -> Cli Names | ||
makeShadowedPrintNamesFromHQ shadowing = do | ||
basicNames <- basicPrettyPrintNamesA | ||
pure $ Names.shadowing shadowing basicNames | ||
|
||
makeShadowedPrintNamesFromLabeled :: Names -> Cli Names | ||
makeShadowedPrintNamesFromLabeled shadowing = | ||
Names.shadowing shadowing <$> makePrintNamesFromLabeled' | ||
-- | Produce a 'Names' object which contains names for the current branch. | ||
currentNames :: Cli Names | ||
currentNames = do | ||
Branch.toNames <$> getCurrentBranch0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
-- | Utilities that have to do with constructing pretty-print environments, given stateful information in the Cli monad | ||
-- state/environment, such as the current path. | ||
module Unison.Cli.PrettyPrintUtils | ||
( prettyPrintEnvDecl, | ||
( prettyPrintEnvDeclFromNames, | ||
currentPrettyPrintEnvDecl, | ||
) | ||
where | ||
|
||
import Unison.Cli.Monad (Cli) | ||
import Unison.Cli.Monad qualified as Cli | ||
import Unison.Cli.MonadUtils qualified as Cli | ||
import Unison.Cli.NamesUtils qualified as Cli | ||
import Unison.Codebase qualified as Codebase | ||
import Unison.Codebase.Path (Path) | ||
import Unison.Codebase.Path qualified as Path | ||
import Unison.Names (Names) | ||
import Unison.Prelude | ||
import Unison.PrettyPrintEnv.Names qualified as PPE | ||
import Unison.PrettyPrintEnvDecl (PrettyPrintEnvDecl) | ||
import Unison.PrettyPrintEnvDecl qualified as PPE hiding (biasTo) | ||
import Unison.PrettyPrintEnvDecl.Names qualified as PPED | ||
import Unison.Server.Backend qualified as Backend | ||
|
||
prettyPrintEnvDecl :: Names -> Cli PrettyPrintEnvDecl | ||
prettyPrintEnvDecl ns = | ||
-- | Builds a pretty print env decl from a names object. | ||
prettyPrintEnvDeclFromNames :: Names -> Cli PPE.PrettyPrintEnvDecl | ||
prettyPrintEnvDeclFromNames ns = | ||
Cli.runTransaction Codebase.hashLength <&> \hashLen -> | ||
PPED.makePPED (PPE.hqNamer hashLen ns) (PPE.suffixifyByHash ns) | ||
|
||
-- | Get a pretty print env decl for the current names at the current path. | ||
currentPrettyPrintEnvDecl :: (Path -> Backend.NameScoping) -> Cli PrettyPrintEnvDecl | ||
currentPrettyPrintEnvDecl scoping = do | ||
root' <- Cli.getRootBranch | ||
currentPath <- Cli.getCurrentPath | ||
hqLen <- Cli.runTransaction Codebase.hashLength | ||
pure $ Backend.getCurrentPrettyNames hqLen (scoping (Path.unabsolute currentPath)) root' | ||
-- | ||
-- Prefer using 'prettyPrintEnvDeclFromNames' when you've already got | ||
-- a 'Names' value around, since using 'currentPrettyPrintEnvDecl' rebuilds the underlying | ||
-- names object. | ||
currentPrettyPrintEnvDecl :: Cli PPE.PrettyPrintEnvDecl | ||
currentPrettyPrintEnvDecl = do | ||
Cli.currentNames >>= prettyPrintEnvDeclFromNames |
Oops, something went wrong.