Skip to content

How to make Haskell Language Server read the cabal dependencies as a comment in the script? #3465

@TheOddler

Description

@TheOddler

Your environment

Which OS do you use?
NixOS 22.11

Which version of GHC do you use and how did you install it?
9.0.2 installed using nix

Which LSP client (editor/plugin) do you use?
VS Codium+vscode-haskell

Which version of HLS do you use and how did you install it?
1.8.0.0 installed using nix

Have you configured HLS in any way (especially: a hie.yaml file)?
No

What's wrong?

I was trying to use haskell to write some small scripts, by adding a shebang at the top of the file and de dependencies as a comment at the top of the file, like this:

#! /usr/bin/env nix-shell
#! nix-shell -i cabal -p ghc cabal-install

{- cabal:
build-depends:
  , base ^>= 4.15
  , elm-syntax
-}

import Language.Elm.Expression as Elm

main :: IO ()
main = do
  putStrLn "Hello"

If I then make the file executable (chmod +x ...) it runs as expected (showing Hello).

However, in my editor (VS Code) I get the error Could not find module ‘Language.Elm.Expression’.

Is there a way to tell the Haskell Language Server to read those build-depends in the comment at the top of the file?
I'm not sure what to call that comment, so Googling didn't help, but probably just because I don't know what to call it.

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