0

I am playing around with the integration of the haskell language server and VsCode. More specifically, I'm going all around to understand the behavior of the HLS.

I have understood so far how it works in the following scenario

  • Opening a stack project

  • Opening a cabal Project

  • Having to generate a hie file if the cabal file is too old. (I have done it manually and i have used gen-hie as well)

What puzzles me is the behavior when opening a project with some standalone haskell file i.e. not part of a cabal or stack project.

As a an example i created a folder with a Test.hs file in it and opened it with VsCode, everything works. It is the output that i do not understand.

[Info  - 10:50:14 PM] Starting server
[Info  - 10:50:14 PM] Started LSP server in 0.00s
[Info  - 10:50:14 PM] Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 5126163944652757563 "file:///Users/maatari/Dev/VScode/haskell-no-project-bare"], clientSettings = hashed Nothing}
2023-04-17T21:50:14.357737Z | Info | Cradle path: Test.hs
2023-04-17T21:50:14.357932Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for Test.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
[Info  - 10:50:14 PM] Cradle path: Test.hs
[Warn  - 10:50:14 PM] No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for Test.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2023-04-17T21:50:14.378890Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
[Info  - 10:50:14 PM] invoking build tool to determine build flags (this may take some time depending on the cache)
2023-04-17T21:50:14.550243Z | Info | Interface files cache directory: /Users/******/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda
2023-04-17T21:50:14.550558Z | Info | Making new HscEnv. In-place unit ids: [main]
[Info  - 10:50:14 PM] Interface files cache directory: /Users/*****/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda

So if no craddle is found, how does Vscode/LSH manage to work anyway ?

I try to emulate the situation, by using gen-hie in that scenario, but obviously as the doc says, it default to expecting a cabal file and fails.

Hence my question is, what magic is happening behind the scene when opening a project with no package manager, but only standalone hs files. Why does it work and how does it work ?

IS there a specific global configuration that is being used here. For instance with stack we know we have an implicit global project. But the documentation does not says that stack should be in the path for standalone to work. It only says:

Prerequisites (https://haskell-language-server.readthedocs.io/en/latest/installation.html#prerequisites)

For standalone .hs/.lhs files, ghc must be installed and on the PATH. The easiest way to >install it is with ghcup or chocolatey on Windows.

MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
  • 1
    I don't know much in the way of details, but I would assume that the only reason HLS *needs* cradles, project layout, etc, is because it has to know about what dependencies you're using, and any settings you have in project files that affect how source files should be compiled (e.g. `default-extensions`, warning options, etc). If all you have are standalone files, then you're just using whatever libs are in your GHC install so HLS can just use those, and any compilation-altering settings would have to appear in pragmas in the source files where HLS can see them on a file-by-file basis. – Ben Apr 18 '23 at 01:06
  • Your question about whether there is a global configuration like stack has, makes it seem like you are asking about the behavior of GHC in general and not about how HLS uses GHC in particular. Is that right? – Noughtmare Apr 19 '23 at 08:53
  • I guess you can frame it that way, because from the previous answer, this is what i understand now is happening indeed ..... – MaatDeamon Apr 19 '23 at 13:24

0 Answers0