diff --git a/.gitignore b/.gitignore index 686a1ac840..5cd5778264 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ dist-newstyle # Nix result +result-transcripts diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/DiffUpdate.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/DiffUpdate.hs index 5fcd20db6d..4aac9b25d2 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/DiffUpdate.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/DiffUpdate.hs @@ -178,8 +178,8 @@ handleDiffUpdate = do | (var, (refId, decl)) <- Map.toList (UF.effectDeclarationsId' tuf) ] - let newTypes :: Map Name (DeclOrBuiltin Symbol Ann) - newTypes = Map.restrictKeys fileTypeDecls newTypeNames + let newTypes :: Map Name (TypeReferenceId, Decl Symbol Ann) + newTypes = Map.restrictKeys fileTypeDeclsWithRefIds newTypeNames -- Types from the file that are updates to existing codebase definitions let updatedFileTypes :: Map Name (TypeReferenceId, Decl Symbol Ann) diff --git a/unison-cli/src/Unison/Codebase/Editor/Output.hs b/unison-cli/src/Unison/Codebase/Editor/Output.hs index 17c2a7aac9..384e5177bc 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Output.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Output.hs @@ -494,8 +494,8 @@ data Output !PPE.PrettyPrintEnvDecl -- PPE for old definitions (namespace names without file shadowing) !PPE.PrettyPrintEnvDecl - -- New definitions (terms with body and type, types with decl) - !(Defns (Map Name (Term Symbol Ann, Type Symbol Ann)) (Map Name (DeclOrBuiltin Symbol Ann))) + -- New definitions (terms with body and type, types with refId and decl) + !(Defns (Map Name (Term Symbol Ann, Type Symbol Ann)) (Map Name (TypeReferenceId, DD.Decl Symbol Ann))) -- Updated definitions: ((old term, old type), (new term, new type)) for terms, -- ((old refId, old decl), (new refId, new decl)) for types !(Defns (Map Name ((Term Symbol Ann, Type Symbol Ann), (Term Symbol Ann, Type Symbol Ann))) (Map Name ((TypeReferenceId, DD.Decl Symbol Ann), (TypeReferenceId, DD.Decl Symbol Ann)))) diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index d09916ed15..7f21ff3477 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -2654,21 +2654,24 @@ notifyUser dir issueFn = \case let ppe = PPED.suffixifiedPPE ppedNew let colorAdd = P.green . ("+ " <>) - let renderTypes :: (Pretty -> Pretty) -> Map Name (DeclOrBuiltin Symbol Ann) -> Pretty - renderTypes colored types = + -- Render new types with "+ " prefix on each line + -- Similar to renderTerms, we render multiline text for full type definitions + let renderNewTypes :: Map Name (TypeReferenceId, DD.Decl Symbol Ann) -> Pretty + renderNewTypes types = types & Map.toList & sortAlphabeticallyOn (view _1) & map - ( \(name, decl) -> - colored $ - P.syntaxToColor $ - DeclPrinter.prettyDeclOrBuiltinHeader - DeclPrinter.RenderUniqueTypeGuids'No - (HQ.fromName name) - decl + ( \(name, (refId, decl)) -> + let ref = Reference.fromId refId + typeText = + P.toPlain 80 $ + P.syntaxToColor $ + DeclPrinter.prettyDecl ppedNew DeclPrinter.RenderUniqueTypeGuids'No ref (HQ.fromName name) decl + typeLines = Text.lines typeText + in P.lines $ map (\line -> P.green $ P.text $ "+ " <> line) typeLines ) - & P.lines + & P.sepNonEmpty "\n" -- Render new terms with "+ " prefix on each line -- Note: We use prettyBindingForDiff which renders multiline text with actual newlines @@ -2769,7 +2772,7 @@ notifyUser dir issueFn = \case then P.linesNonEmpty [ P.wrap "New definitions:", - if Map.null newDefns.types then mempty else P.indentN 2 $ renderTypes colorAdd newDefns.types, + if Map.null newDefns.types then mempty else P.indentN 2 $ renderNewTypes newDefns.types, if Map.null newDefns.terms then mempty else P.indentN 2 $ renderTerms newDefns.terms ] else mempty, diff --git a/unison-src/transcripts/idempotent/diff-update.md b/unison-src/transcripts/idempotent/diff-update.md index ccee2b1318..bbf22b5ee7 100644 --- a/unison-src/transcripts/idempotent/diff-update.md +++ b/unison-src/transcripts/idempotent/diff-update.md @@ -150,6 +150,74 @@ scratch/main> update Done. ``` +## Test diff.update with a new type + +Let's test adding a brand new type (not modifying an existing one) to see if diff.update +shows the full type structure or just the type name: + +``` unison +structural type Person = { name : Text, age : Nat } + +unique ability Counter where + increment : Nat + getCount : Nat +``` + +``` ucm :added-by-ucm + Loading changes detected in scratch.u. + + + ability Counter + + structural type Person + + + Person.age : Person -> Nat + + Person.age.modify : (Nat ->{g} Nat) -> Person ->{g} Person + + Person.age.set : Nat -> Person -> Person + + Person.name : Person -> Text + + Person.name.modify : (Text ->{g} Text) + -> Person + ->{g} Person + + Person.name.set : Text -> Person -> Person + + Run `update` to apply these changes to your codebase. +``` + +Running `diff.update` should show the new type with its full structure: + +``` ucm +scratch/main> diff.update + + Preview of changes that would be made by `update`: + + New definitions: + + ability Counter where + + increment : {Counter} Nat + + getCount : {Counter} Nat + + structural type Person = { name : Text, age : Nat } + + Person.age : Person -> Nat + + Person.age = cases Person _ age -> age + + Person.age.modify : (Nat ->{g} Nat) -> Person ->{g} Person + + Person.age.modify f = cases Person name age -> Person name (f age) + + Person.age.set : Nat -> Person -> Person + + Person.age.set age1 = cases Person name _ -> Person name age1 + + Person.name : Person -> Text + + Person.name = cases Person name _ -> name + + Person.name.modify : (Text ->{g} Text) -> Person ->{g} Person + + Person.name.modify f = cases Person name age -> Person (f name) age + + Person.name.set : Text -> Person -> Person + + Person.name.set name1 = cases Person _ age -> Person name1 age + + Run `update` to apply these changes. +``` + +``` ucm +scratch/main> update + + Okay, I'm searching the branch for code that needs to be + updated... + + Done. +``` + ## Test diff.update with a modified type Let's add a type to the codebase: