haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

"Couldn't figure out what GHC version the project is using" if the path contains a german umlaut #601

Closed I-Al-Istannen closed 3 years ago

I-Al-Istannen commented 3 years ago

Problem

Since a few days (I don't know the exact one, but within ~ the last 5) the haskell plugin can no longer deal with files that have a german umlaut (öäü) in their path. When I open such a file, the plugin reports the error Couldn't figure out what GHC version the project is using. I couldn't find any further logs. The more detailed error message below seems to indicate that it doesn't understand that character.

Renaming the folder to a name without an umlaut - and changing nothing else - resolves the problem.

Error message

The path to the folder opened in VSC and the haskell file is /tmp/test/Rändom/Test.hs.

Couldn't figure out what GHC version the project is using:
/home/i_al_istannen/.config/Code - OSS/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-0.6.0-linux --project-ghc-version
exited with exit code 1: Module "/tmp/test/Rhaskell-language-server-wrapper-0.6.0-linux: <stderr>: hPutChar: invalid argument (invalid character)

How to reproduce

# Setup directory
cd /tmp/
mdkir Rändom && cd Rändom

# Setup project file
echo "module Test where" > Test.hs

# Start VSCode
code .

# Observe the error message when opening Test.hs

# Rename the folder
cd ..
mv Rändom Random

# Enter it and restart VSCode
cd Random
code .

# Watch it work when opening Test.hs

Disclaimer

I couldn't find a duplicate issue but I might have missed one, as I didn't trail through every available issue and used the search function instead. In that case I apologize and would love a pointer to a relevant issue.

fendor commented 3 years ago

I can not re-produce that error, is you locale (check by invoking locale anywhere) set in a sensible way? E.g. set to some UTF-8 charset?

It could be a good idea to use https://hackage.haskell.org/package/with-utf8 to make sure we open file handles in utf-8 only.

jneira commented 3 years ago

I am trying to reproduce in windows with a á or ä and it works for me, could you share the output of execute haskell-language-server-wrapper -d . in /tmp/Rändom?

Mine is

[client] run command: "haskell-language-server-wrapper --lsp -d"
[client] debug command: "haskell-language-server-wrapper --lsp -d"
[client] server cwd: undefined
Module "d:\dev\ws\haskell\st�ndalone-hs\a" is loaded by Cradle: Cradle {cradleRootDir = "d:\\dev\\ws\\haskell\\st\228ndalone-hs", cradleOptsProg = CradleAction: Default}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.6.0.0 x86_64 ghc-8.10.2
Current directory: d:\dev\ws\haskell\st�ndalone-hs
Operating system: mingw32
Arguments: ["--lsp","-d"]
Cradle directory: d:\dev\ws\haskell\st�ndalone-hs
Cradle type: Default

Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.5.1
ghc:        8.10.1

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.1
haskell-language-server exe candidates: ["haskell-language-server-8.10.1.exe","haskell-language-server-8.10.exe","haskell-language-server.exe"]
Launching haskell-language-server exe at:D:\bin\haskell-language-server-8.10.1.exe
I-Al-Istannen commented 3 years ago

I just noticed I didn't open this in https://github.com/haskell/vscode-haskell but in the core language server repo. Damn it, I had those tabs side by side and probably misclicked. I suspect the VSC plugin is at fault, but maybe you can confirm that. I will re-post the issue in the plugin repo, if you think it is plugin related as well.

localectl

   System Locale: LANG=de_DE.UTF-8
       VC Keymap: de-latin1
      X11 Layout: de
       X11 Model: pc105
     X11 Variant: nodeadkeys
     X11 Options: terminate:ctrl_alt_bksp,compose:rctrl

locale

LANG=de_DE.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

The other command

I use it from within VSCode, so the language server executable path is probably messed up, but:

Module "/tmp/Rändom/a" is loaded by Cradle: Cradle {cradleRootDir = "/tmp/R\228ndom", cradleOptsProg = CradleAction: Default}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper-0.6.0-linux) Version 0.6.0.0, Git revision 372a12e797069dc3ac4fa33dcaabe3b992999d7c (dirty) x86_64 ghc-8.10.1
Current directory: /tmp/Rändom
Operating system: linux
Arguments: ["-d","."]
Cradle directory: /tmp/Rändom
Cradle type: Default

Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.5.1
ghc:        8.10.2

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.2
haskell-language-server exe candidates: ["haskell-language-server-8.10.2","haskell-language-server-8.10","haskell-language-server"]
Cannot find any haskell-language-server exe, looked for: haskell-language-server-8.10.2, haskell-language-server-8.10, haskell-language-server
jneira commented 3 years ago

I just noticed I didn't open this in https://github.com/haskell/vscode-haskell but in the core language server repo

You did it but i translated the issue here, assuming that the culprit was haskell-language-server-wrapper (it is an executable of this project).

fendor commented 3 years ago

@I-Al-Istannen If you have time, could you build the PR #602, build it from source and see if it fixes your issue?

I-Al-Istannen commented 3 years ago

@I-Al-Istannen If you have time, could you build the PR #602, build it from source and see if it fixes your issue?

I didn't think compilation would finish, but it is done now... Just took about 20 minutes :P

I have good and bad news, the error message changed to this:

