Skip to content

Commit

Permalink
Merge branch 'trunk' into 24-08-01-merge-api
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani committed Aug 13, 2024
2 parents 1741ffb + 2187b2e commit ed555a3
Show file tree
Hide file tree
Showing 7 changed files with 2,943 additions and 11 deletions.
18 changes: 15 additions & 3 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,11 @@ getProjectReflog numEntries projectId =
SELECT project_id, project_branch_id, time, from_root_causal_id, to_root_causal_id, reason
FROM project_branch_reflog
WHERE project_id = :projectId
ORDER BY time DESC
ORDER BY
time DESC,
-- Strictly for breaking ties in transcripts with the same time,
-- this will break ties in the correct order, sorting later inserted rows first.
ROWID DESC
LIMIT :numEntries
|]

Expand All @@ -3512,7 +3516,11 @@ getProjectBranchReflog numEntries projectBranchId =
SELECT project_id, project_branch_id, time, from_root_causal_id, to_root_causal_id, reason
FROM project_branch_reflog
WHERE project_branch_id = :projectBranchId
ORDER BY time DESC
ORDER BY
time DESC,
-- Strictly for breaking ties in transcripts with the same time,
-- this will break ties in the correct order, sorting later inserted rows first.
ROWID DESC
LIMIT :numEntries
|]

Expand All @@ -3523,7 +3531,11 @@ getGlobalReflog numEntries =
[sql|
SELECT project_id, project_branch_id, time, from_root_causal_id, to_root_causal_id, reason
FROM project_branch_reflog
ORDER BY time DESC
ORDER BY
time DESC,
-- Strictly for breaking ties in transcripts with the same time,
-- this will break ties in the correct order, sorting later inserted rows first.
ROWID DESC
LIMIT :numEntries
|]

Expand Down
3 changes: 2 additions & 1 deletion unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Unison.Codebase.Editor.HandleInput.Update2
)
where

import Control.Lens (mapped)
import Control.Lens (mapped, (.=))
import Control.Monad.Reader.Class (ask)
import Data.Bifoldable (bifoldMap)
import Data.Foldable qualified as Foldable
Expand Down Expand Up @@ -167,6 +167,7 @@ handleUpdate2 = do
(\typeName -> Right (Map.lookup typeName declNameLookup.declToConstructors))
secondTuf
Cli.stepAt "update" (path, Branch.batchUpdates branchUpdates)
#latestTypecheckedFile .= Nothing

Cli.respond Output.Success

Expand Down
14 changes: 13 additions & 1 deletion unison-share-api/src/Unison/Server/Backend/DefinitionDiff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,17 @@ diffSyntaxText (AnnotatedText fromST) (AnnotatedText toST) =
detectSpecialCase fromSegment toSegment
| fromSegment == toSegment = Left fromSegment
| AT.annotation fromSegment == AT.annotation toSegment = Right (SegmentChange (AT.segment fromSegment, AT.segment toSegment) (AT.annotation fromSegment))
| AT.segment fromSegment == AT.segment toSegment = Right (AnnotationChange (AT.segment fromSegment) (AT.annotation fromSegment, AT.annotation toSegment))
-- We only emit an annotation change if it's a change in just the hash of the element (optionally the KIND of hash reference can change too).
| AT.segment fromSegment == AT.segment toSegment,
Just _fromHash <- AT.annotation fromSegment >>= elementHash,
Just _toHash <- AT.annotation toSegment >>= elementHash =
Right (AnnotationChange (AT.segment fromSegment) (AT.annotation fromSegment, AT.annotation toSegment))
| otherwise = error "diffSyntaxText: found Syntax Elements in 'both' which have nothing in common."
where
elementHash :: Syntax.Element -> Maybe Syntax.UnisonHash
elementHash = \case
Syntax.TypeReference hash -> Just hash
Syntax.TermReference hash -> Just hash
Syntax.DataConstructorReference hash -> Just hash
Syntax.AbilityConstructorReference hash -> Just hash
_ -> Nothing
41 changes: 40 additions & 1 deletion unison-src/transcripts/definition-diff-api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
```ucm
diffs/main> builtins.merge
diffs/main> builtins.mergeio lib.builtins
diffs/main> alias.term lib.builtins.Nat.gt lib.builtins.Nat.>
diffs/main> alias.term lib.builtins.Nat.drop lib.builtins.Nat.-
```

```unison
Expand All @@ -8,6 +10,20 @@ term =
1 + 1
type Type = Type Nat
ability Stream a where
emit : a -> ()
take n s =
use Nat > -
h n = cases
{ emit a -> k } -> if n > 0
then
emit a
handle k() with h (n - 1)
else None
{ r } -> Some r
handle s() with h n
```

```ucm
Expand All @@ -21,6 +37,22 @@ term =
1 + 2
type Type a = Type a Text
ability Stream a where
emit : a -> ()
take n s =
use Nat > -
h n = cases
{ emit a -> k } ->
emit a
if n > 0
then handle k() with h (n - 1)
else None
{ r } -> Some r
if n > 0
then handle s () with h (n - 1)
else None
```

```ucm
Expand All @@ -33,6 +65,13 @@ Diff terms
GET /api/projects/diffs/diff/terms?oldBranchRef=main&newBranchRef=new&oldTerm=term&newTerm=term
```

More complex diff

```api
GET /api/projects/diffs/diff/terms?oldBranchRef=main&newBranchRef=new&oldTerm=take&newTerm=take
```


Diff types

```api
Expand Down
Loading

0 comments on commit ed555a3

Please sign in to comment.