windowshaskellvscode-extensionshaskell-language-server

How to setup MINGW environment variables for Haskell language server in vscode?


I have a Haskell project on Windows. The project depends on diagrams-cairo, which depends on GTK+.

I have successfully built this project (via msys64+MINGW) and it runs nicely.

The problem is how to setup Haskell language server?

I used the following settings for Haskell vscode extension:

    "haskell.serverExecutablePath": "C:\\env\\haskell\\lsp\\haskell-language-server-9.6.3.exe",
    "haskell.serverEnvironment": {
        "PATH": "C:/env/haskell/ghc/ghc-9.6.3-x86_64-unknown-mingw32/bin;C:/env/haskell/cabal;C:/Program Files/Git/cmd;$PATH",
        "PKG_CONFIG_PATH": "C:/msys64/mingw64/lib/pkgconfig;C:/msys64/mingw64/share/pkgconfig",
        "XDG_DATA_DIRS": "C:/msys64/mingw64/share;C:/msys64/usr/share/"
    },

However, the language server complained (selected log messages):

2024-02-15 09:15:15.7370000 [client] INFO Finding haskell-language-server
2024-02-15 09:15:15.7370000 [client] INFO Trying to find the server executable in: C:\env\haskell\lsp\haskell-language-server-9.6.3.exe
2024-02-15 09:15:15.7530000 [client] INFO Activating the language server in working dir: e:\work-pl\haskell\code\frp\yampa-gloss\yampa-gloss-0.2.1-yampa-0.14.7 (the workspace folder)
2024-02-15 09:15:15.7530000 [client] INFO run command: C:\env\haskell\lsp\haskell-language-server-9.6.3.exe --lsp
2024-02-15 09:15:15.7530000 [client] INFO debug command: C:\env\haskell\lsp\haskell-language-server-9.6.3.exe --lsp
2024-02-15 09:15:15.7530000 [client] INFO server environment variables:
2024-02-15 09:15:15.7530000 [client] INFO   PATH=C:/env/haskell/ghc/ghc-9.6.3-x86_64-unknown-mingw32/bin;C:/env/haskell/cabal;C:/Program Files/Git/cmd;$PATH
2024-02-15 09:15:15.7530000 [client] INFO   PKG_CONFIG_PATH=/c/msys64/mingw64/lib/pkgconfig:/c/msys64/mingw64/share/pkgconfig
2024-02-15 09:15:15.7530000 [client] INFO   XDG_DATA_DIRS=/c/msys64/mingw64/share:/c/msys64/usr/share/
2024-02-15 09:15:15.7560000 [client] INFO Starting language server
2024-02-15T09:15:15.814223Z | Info | haskell-language-server version: 2.5.0.0 (GHC: 9.6.3) (PATH: C:\env\haskell\lsp\haskell-language-server-9.6.3.exe)
2024-02-15T09:15:15.814223Z | Info | Directory: e:\work-pl\haskell\code\frp\yampa-gloss\yampa-gloss-0.2.1-yampa-0.14.7
2024-02-15T09:15:15.815223Z | Info | Starting (haskell-language-server) LSP server...

...

2024-02-15T09:15:15.827223Z | Info | Starting server
2024-02-15T09:15:15.830224Z | Info | Started LSP server in 0.00s 2024-02-15T09:15:19.003405Z | Error |
Couldn't load cradle for ghc libdir.   Cradle error:    CradleError
{cradleErrorDependencies = [],  cradleErrorExitCode = ExitFailure 1,  cradleErrorStderr =   [   "Error
when calling cabal exec -v0 -- ghc --print-libdir",   "",   "Error: cabal: Could
not resolve dependencies:\n[__0] trying: yampa-gloss-0.2.1 (user goal)\n[__1]
trying: yampa-gloss:+examples\n[__2] trying: diagrams-cairo-1.4.2.1 (dependency of
yampa-gloss +examples)\n[__3] next goal: pango (dependency of diagrams-cairo)\n[__3]
rejecting: pango-0.13.10.0, pango-0.13.8.2, pango-0.13.8.1,\npango-0.13.8.0,
pango-0.13.6.1, pango-0.13.6.0, pango-0.13.5.0,\npango-0.13.4.0, pango-0.13.3.1,
pango-0.13.3.0, pango-0.13.2.0,\npango-0.13.1.1, pango-0.13.1.0, pango-0.13.0.5,
pango-0.13.0.4,\npango-0.13.0.3, pango-0.13.0.2, pango-0.13.0.1, pango-0.13.0.0,\npango-0.12.5.3,
pango-0.12.5.0 (conflict: pkg-config package pango>=1.0, not\nfound in the pkg-config
database)\n[__3] rejecting: pango-0.12.4 (conflict: diagrams-cairo => pango>=0.12.5
&&\n<0.14)\n[__3] skipping: pango-0.12.3, pango-0.12.2, pango-0.12.1,
pango-0.12.0,\npango-0.11.2, pango-0.11.1, pango-0.11.0 (has the same characteristics that\ncaused the
previous version to fail: excluded by constraint '>=0.12.5 &&\n<0.14' from
'diagrams-cairo')\n[__3] fail (backjumping, conflict set: diagrams-cairo, pango)\nAfter searching the
rest of the dependency tree exhaustively, these were the\ngoals I've had most
trouble fulfilling: base, pango, diagrams-cairo,\nyampa-gloss,
yampa-gloss:examples\nTry running with --minimize-conflict-set to improve the error message.\n\n" ]}  
Root dir path:
e:\work-pl\haskell\code\frp\yampa-gloss\yampa-gloss-0.2.1-yampa-0.14.7   hie.yaml path:  

Notice this message:

conflict: pkg-config package pango>=1.0, not\nfound in the pkg-config database

which means that haskell-language-server doesn't seem to recognize PKG_CONFIG_PATH?

The question is:

How to correctly pass these MINGW related environment variables like PKG_CONFIG_PATH to haskell-language-server?

Or is it possible to let VSCODE run haskell-language-server under MINGW environment (just like normal build, which can recognize PKG_CONFIG_PATH)?

Thanks.

P.S.

  1. I doesn't use GHCup, all installations are manual.

  2. I have worked other projects (i.e. non MINGW dependencies) by HLS VSCODE without any problems, only this project has the problem. So I think other configurations are correct.

  3. I asked the question here rather than vscode-haskell and haskell-language-server is because I don't know which repository I should submit the issue.


Solution

  • After some research, I have configured this project with MINGW (GTK related deps) + Haskell language server successfully .

    The solution as follows:

    Due to the project depends on GTK+, which relies on MINGW, all MINGW related environment variables need to be included in the settings (not only PKG_CONFIG_PATH, XDG_DATA_DIRS).

    The updated settings is as follows:

        "haskell.serverExecutablePath": "C:\\env\\haskell\\lsp\\haskell-language-server-9.8.1.exe",
        "haskell.serverEnvironment": {
            "PATH": "C:/env/haskell/ghc/ghc-9.8.1-x86_64-unknown-mingw32/bin;C:/env/haskell/cabal;C:/Program Files/Git/cmd;C:/msys64/mingw64/bin;C:/msys64/usr/local/bin;C:/msys64/usr/bin;$PATH"
            , "PKG_CONFIG_PATH": "C:/msys64/mingw64/lib/pkgconfig;C:/msys64/mingw64/share/pkgconfig"
            , "XDG_DATA_DIRS": "C:/msys64/mingw64/share;C:/msys64/usr/share"
            , "PKG_CONFIG_SYSTEM_INCLUDE_PATH": "C:/msys64/mingw64/include"
            , "PKG_CONFIG_SYSTEM_LIBRARY_PATH": "C:/msys64/mingw64/lib"
            , "LANG": "en_GB.UTF-8"
            , "MINGW_PREFIX": "C:/msys64/mingw64"
            , "WD": "C:/msys64/usr/bin/"
        },
    

    P.S. The above settings might be simplified further (since not all the variables would be used), but this is just to demonstrate that it can work!