From 31ec8de65672e45dfdb2ae430569684c539f11fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20Bayramo=C4=9Flu?= Date: Tue, 8 Aug 2023 10:02:26 +0200 Subject: [PATCH] HLS integration fixes for the chainweb-data codebase (#157) This PR adds a `hie.yaml` to the project and also works around the following HLS bug: https://github.com/haskell/haskell-language-server/issues/481 That issue is actually related to stack, but seems like the cabal integration is suffering from the same in our case. There are quite a few relative-path related issues open in HLS anyway. This commit uses the `makeRelativeToProject` function from file-embed ([As suggested by phadej under another issue](https://github.com/commercialhaskell/stack/issues/5421#issuecomment-737110569)) in order to resolve the relative paths in a way that's independent of the build system, working around this long-standing HLS bug. * Add a hie.yaml to the project * Work around HLS bug while embedding files This commit works around the following HLS bug: https://github.com/haskell/haskell-language-server/issues/481 That issue is actually related to stack, but seems like the cabal integration is suffering from the same in our case. There are quite a few relative-path related issue open HLS anyway. This commit uses the `makeRelativeToProject` function from file-embed in order to resolve the relative paths in a way that's independent of the build system, working around this long-standing HLS bug. --- haskell-src/exec/Chainweb/Coins.hs | 4 ++-- haskell-src/exec/Main.hs | 4 ++-- hie.yaml | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 hie.yaml diff --git a/haskell-src/exec/Chainweb/Coins.hs b/haskell-src/exec/Chainweb/Coins.hs index d57bf3c1..4fa46e2a 100644 --- a/haskell-src/exec/Chainweb/Coins.hs +++ b/haskell-src/exec/Chainweb/Coins.hs @@ -37,11 +37,11 @@ import Text.Read -- | Read in the reward csv via TH for deployment purposes. -- rawMinerRewards :: ByteString -rawMinerRewards = $(embedFile "data/miner_rewards.csv") +rawMinerRewards = $(makeRelativeToProject "data/miner_rewards.csv" >>= embedFile) {-# NOINLINE rawMinerRewards #-} rawAllocations :: ByteString -rawAllocations = $(embedFile "data/token_payments.csv") +rawAllocations = $(makeRelativeToProject "data/token_payments.csv" >>= embedFile) allocations :: [AllocationEntry] allocations = V.toList $ decodeAllocations rawAllocations diff --git a/haskell-src/exec/Main.hs b/haskell-src/exec/Main.hs index 0f57658c..69398c82 100644 --- a/haskell-src/exec/Main.hs +++ b/haskell-src/exec/Main.hs @@ -118,10 +118,10 @@ main = do CheckSchema _ level -> level migrationFiles :: [(FilePath, BS.ByteString)] -migrationFiles = $(embedDir "db-schema/migrations") +migrationFiles = $(makeRelativeToProject "db-schema/migrations" >>= embedDir) initSql :: BS.ByteString -initSql = $(embedFile "db-schema/init.sql") +initSql = $(makeRelativeToProject "db-schema/init.sql" >>= embedFile) runMigrations :: P.Pool Connection -> diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 00000000..16a7d288 --- /dev/null +++ b/hie.yaml @@ -0,0 +1,5 @@ +cradle: + cabal: + - path: "haskell-src" + component: "lib:chainweb-data" +