[client] run command: "haskell-language-server-wrapper --lsp"
[client] debug command: "haskell-language-server-wrapper --lsp"
[client] server cwd: undefined
Module "/tmp/R??ndom/a" is loaded by Cradle: Cradle {cradleRootDir = "/tmp/R\56515\56484ndom", cradleOptsProg = CradleAction: Default}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.6.0.0, Git revision 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589 (826 commits) x86_64 ghc-8.10.2
Current directory: /tmp/R??ndom
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /tmp/R??ndom
Cradle type: Default

Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.5.1
ghc:        8.10.2

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.2
haskell-language-server exe candidates: ["haskell-language-server-8.10.2","haskell-language-server-8.10","haskell-language-server"]
Launching haskell-language-server exe at:/home/i_al_istannen/.local/bin/haskell-language-server-8.10.2
haskell-language-server version: 0.6.0.0 (GHC: 8.10.2) (PATH: /home/i_al_istannen/.local/bin/haskell-language-server-8.10.2) (GIT hash: 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589)
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 "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /tmp/Rhaskell-language-server-8.10.2: <stderr>: hPutChar: invalid argument (invalid character)
haskell-language-server-wrapper: callProcess: /home/i_al_istannen/.local/bin/haskell-language-server-8.10.2 "--lsp" (exit 1): failed
[Info  - 23:04:57] Connection to server got closed. Server will restart.

It actually gets far enough in the starting process now that it prints a usable log, but it still dies.

fendor commented 3 years ago

in directory: /tmp/Rhaskell-language-server-8.10.2: : hPutChar: invalid argument (invalid character)

Still looks like it crashes :(

I-Al-Istannen commented 3 years ago

I can putStrLn and putChar äöü in GHCI if that helps :/ I wonder why I can reproduce it but you can't, maybe my system is screwed up somehow... Is there anything I could help debug this? It isn't a show-stopping bug, just mildly annoying.

merijn commented 3 years ago

If it helps I just spend some time on IRC explaining @fendor why "I wanna open a path with unicode characters on linux" is a fundamentally cursed problem. See the history here for details why it's impossible to do correctly in general: https://ircbrowse.tomsmeding.com/day/haskell/today/recent?id=134192&timestamp=1605625693#t1605625693

Of course most of base/directory/filepath having FilePath defined as String doesn't help here...

I-Al-Istannen commented 3 years ago

I'd like to thank you for responding so swiftly :) I am quite content with having a language server, even if it doesn't work in some paths, it is miles better than not having it :)

I tried reproducing the problem in a simple docker image and failed. I also noticed that it works when run from the command line.

The only difference seems to be that the VSCode one says /tmp/R??ndom while the one run from the terminal properly displays the ä. VSCode was started from that terminal and should have inherited all env vars. locale inside a VSCode terminal was also identical, but I am not sure it uses the same environment for executings its internal commands.

Running the command manually in a terminal

Module "/tmp/Rändom/a" is loaded by Cradle: Cradle {cradleRootDir = "/tmp/R\228ndom", cradleOptsProg = CradleAction: Default}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.6.0.0, Git revision 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589 (826 commits) x86_64 ghc-8.10.2
Current directory: /tmp/Rändom
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /tmp/Rändom
Cradle type: Default

Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.5.1
ghc:        8.10.2

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.2
haskell-language-server exe candidates: ["haskell-language-server-8.10.2","haskell-language-server-8.10","haskell-language-server"]
Launching haskell-language-server exe at:/home/i_al_istannen/.local/bin/haskell-language-server-8.10.2
haskell-language-server version: 0.6.0.0 (GHC: 8.10.2) (PATH: /home/i_al_istannen/.local/bin/haskell-language-server-8.10.2) (GIT hash: 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589)
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 "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /tmp/Rändom
If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!

Running from VSCode

Module "/tmp/R??ndom/a" is loaded by Cradle: Cradle {cradleRootDir = "/tmp/R\56515\56484ndom", cradleOptsProg = CradleAction: Default}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.6.0.0, Git revision 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589 (826 commits) x86_64 ghc-8.10.2
Current directory: /tmp/R??ndom
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /tmp/R??ndom
Cradle type: Default

Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.5.1
ghc:        8.10.2

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.2
haskell-language-server exe candidates: ["haskell-language-server-8.10.2","haskell-language-server-8.10","haskell-language-server"]
Launching haskell-language-server exe at:/home/i_al_istannen/.local/bin/haskell-language-server-8.10.2
haskell-language-server version: 0.6.0.0 (GHC: 8.10.2) (PATH: /home/i_al_istannen/.local/bin/haskell-language-server-8.10.2) (GIT hash: 4ddf0a233ddaefcbaab740f4e209f0b1e3f09589)
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 "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /tmp/Rhaskell-language-server-8.10.2: <stderr>: hPutChar: invalid argument (invalid character)
haskell-language-server-wrapper: callProcess: /home/i_al_istannen/.local/bin/haskell-language-server-8.10.2 "--lsp" (exit 1): failed
[Error - 23:10:22] Connection to server got closed. Server will not be restarted.
I-Al-Istannen commented 3 years ago

After I spotted a clearer error message in the python language server and factoring in that it only happens in VSCode I got suspicious. Using the correct search terms this time I came across https://github.com/microsoft/vscode/issues/110322#issuecomment-726426703 and I can confirm this solves my problem.

Sorry for wasting your time, I wasn't aware of that electron bug :/

As that bug seems to fixed in upstream, it shouldn't reappear once they pushed the update either. I will close this issue now, thank you all! :)

i-am-the-slime commented 3 years ago

I get the same error message on macOS and the linked ArchLinux post doesn't really help me. What else can I try now?

merijn commented 3 years ago

@i-am-the-slime macOS by default doesn't specify a LANG environment variable in the shell, which means the language locale defaults to C which breaks on any non-ASCII. The solution is to set LANG to an appropriate locale value, which would depend on, well, your locale.

i-am-the-slime commented 3 years ago

@merijn Thanks for the quick feedback: In my particular setup I added this to ~/.config/fish/config.fish:

set -gx  LC_ALL en_GB.UTF-8

Which gets me to:

haskell-language-server 0.6.0 for GHC 8.2.2 is not available on Darwin

Which I suppose is a different problem.