diff --git a/CHANGELOG.md b/CHANGELOG.md index c14759d..36e9dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog -## WIP +## [0.2.12] - 2024-01-DD +- Changes for hnix-0.17 ## [0.2.11] - 2022-12-06 - Changes for hnix-0.16 diff --git a/Setup.hs b/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/cabal.project b/cabal.project index 9683d41..e7a3b01 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,2 @@ packages: ./*.cabal optimization: 2 -allow-newer: all:base, all:ghc-prim, hnix:template-haskell diff --git a/hnix.patch b/hnix.patch deleted file mode 100644 index 78ac22c..0000000 --- a/hnix.patch +++ /dev/null @@ -1,82 +0,0 @@ -diff --git a/src/Nix/Parser.hs b/src/Nix/Parser.hs -index 0a820b8..7e0a4d2 100644 ---- a/src/Nix/Parser.hs -+++ b/src/Nix/Parser.hs -@@ -609,9 +609,10 @@ annotateLocation :: Parser a -> Parser (Ann SrcSpan a) - annotateLocation p = - do - begin <- getSourcePos -+ res <- p - end <- get -- The state set before the last whitespace - -- Ann (SrcSpan begin end) <$> p -+ pure $ Ann (SrcSpan begin end) res - - annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc - annotateLocation1 = fmap annToAnnF . annotateLocation -diff --git a/tests/ParserTests.hs b/tests/ParserTests.hs -index 0b50cf6..5720999 100644 ---- a/tests/ParserTests.hs -+++ b/tests/ParserTests.hs -@@ -357,6 +357,42 @@ in null|] [text|let - in (matcher.case or null).foo (v.case); - in null|] - -+case_simpleLoc = -+ let -+ mkSPos l c = SourcePos "" (mkPos l) (mkPos c) -+ mkSpan l1 c1 l2 c2 = SrcSpan (mkSPos l1 c1) (mkSPos l2 c2) -+ in -+ assertParseTextLoc [text|let -+ foo = bar -+ baz "qux"; -+ in foo -+ |] -+ (Fix -+ (NLet_ -+ (mkSpan 1 1 4 7) -+ [ NamedVar -+ (StaticKey "foo" :| []) -+ (Fix -+ (NBinary_ -+ (mkSpan 2 7 3 15) -+ NApp -+ (Fix -+ (NBinary_ (mkSpan 2 7 3 9) -+ NApp -+ (Fix (NSym_ (mkSpan 2 7 2 10) "bar")) -+ (Fix (NSym_ (mkSpan 3 6 3 9) "baz")) -+ ) -+ ) -+ (Fix (NStr_ (mkSpan 3 10 3 15) (DoubleQuoted [Plain "qux"]))) -+ ) -+ ) -+ (mkSPos 2 1) -+ ] -+ (Fix (NSym_ (mkSpan 4 4 4 7) "foo")) -+ ) -+ ) -+ -+ - tests :: TestTree - tests = $testGroupGenerator - -@@ -375,6 +411,18 @@ assertParseText str expected = - ) - (parseNixText str) - -+assertParseTextLoc :: Text -> NExprLoc -> Assertion -+assertParseTextLoc str expected = -+ either -+ (\ err -> -+ assertFailure $ toString $ "Unexpected fail parsing `" <> str <> "':\n" <> show err -+ ) -+ (assertEqual -+ ("When parsing " <> toString str) -+ expected -+ ) -+ (parseNixTextLoc str) -+ - assertParseFile :: FilePath -> NExpr -> Assertion - assertParseFile file expected = - do diff --git a/nixpkgs.nix b/nixpkgs.nix index 1d44497..22740a4 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -1,8 +1,8 @@ let nixpkgsSrc = builtins.fetchTarball { url = - "https://github.com/NixOS/nixpkgs/archive/d7af8ae032b081ab01461be06838ba5ea89110f1.tar.gz"; # haskell-updates - sha256 = "1n6ky9lczwh2dk2q0ckdv4wm096q1syk2pddrhidj1vy34aigpxd"; + "https://github.com/NixOS/nixpkgs/archive/50d354db00061ebfc6992b6040e81e7bfbedd473.tar.gz"; # haskell-updates + sha256 = "08i444lcs8m8kby1hcylbddlllyyh3dnxvy6lv0sicbymra4jw7z"; }; in import nixpkgsSrc { } diff --git a/src/Nix/Comments.hs b/src/Nix/Comments.hs index b31983f..808ddfc 100644 --- a/src/Nix/Comments.hs +++ b/src/Nix/Comments.hs @@ -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 = diff --git a/src/Update/Nix/FetchGit/Prefetch.hs b/src/Update/Nix/FetchGit/Prefetch.hs index 02942d5..763a622 100644 --- a/src/Update/Nix/FetchGit/Prefetch.hs +++ b/src/Update/Nix/FetchGit/Prefetch.hs @@ -144,7 +144,7 @@ getGitHubRevisionDate owner repo revision = do ghState :: GitHubSettings ghState = GitHubSettings { token = Nothing , userAgent = "expipiplus1/update-nix-fetchgit" - , apiVersion = "v3" + , apiVersion = "2022-11-28" } ---------------------------------------------------------------- diff --git a/src/Update/Nix/FetchGit/Utils.hs b/src/Update/Nix/FetchGit/Utils.hs index c05c946..562ee21 100644 --- a/src/Update/Nix/FetchGit/Utils.hs +++ b/src/Update/Nix/FetchGit/Utils.hs @@ -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 " @@ -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 ---------------------------------------------------------------- diff --git a/src/Update/Span.hs b/src/Update/Span.hs index 9eacd67..53a0c33 100644 --- a/src/Update/Span.hs +++ b/src/Update/Span.hs @@ -6,7 +6,7 @@ module Update.Span ( SpanUpdate(..) , SrcSpan(..) - , SourcePos(..) + , NSourcePos(..) , updateSpan , updateSpans , linearizeSourcePos @@ -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 @@ -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) @@ -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)) @@ -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) diff --git a/update-nix-fetchgit.cabal b/update-nix-fetchgit.cabal index 8552cb7..ce0df1a 100644 --- a/update-nix-fetchgit.cabal +++ b/update-nix-fetchgit.cabal @@ -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