-
-
Notifications
You must be signed in to change notification settings - Fork 399
Closed
Labels
component: ghcidetype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Description
Which OS do you use?
MacOS
Which version of GHC do you use and how did you install it?
GHC 9.10.1 with ghcup
How is your project built (alternative: link to the project)?
cabal build
Which LSP client (editor/plugin) do you use?
emacs+eglot
Which version of HLS do you use and how did you install it?
haskell-language-server 2.9.0.1 with ghcup
Steps to reproduce
When using autogenerated Paths_<pkgname>
module from Cabal to read project files from a template haskell function, HLS reports an error diagnostic at the splice sites that use this function.
Reproducing project
project.cabal
cabal-version: 3.0
name: project
version: 0.1.0.0
license: MIT
license-file: LICENSE
author: NeuroCorgi
build-type: Simple
executable project
main-is: Main.hs
other-modules: TH
Paths_project
autogen-modules: Paths_project
build-depends: base, template-haskell
hs-source-dirs: src
default-language: Haskell2010
src/Main.hs
{-# LANGUAGE TemplateHaskell #-}
import TH
main :: IO ()
main = putStrLn $(embedFileFromProject "src/TH.hs")
src/TH.hs
module TH where
import System.IO
import Language.Haskell.TH
import qualified Paths_project as Paths
embedFileFromProject :: FilePath -> ExpQ
embedFileFromProject filePath = stringE =<< (runIO $ contents =<< Paths.getDataFileName filePath)
where contents path = withFile path ReadMode hGetContents'
Expected behaviour
No diagnostic reported.
Actual behaviour
Diagnostic reported at the template haskell splice in src/Main.hs
:
• Exception when trying to run compile-time code:
/Users/neurocorgi/.cabal/share/aarch64-osx-ghc-9.10.1-64dd/project-0.1.0.0/src/TH.hs: withFile: does not exist (No such file or directory)
Code: (embedFileFromProject "src/TH.hs")
• In the untyped splice: $(embedFileFromProject "src/TH.hs")
Metadata
Metadata
Assignees
Labels
component: ghcidetype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
fendor commentedon Jun 4, 2025
Hi, thank you for your bug report!
I think your example isn't quite correct, for example,
cabal install
fails with the error message:You can have a look at https://hackage.haskell.org/package/file-embed-0.0.16.0/docs/src/Data.FileEmbed.html#embedFileRelative, which makes sure to change to the root directory before running the TH code.
michaelpj commentedon Jul 9, 2025
This is a known issue, you have to use the
makeRelativeToProject
functions fromfile-embed
if you want it to work reliably, as the working directory for TH code is not specified and can vary.