Skip to content

Commit

Permalink
Only emit annotation changes if it's a hash change
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Aug 8, 2024
1 parent 4c3eb03 commit bcf0ff6
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit bcf0ff6

Please sign in to comment.