Skip to content

Commit 8f0da09

Browse files
committed
Port to hnix-0.17
1 parent 78133d1 commit 8f0da09

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
packages: ./*.cabal
22
optimization: 2
3-
allow-newer: all:base, all:ghc-prim, hnix:template-haskell
3+
allow-newer: all:base, all:ghc-prim, hnix:template-haskell, lens-family-th:template-haskell

src/Nix/Comments.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ annotateWithComments sourceLines = go
4646

4747
go' :: NExprLocF f -> NExprCommentsF f
4848
go' e =
49-
let comment = case spanEnd . annotation . getCompose $ e of
50-
SourcePos _ line col -> do
49+
let comment = case getSpanEnd . annotation . getCompose $ e of
50+
NSourcePos _ (NPos line) (NPos col) -> do
5151
theLine <- sourceLines !? (unPos line - 1)
5252
theLineAfterExpression <- dropMaybe (unPos col - 1) theLine
5353
let theLineAfterCruft =

src/Update/Nix/FetchGit/Utils.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ formatWarning (DuplicateAttrs attrName) =
145145
"Error: The \"" <> attrName <> "\" attribute appears twice in a set."
146146
formatWarning (NotAString expr) =
147147
"Error: The expression at "
148-
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
148+
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
149149
<> " is not a string literal."
150150
formatWarning (NotABool expr) =
151151
"Error: The expression at "
152-
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
152+
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
153153
<> " is not a boolean literal."
154154
formatWarning (NixPrefetchGitFailed exitCode errorOutput) =
155155
"Error: nix-prefetch-git failed with exit code "
@@ -185,7 +185,7 @@ tShow = T.pack . show
185185

186186
containsPosition :: NExprLoc -> (Int, Int) -> Bool
187187
containsPosition (Fix (Compose (AnnUnit (SrcSpan begin end) _))) p =
188-
let unSourcePos (SourcePos _ l c) = (unPos l, unPos c)
188+
let unSourcePos (NSourcePos _ (NPos l) (NPos c)) = (unPos l, unPos c)
189189
in p >= unSourcePos begin && p < unSourcePos end
190190

191191
----------------------------------------------------------------

src/Update/Span.hs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module Update.Span
77
( SpanUpdate(..)
88
, SrcSpan(..)
9-
, SourcePos(..)
9+
, NSourcePos(..)
1010
, updateSpan
1111
, updateSpans
1212
, linearizeSourcePos
@@ -25,7 +25,11 @@ import Data.Text ( Text
2525
, lines
2626
, splitAt
2727
)
28-
import Nix.Expr.Types.Annotated
28+
import Nix.Expr.Types ( NPos(..)
29+
, NSourcePos(..)
30+
, unPos
31+
)
32+
import Nix.Expr.Types.Annotated ( SrcSpan(..) )
2933
import Prelude hiding ( length
3034
, lines
3135
, splitAt
@@ -42,7 +46,7 @@ data SpanUpdate = SpanUpdate
4246
-- | Update many spans in a file. They must be non-overlapping.
4347
updateSpans :: [SpanUpdate] -> Text -> Text
4448
updateSpans us t =
45-
let sortedSpans = sortOn (spanBegin . spanUpdateSpan) us
49+
let sortedSpans = sortOn (getSpanBegin . spanUpdateSpan) us
4650
anyOverlap =
4751
any (uncurry overlaps) (zip <*> tail $ spanUpdateSpan <$> sortedSpans)
4852
in assert (not anyOverlap) (foldr updateSpan t sortedSpans)
@@ -60,9 +64,9 @@ overlaps :: SrcSpan -> SrcSpan -> Bool
6064
overlaps (SrcSpan b1 e1) (SrcSpan b2 e2) =
6165
b2 >= b1 && b2 < e1 || e2 >= b1 && e2 < e1
6266

63-
-- | Split some text at a particular 'SourcePos'
64-
split :: SourcePos -> Text -> (Text, Text)
65-
split (SourcePos _ row col) t = splitAt
67+
-- | Split some text at a particular 'NSourcePos'
68+
split :: NSourcePos -> Text -> (Text, Text)
69+
split (NSourcePos _ (NPos row) (NPos col)) t = splitAt
6670
(fromIntegral
6771
(linearizeSourcePos t
6872
(fromIntegral (unPos row - 1))
@@ -84,6 +88,6 @@ linearizeSourcePos t l c = fromIntegral lineCharOffset + c
8488
where
8589
lineCharOffset = sum . fmap ((+ 1) . length) . genericTake l . lines $ t
8690

87-
prettyPrintSourcePos :: SourcePos -> String
88-
prettyPrintSourcePos (SourcePos _ row column) =
91+
prettyPrintSourcePos :: NSourcePos -> String
92+
prettyPrintSourcePos (NSourcePos _ (NPos row) (NPos column)) =
8993
show (unPos row) <> ":" <> show (unPos column)

update-nix-fetchgit.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ library
108108
, bytestring >=0.10
109109
, data-fix
110110
, github-rest >=1.1
111-
, hnix ==0.16.*
111+
, hnix >=0.17 && <0.18
112112
, monad-validate
113113
, mtl
114114
, process >=1.2

0 commit comments

Comments
 (0)