Skip to content

Commit

Permalink
Remove metadata related inputs
Browse files Browse the repository at this point in the history
Stop loading metadata

fixes #4416
  • Loading branch information
tstat committed Nov 29, 2023
1 parent 4ffbc7e commit e96caa1
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 394 deletions.
4 changes: 2 additions & 2 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ s2cBranch (S.Branch.Full.Branch tms tps patches children) =
(fmap NameSegment . Q.expectText)
( Map.bitraverse s2cReferent \case
S.MetadataSet.Inline rs ->
pure $ C.Branch.MdValues <$> loadTypesForMetadata rs
pure $ pure $ C.Branch.MdValues Map.empty
)
doTypes ::
Map Db.TextId (Map S.Reference S.DbMetadataSet) ->
Expand All @@ -590,7 +590,7 @@ s2cBranch (S.Branch.Full.Branch tms tps patches children) =
(fmap NameSegment . Q.expectText)
( Map.bitraverse s2cReference \case
S.MetadataSet.Inline rs ->
pure $ C.Branch.MdValues <$> loadTypesForMetadata rs
pure $ pure $ C.Branch.MdValues Map.empty
)
doPatches ::
Map Db.TextId Db.PatchObjectId ->
Expand Down
101 changes: 5 additions & 96 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import Unison.Codebase.Editor.HandleInput.BranchRename (handleBranchRename)
import Unison.Codebase.Editor.HandleInput.Branches (handleBranches)
import Unison.Codebase.Editor.HandleInput.DeleteBranch (handleDeleteBranch)
import Unison.Codebase.Editor.HandleInput.DeleteProject (handleDeleteProject)
import Unison.Codebase.Editor.HandleInput.MetadataUtils (addDefaultMetadata, manageLinks)
import Unison.Codebase.Editor.HandleInput.MoveBranch (doMoveBranch)
import Unison.Codebase.Editor.HandleInput.NamespaceDependencies qualified as NamespaceDependencies
import Unison.Codebase.Editor.HandleInput.NamespaceDiffUtils (diffHelper)
Expand Down Expand Up @@ -195,7 +194,6 @@ import Unison.Util.Pretty qualified as P
import Unison.Util.Pretty qualified as Pretty
import Unison.Util.Relation qualified as R
import Unison.Util.Relation qualified as Relation
import Unison.Util.Relation4 qualified as R4
import Unison.Util.Set qualified as Set
import Unison.Util.Star3 qualified as Star3
import Unison.Util.TransitiveClosure (transitiveClosure)
Expand Down Expand Up @@ -718,23 +716,6 @@ loop e = do
types' :: [(Reference, [HQ'.HashQualified Name])]
types' = map (\r -> (r, PPE.allTypeNames unsuffixifiedPPE r)) (Set.toList types)
Cli.respond $ ListNames global hqLength types' terms'
LinkI mdValue srcs -> do
description <- inputDescription input
manageLinks False srcs [mdValue] Metadata.insert
Cli.syncRoot description
UnlinkI mdValue srcs -> do
description <- inputDescription input
manageLinks False srcs [mdValue] Metadata.delete
Cli.syncRoot description

