Skip to content

Relative filepath in Template Haskell different in HLS from Stack #481

Closed
@Vlix

Description

@Vlix

Subject of the issue

When having sub-libraries in a stack project, relative filepaths used in Template Haskell expressions are parsed as if they were run from the root directory of the project, but stack itself parses it relatively from the sub-library's root (which is one directory deeper).

For example:

import Data.Yaml (Value)
import Data.Yaml.TH (decodeFile)

val :: Value
val = $$(decodeFile "config/value.yaml")

Given the TH is used in ./lib/src/Lib.hs with the stack.yaml at ./stack.yaml and the lib.cabal at ./lib/lib.cabal, HLS will want the relative path to be "lib/config/value.yaml", where stack itself wants it to be "config/value.yml"

Your environment

$ haskell-language-server-0.5.0-linux-8.8.4 --probe-tools
haskell-language-server version: 0.5.0.0 (GHC: 8.8.4) (PATH: /home/fpaulusma/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4) (GIT hash: 14497f2503a2a0d389fabf3b146d674b9af41a34)
Tool versions found on the $PATH
cabal:    3.0.0.0
stack:    2.3.3
ghc:    8.0.2

I tried this on VS Code with just the Haskell plugin installed

$ cat stack.yaml
resolver: lts-16.17

packages:
- lib
$ cat lib/lib.cabal
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.33.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 643499591d6ce6070d19763e325b50c6e2d76cbf091125bdf17e6c9a8d421ad9

name:           lib
version:        0.1.0.0
description:    Please see the README on GitHub at <https://github.com/githubuser/test#readme>
homepage:       https://github.com/githubuser/test#readme
bug-reports:    https://github.com/githubuser/test/issues
author:         Author name here
maintainer:     [email protected]
copyright:      2020 Author name here
license:        BSD3
license-file:   LICENSE
build-type:     Simple
extra-source-files:
    README.md
    ChangeLog.md

source-repository head
  type: git
  location: https://github.com/githubuser/lib

library
  exposed-modules:
      Lib
  other-modules:
      Paths_test
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
    , yaml
  default-language: Haskell2010

executable test-exe
  main-is: Main.hs
  other-modules:
      Paths_test
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , test
  default-language: Haskell2010

test-suite test-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_test
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , test
  default-language: Haskell2010

Steps to reproduce

Use this repo

Expected behaviour

I expect HLS to just compile the package

Actual behaviour

HLS gives an error that the file ({root}/lib/config/value.yaml) can't be found with relative path "config/value.yaml", even though it compiles fine with stack build. It will build with "lib/config/value.yaml", but then stack build fails to compile.

Include debug information

Debug output:
$ /home/myhome/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4 --debug .
haskell-language-server version: 0.5.0.0 (GHC: 8.8.4) (PATH: /home/myhome/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4) (GIT hash: 14497f2503a2a0d389fabf3b146d674b9af41a34)
(haskell-language-server)Ghcide setup tester in /home/myhome/code/test.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Tool versions found on the $PATH
cabal:    3.0.0.0
stack:    2.3.3
ghc:    8.0.2


Step 1/4: Finding files to test in /home/myhome/code/test
Found 4 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
[INFO] Consulting the cradle for "lib/Setup.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/Setup.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
File:     /home/myhome/code/test/lib/Setup.hs
Hidden:   no
Range:    1:0-2:0
Source:   cradle
Severity: DsError
Message:
  Multi Cradle: No prefixes matched
  pwd: /home/myhome/code/test
  filepath: /home/myhome/code/test/lib/Setup.hs
  prefixes:
  ("lib/src",Stack {component = Just "lib:lib", stackYaml = Nothing})
  ("lib/app/Main.hs",Stack {component = Just "lib:exe:test-exe", stackYaml = Nothing})
  ("lib/app/Paths_test.hs",Stack {component = Just "lib:exe:test-exe", stackYaml = Nothing})
  ("lib/test",Stack {component = Just "lib:test:test-test", stackYaml = Nothing})
