Skip to content

Commit

Permalink
Port to hnix-0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 31, 2023
1 parent 78133d1 commit 8f0da09
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages: ./*.cabal
optimization: 2
allow-newer: all:base, all:ghc-prim, hnix:template-haskell
allow-newer: all:base, all:ghc-prim, hnix:template-haskell, lens-family-th:template-haskell
4 changes: 2 additions & 2 deletions src/Nix/Comments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ annotateWithComments sourceLines = go

go' :: NExprLocF f -> NExprCommentsF f
go' e =
let comment = case spanEnd . annotation . getCompose $ e of
SourcePos _ line col -> do
let comment = case getSpanEnd . annotation . getCompose $ e of
NSourcePos _ (NPos line) (NPos col) -> do
theLine <- sourceLines !? (unPos line - 1)
theLineAfterExpression <- dropMaybe (unPos col - 1) theLine
let theLineAfterCruft =
Expand Down
6 changes: 3 additions & 3 deletions src/Update/Nix/FetchGit/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ formatWarning (DuplicateAttrs attrName) =
"Error: The \"" <> attrName <> "\" attribute appears twice in a set."
formatWarning (NotAString expr) =
"Error: The expression at "
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
<> " is not a string literal."
formatWarning (NotABool expr) =
"Error: The expression at "
<> (T.pack . prettyPrintSourcePos . spanBegin . exprSpan) expr
<> (T.pack . prettyPrintSourcePos . getSpanBegin . exprSpan) expr
<> " is not a boolean literal."
formatWarning (NixPrefetchGitFailed exitCode errorOutput) =
"Error: nix-prefetch-git failed with exit code "
Expand Down Expand Up @@ -185,7 +185,7 @@ tShow = T.pack . show

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

----------------------------------------------------------------
Expand Down
20 changes: 12 additions & 8 deletions src/Update/Span.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Update.Span
( SpanUpdate(..)
, SrcSpan(..)
, SourcePos(..)
, NSourcePos(..)
, updateSpan
, updateSpans
, linearizeSourcePos
Expand All @@ -25,7 +25,11 @@ import Data.Text ( Text
, lines
, splitAt
)
import Nix.Expr.Types.Annotated
import Nix.Expr.Types ( NPos(..)
, NSourcePos(..)
, unPos
)
import Nix.Expr.Types.Annotated ( SrcSpan(..) )
import Prelude hiding ( length
, lines
, splitAt
Expand All @@ -42,7 +46,7 @@ data SpanUpdate = SpanUpdate
-- | Update many spans in a file. They must be non-overlapping.
updateSpans :: [SpanUpdate] -> Text -> Text
updateSpans us t =
let sortedSpans = sortOn (spanBegin . spanUpdateSpan) us
let sortedSpans = sortOn (getSpanBegin . spanUpdateSpan) us
anyOverlap =
any (uncurry overlaps) (zip <*> tail $ spanUpdateSpan <$> sortedSpans)
in assert (not anyOverlap) (foldr updateSpan t sortedSpans)
Expand All @@ -60,9 +64,9 @@ overlaps :: SrcSpan -> SrcSpan -> Bool
overlaps (SrcSpan b1 e1) (SrcSpan b2 e2) =
b2 >= b1 && b2 < e1 || e2 >= b1 && e2 < e1

-- | Split some text at a particular 'SourcePos'
split :: SourcePos -> Text -> (Text, Text)
split (SourcePos _ row col) t = splitAt
-- | Split some text at a particular 'NSourcePos'
split :: NSourcePos -> Text -> (Text, Text)
split (NSourcePos _ (NPos row) (NPos col)) t = splitAt
(fromIntegral
(linearizeSourcePos t
(fromIntegral (unPos row - 1))
Expand All @@ -84,6 +88,6 @@ linearizeSourcePos t l c = fromIntegral lineCharOffset + c
where
lineCharOffset = sum . fmap ((+ 1) . length) . genericTake l . lines $ t

prettyPrintSourcePos :: SourcePos -> String
prettyPrintSourcePos (SourcePos _ row column) =
prettyPrintSourcePos :: NSourcePos -> String
prettyPrintSourcePos (NSourcePos _ (NPos row) (NPos column)) =
show (unPos row) <> ":" <> show (unPos column)
2 changes: 1 addition & 1 deletion update-nix-fetchgit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ library
, bytestring >=0.10
, data-fix
, github-rest >=1.1
, hnix ==0.16.*
, hnix >=0.17 && <0.18
, monad-validate
, mtl
, process >=1.2
Expand Down

0 comments on commit 8f0da09

Please sign in to comment.