-- > links List.map (.Docs .English)
-- > links List.map -- give me all the
-- > links Optional License
LinksI src mdTypeStr -> do
(ppe, out) <- getLinks (show input) src (Right mdTypeStr)
#numberedArgs .= fmap (HQ.toString . view _1) out
let biasedPPE = (PPE.biasTo (maybeToList . Path.toName' . HQ'.toName $ Path.unsplitHQ' src) ppe)
Cli.respond $ ListOfLinks biasedPPE out
DocsI srcs -> do
currentBranch0 <- Cli.getCurrentBranch0
basicPrettyPrintNames <- getBasicPrettyPrintNames
Expand Down Expand Up @@ -1089,7 +1070,6 @@ loop e = do
Cli.runTransaction . Codebase.addDefsToCodebase codebase . SlurpResult.filterUnisonFile sr $ uf
ppe <- prettyPrintEnvDecl =<< displayNames uf
Cli.respond $ SlurpOutput input (PPE.suffixifiedPPE ppe) sr
addDefaultMetadata adds
Cli.syncRoot description
SaveExecuteResultI resultName -> do
description <- inputDescription input
Expand All @@ -1103,7 +1083,6 @@ loop e = do
Cli.stepAtNoSync (Path.unabsolute currentPath, doSlurpAdds adds uf)
Cli.runTransaction . Codebase.addDefsToCodebase codebase . SlurpResult.filterUnisonFile sr $ uf
ppe <- prettyPrintEnvDecl =<< displayNames uf
addDefaultMetadata adds
Cli.syncRoot description
Cli.respond $ SlurpOutput input (PPE.suffixifiedPPE ppe) sr
PreviewAddI requestedNames -> do
Expand Down Expand Up @@ -1547,12 +1526,6 @@ inputDescription input =
UndoI {} -> pure "undo"
ExecuteI s args -> pure ("execute " <> Text.unwords (fmap Text.pack (s : args)))
IOTestI hq -> pure ("io.test " <> HQ.toText hq)
LinkI md defs0 -> do
defs <- traverse hqs' defs0
pure ("link " <> HQ.toText md <> " " <> Text.intercalate " " defs)
UnlinkI md defs0 -> do
defs <- traverse hqs' defs0
pure ("unlink " <> HQ.toText md <> " " <> Text.intercalate " " defs)
UpdateBuiltinsI -> pure "builtins.update"
MergeBuiltinsI -> pure "builtins.merge"
MergeIOBuiltinsI -> pure "builtins.mergeio"
Expand Down Expand Up @@ -1611,7 +1584,6 @@ inputDescription input =
StructuredFindReplaceI {} -> wat
GistI {} -> wat
HistoryI {} -> wat
LinksI {} -> wat
ListDependenciesI {} -> wat
ListDependentsI {} -> wat
ListEditsI {} -> wat
Expand Down Expand Up @@ -2254,52 +2226,6 @@ doDisplay outputLoc names tm = do
tm
Cli.respond $ DisplayRendered loc rendered

getLinks ::
SrcLoc ->
Path.HQSplit' ->
Either (Set Reference) (Maybe String) ->
Cli
( PPE.PrettyPrintEnv,
-- e.g. ("Foo.doc", #foodoc, Just (#builtin.Doc)
[(HQ.HashQualified Name, Reference, Maybe (Type Symbol Ann))]
)
getLinks srcLoc src =
getLinks' src <=< \case
Left s -> pure (Just s)
Right Nothing -> pure Nothing
Right (Just mdTypeStr) -> do
typ <- parseType srcLoc mdTypeStr
pure (Just (Set.singleton (Hashing.typeToReference typ)))

getLinks' ::
Path.HQSplit' -> -- definition to print metadata of
Maybe (Set Reference) -> -- return all metadata if empty
Cli
( PPE.PrettyPrintEnv,
-- e.g. ("Foo.doc", #foodoc, Just (#builtin.Doc)
[(HQ.HashQualified Name, Reference, Maybe (Type Symbol Ann))]
)
getLinks' src selection0 = do
Cli.Env {codebase} <- ask
root0 <- Cli.getRootBranch0
p <- Path.convert <$> Cli.resolveSplit' src -- ex: the (parent,hqsegment) of `List.map` - `List`
let -- all metadata (type+value) associated with name `src`
allMd =
R4.d34 (BranchUtil.getTermMetadataHQNamed p root0)
<> R4.d34 (BranchUtil.getTypeMetadataHQNamed p root0)
allMd' = maybe allMd (`R.restrictDom` allMd) selection0
-- then list the values after filtering by type
allRefs :: Set Reference = R.ran allMd'
sigs <- Cli.runTransaction (for (toList allRefs) (loadTypeOfTerm codebase . Referent.Ref))
let deps =
Set.map LD.termRef allRefs
<> Set.unions [Set.map LD.typeRef . Type.dependencies $ t | Just t <- sigs]
ppe <- prettyPrintEnvDecl =<< makePrintNamesFromLabeled' deps
let ppeDecl = PPE.unsuffixifiedPPE ppe
let sortedSigs = sortOn snd (toList allRefs `zip` sigs)
let out = [(PPE.termName ppeDecl (Referent.Ref r), r, t) | (r, t) <- sortedSigs]
pure (PPE.suffixifiedPPE ppe, out)

-- | Show todo output if there are any conflicts or edits.
doShowTodoOutput :: Patch -> Path.Absolute -> Cli ()
doShowTodoOutput patch scopePath = do
Expand Down Expand Up @@ -2822,12 +2748,11 @@ displayI prettyPrintNames outputLoc hq = do
doDisplay outputLoc ns tm

docsI :: SrcLoc -> Names -> Path.HQSplit' -> Cli ()
docsI srcLoc prettyPrintNames src =
docsI _srcLoc prettyPrintNames src =
fileByName
where
{- Given `docs foo`, we look for docs in 3 places, in this order:
{- Given `docs foo`, we look for docs in 2 places, in this order:
(fileByName) First check the file for `foo.doc`, and if found do `display foo.doc`
(codebaseByMetadata) Next check for doc metadata linked to `foo` in the codebase
(codebaseByName) Lastly check for `foo.doc` in the codebase and if found do `display foo.doc`
-}
hq :: HQ.HashQualified Name
Expand All @@ -2849,32 +2774,16 @@ docsI srcLoc prettyPrintNames src =
-- the hash back to its full name in the file
fname' <- pure $ NamesWithHistory.longestTermName 10 (Set.findMin s) fnames
displayI prettyPrintNames ConsoleLocation fname'
_ -> codebaseByMetadata

codebaseByMetadata :: Cli ()
codebaseByMetadata = do
(ppe, out) <- getLinks srcLoc src (Left $ Set.fromList [DD.docRef, IOSource.doc2Ref])
case out of
[] -> codebaseByName
[(_name, ref, _tm)] -> do
len <- Cli.runTransaction Codebase.branchHashLength
let names = NamesWithHistory.NamesWithHistory prettyPrintNames mempty
let tm = Term.ref External ref
tm <- evalUnisonTerm True (PPE.fromNames len names) True tm
doDisplay ConsoleLocation names (Term.unannotate tm)
out -> do
#numberedArgs .= fmap (HQ.toString . view _1) out
Cli.respond $ ListOfLinks ppe out
_ -> codebaseByName

codebaseByName :: Cli ()
codebaseByName = do
parseNames <- basicParseNames
case NamesWithHistory.lookupHQTerm dotDoc (NamesWithHistory.NamesWithHistory parseNames mempty) of
s
| Set.size s == 1 -> displayI prettyPrintNames ConsoleLocation dotDoc
| Set.size s == 0 -> Cli.respond $ ListOfLinks PPE.empty []
-- todo: return a list of links here too
| otherwise -> Cli.respond $ ListOfLinks PPE.empty []
| Set.size s == 0 -> Cli.respond (PrintFailure "No doc found.")
| otherwise -> Cli.respond (PrintFailure "Conflicted docs.")

loadDisplayInfo ::
Codebase m Symbol Ann ->
Expand Down
176 changes: 0 additions & 176 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/MetadataUtils.hs

This file was deleted.

2 changes: 0 additions & 2 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Unison.Codebase.Branch (Branch0 (..))
import Unison.Codebase.Branch qualified as Branch
import Unison.Codebase.Branch.Names qualified as Branch
import Unison.Codebase.BranchUtil qualified as BranchUtil
import Unison.Codebase.Editor.HandleInput.MetadataUtils (addDefaultMetadata)
import Unison.Codebase.Editor.Input
import Unison.Codebase.Editor.Output
import Unison.Codebase.Editor.Propagate qualified as Propagate
Expand Down Expand Up @@ -199,7 +198,6 @@ handleUpdate input optionalPatch requestedNames = do
Cli.respond $ SlurpOutput input (PPE.suffixifiedPPE ppe) sr
whenJust patchOps \(updatedPatch, _, _) ->
void $ propagatePatchNoSync updatedPatch currentPath'
addDefaultMetadata addsAndUpdates
Cli.syncRoot case patchPath of
Nothing -> "update.nopatch"
Just p ->
Expand Down
Loading

0 comments on commit e96caa1

Please sign in to comment.