I am trying to use the Haskell extension, but it isn't using the correct path. For those who haven't used Haskell before, one way of using it is installing GHCup, then using it to install GHC (the compiler) and Cabal (a Haskell build system) (or if you prefer using Stack instead of Cabal, then you would install that). This is installed to ~/.local/bin
(if you use XDG directories).
The point is, the Haskell Language Server in VSCode looks for the GHC executable. To do this, it looks through the $PATH variable to find it. The issue is that VSCode didn't load the correct $PATH variable and therefore cannot find GHC. The output of the Haskell output after starting VSCode from KDE (either from the application launcher or the quick launcher using Alt+F2) is as follows:
2022-04-09 23:01:18.9040000 [client] INFO Searching for server executables haskell-language-server-wrapper,haskell-language-server in $PATH
2022-04-09 23:01:18.9040000 [client] INFO $PATH environment variable: /usr/local/sbin:/usr/local/bin:/usr/bin:/home/ettolrach/.dotnet/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
2022-04-09 23:01:18.9270000 [client] INFO Downloading haskell-language-server
2022-04-09 23:01:18.9280000 [client] INFO Using /home/ettolrach/.config/Code/User/globalStorage/haskell.haskell to store downloaded binaries
2022-04-09 23:01:18.9280000 [client] INFO Fetching the latest release from GitHub or from cache
2022-04-09 23:01:21.1680000 [client] INFO The latest known release is 1.6.1.0
2022-04-09 23:01:21.1680000 [client] INFO Figure out the ghc version to use or advertise an installation link for missing components
2022-04-09 23:01:21.1680000 [client] INFO Working out the project GHC version. This might take a while...
2022-04-09 23:01:21.1840000 [client] INFO Executing '/home/ettolrach/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-1.6.1.0-linux --project-ghc-version' in cwd '/home/ettolrach/git/reverse' to get the project or file ghc version
2022-04-09 23:01:21.2150000 [client] INFO Execution of '/home/ettolrach/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-1.6.1.0-linux --project-ghc-version' terminated with code 1
2022-04-09 23:01:21.2150000 [client] ERROR Error executing '/home/ettolrach/.config/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-1.6.1.0-linux --project-ghc-version' with error code 1
2022-04-09 23:01:21.2150000 [client] ERROR stderr: No 'hie.yaml' found. Try to discover the project type!
Cradle requires ghc but couldn't find it
Cradle {cradleRootDir = "/home/ettolrach/git/reverse", cradleOptsProg = CradleAction: Default}
Crucially: the $PATH variable it has is /usr/local/sbin:/usr/local/bin:/usr/bin:/home/ettolrach/.dotnet/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
while my actual $PATH is export PATH="$HOME/.local/bin:$PATH"
, notice that there is not /home/ettolrach/.local/bin
(my user is ettolrach
).
I have set the following $PATH variable in ~/.zshenv
and ~/.profile
(I have typed export PATH="$HOME/.local/bin:$PATH"
in both of those files) and it isn't the same as the one VSCode has. The answers I'm reading around the internet such as this one from SO or this one from the Haskell Language Server GitHub suggest to add the $PATH to ~/.profile
(which again doesn't work) or /etc/profile
, but I'd prefer not to define a system wide $PATH for a user-specific configuration. Note that I don't use Bash, so I don't have ~/.bash_profile
, or ~/.bashrc
, or any other Bash related config file.
This works fine when I launch VSCode from the terminal by typing code .
. Probably because it inherits the terminal's (correct) $PATH.
I have also restarted after changing both ~/.profile
and ~/.zshenv
to make sure they're loaded.
So, my question is, if VSCode doesn't read the $PATH from ~/.profile
, nor ~.zshenv
, where does it read it from, and how can I set it correctly?