[INFO] Consulting the cradle for "lib/app/Main.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/app/Main.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> Using main module: 1. Package `lib' component lib:exe:test-exe with main-is file: /home/myhome/code/test/lib/app/Main.hs
> The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
> Configuring GHCi with the following packages: lib
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/.stack-work/install/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/snapshots/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/programs/x86_64-linux/ghc-8.8.4/lib/ghc-8.8.4/package.conf.d
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-e56f5f10e255ef74c8262586c777b8720af43c9c
[INFO] Making new HscEnv[main]
[INFO] Consulting the cradle for "lib/test/Spec.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/test/Spec.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> Using main module: 1. Package `lib' component lib:test:test-test with main-is file: /home/myhome/code/test/lib/test/Spec.hs
> lib> configure (lib + test)
> Configuring lib-0.1.0.0...
> lib> initial-build-steps (lib + test)
> lib> Test running disabled by --no-run-tests flag.
> Completed 2 action(s).
> The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
> Configuring GHCi with the following packages: lib
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/.stack-work/install/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/snapshots/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/programs/x86_64-linux/ghc-8.8.4/lib/ghc-8.8.4/package.conf.d
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-571a0d71e220d3f38e32a126cede89eec54d7b5c
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-571a0d71e220d3f38e32a126cede89eec54d7b5c
[INFO] Making new HscEnv[main,main]
[INFO] Consulting the cradle for "lib/Setup.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/Setup.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
[INFO] Consulting the cradle for "lib/src/Lib.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/src/Lib.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> Configuring GHCi with the following packages: lib
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/.stack-work/install/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/snapshots/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/programs/x86_64-linux/ghc-8.8.4/lib/ghc-8.8.4/package.conf.d
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-6ff17596e79d45dfaf842cbef3cbb8111eee8688
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-6ff17596e79d45dfaf842cbef3cbb8111eee8688
[INFO] Using interface files cache dir: /home/myhome/.cache/ghcide/main-6ff17596e79d45dfaf842cbef3cbb8111eee8688
[INFO] Making new HscEnv[main,main,main]
[INFO] Consulting the cradle for "lib/Setup.hs"
NotShowMessage (NotificationMessage {_jsonrpc = "2.0", _method = WindowShowMessage, _params = ShowMessageParams {_xtype = MtWarning, _message = "No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for lib/Setup.hs.\n Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie)"}})
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
File:     /home/myhome/code/test/lib/src/Lib.hs
Hidden:   no
Range:    9:9-9:39
Source:   typecheck
Severity: DsError
Message:
  • Exception when trying to run compile-time code:
  InvalidYaml (Just (YamlException "Yaml file not found: config/value.yaml"))
  Code: decodeFile "config/value.yaml"
  • In the Template Haskell splice $$(decodeFile "config/value.yaml")
  In the expression: $$(decodeFile "config/value.yaml")
  In an equation for ‘val’: val = $$(decodeFile "config/value.yaml")
Files that failed:
[INFO] finish: User TypeCheck (took 0.37s) * /home/myhome/code/test/lib/Setup.hs

 * /home/myhome/code/test/lib/src/Lib.hs

Completed (2 files worked, 2 files failed)
haskell-language-server-0.5.0-linux-8.8.4: allocatestack.c:384: advise_stack_range: Assertion `freesize < size' failed.
Aborted (core dumped)

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs:
$ cat 20201009T003506/exthost1/output_logging_20201009T003509/4-Haskell\ \(test\).log
[client] run command: "/home/myhome/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4 --lsp"
[client] debug command: "/home/myhome/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4 --lsp"
[client] server cwd: undefined
haskell-language-server version: 0.5.0.0 (GHC: 8.8.4) (PATH: /home/myhome/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.0-linux-8.8.4) (GIT hash: 14497f2503a2a0d389fabf3b146d674b9af41a34)
Starting (haskell-language-server)LSP server...
  with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "brittany",PluginId "eval",PluginId "floskell",PluginId "fourmolu",PluginId "ghcide",PluginId "importLens",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /home/myhome/code/test
If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!
 Started LSP server in 0.00s
2020-10-09 00:35:09.057015669 [ThreadId 21] - Registering ide configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 6521202141690092544 "file:///home/myhome/code/test"], clientSettings = hashed Nothing}
2020-10-09 00:35:09.059753704 [ThreadId 21] - Configuration changed: Object (fromList [("haskell",Object (fromList [("logFile",String ""),("hlintOn",Bool True),("formatOnImportOn",Bool True),("indentationRules",Object (fromList [("enabled",Bool True)])),("liquidOn",Bool False),("languageServerVariant",String "haskell-language-server"),("serverExecutablePath",String ""),("diagnosticsOnChange",Bool True),("completionSnippetsOn",Bool True),("maxNumberOfProblems",Number 100.0),("formattingProvider",String "ormolu"),("trace",Object (fromList [("server",String "off")]))]))])
2020-10-09 00:35:09.060945361 [ThreadId 21] - Opened text document: file:///home/myhome/code/test/lib/src/Lib.hs
2020-10-09 00:35:09.062115332 [ThreadId 82] - Consulting the cradle for "lib/src/Lib.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/myhome/code/test", cradleOptsProg = CradleAction: Stack}
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
2020-10-09 00:35:09.317449518 [ThreadId 97] - Plugin.makeCodeLens (ideLogger)
> Configuring GHCi with the following packages: lib
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/lib/lib.cabal was modified manually. Ignoring /home/myhome/code/test/lib/package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
> /home/myhome/code/test/.stack-work/install/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/snapshots/x86_64-linux/7a5912a4290fa383fc50d4c4aaddfc9c4b5e5a20c04b4d180f4b13711ebce221/8.8.4/pkgdb:/home/myhome/.stack/programs/x86_64-linux/ghc-8.8.4/lib/ghc-8.8.4/package.conf.d
2020-10-09 00:35:10.549492833 [ThreadId 82] - Using interface files cache dir: /home/myhome/.cache/ghcide/main-6ff17596e79d45dfaf842cbef3cbb8111eee8688
2020-10-09 00:35:10.5496967 [ThreadId 82] - Making new HscEnv[main]
2020-10-09 00:35:10.987847123 [ThreadId 271] - finish: codeLens (took 0.42s)
2020-10-09 00:35:10.988256915 [ThreadId 278] - finish:  (took 0.00s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions