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

Retrie fails on Windows with `could not detect mingw toolchain` #471

Closed Tarmean closed 2 years ago

Tarmean commented 4 years ago

Subject of the issue

For me, the retrie plugin fails on Windows with could not detect mingw toolchain. The action isn't cancelled so the lsp client perpetually waits for the action to complete.

I think the error message is caused by expandToolDir in SysTools.BaseDir but I couldn't figure out how it is called. Since the retrie plugin works on the typechecked syntax tree and initGhcMonad calls expandToolDir this might be related. ghc-lib-parser mentions a similar issue in a comment:

    -- On mingw we avoid a "could not detect toolchain mingw"
      -- runtime error. The error originates from `findToolDir`
      -- indirectly invoked by `initGhcMonad` from `runGhc`). This
      -- line tricks `findToolDir`.
      createDirectoryIfMissing True $ dataDir ++ "/../mingw"

Finally, This issue comment in haskell-ide-engine has a similar message, no idea if this is related.

Your environment

Steps to reproduce

Use a fold or unfold action

Expected behaviour

The action is executed

Actual behaviour

The error haskell-language-server-8.6.5.exe: could not detect mingw toolchain is logged and the action never finishes

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output: ``` haskell-language-server version: 0.5.0.0 (GHC: 8.6.5) (PATH: C:\Users\Name\AppData\Roami ng\local\bin\haskell-language-server-8.6.5.exe) (GIT hash: 14497f2503a2a0d389fabf3b146d67 4b9af41a34) (haskell-language-server)Ghcide setup tester in C:\Users\Name\Projects\temp. Report bugs at https://github.com/haskell/haskell-language-server/issues Tool versions found on the $PATH cabal: 3.2.0.0 stack: 2.3.3 ghc: 8.6.5 Step 1/4: Finding files to test in C:\Users\Name\Projects\temp Found 4 files Step 2/4: Looking for hie.yaml files that control setup Found 1 cradle Step 3/4: Initializing the IDE Step 4/4: Type checking the files [INFO] Consulting the cradle for "executable\\Main.hs" Output from setting up the cradle Cradle {cradleRootDir = "C:\\Users\\Name\\Projects\\te mp", cradleOptsProg = CradleAction: Stack} > Using main module: 1. Package `temp' component temp:exe:temp with main-is file: C:\ Users\Name\Projects\temp\executable\Main.hs > temp> configure (lib + exe) > Configuring temp-0.0.0... > temp> initial-build-steps (lib + exe) > The following GHC options are incompatible with GHCi and have not been passed to it : -threaded > Configuring GHCi with the following packages: temp > C:\Users\Name\Projects\temp\.stack-work\install\8806197a\pkgdb;C:\sr\snapshots\8cc3784 8\pkgdb;C:\Users\Name\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.5\lib\package. conf.d [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-90e3f8f7 e30f0e2fc49f4d12328b383afedd6a7d [INFO] Making new HscEnv[main] [INFO] Consulting the cradle for "library\\Example.hs" Output from setting up the cradle Cradle {cradleRootDir = "C:\\Users\\Name\\Projects\\te mp", cradleOptsProg = CradleAction: Stack} > Configuring GHCi with the following packages: temp > C:\Users\Name\Projects\temp\.stack-work\install\8806197a\pkgdb;C:\sr\snapshots\8cc3784 8\pkgdb;C:\Users\Name\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.5\lib\package. conf.d [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-0eb5227b 8c5a22ac1aa16260cda20535547d8e3d [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-0eb5227b 8c5a22ac1aa16260cda20535547d8e3d [INFO] Making new HscEnv[main,main] [INFO] Consulting the cradle for "benchmark\\Main.hs" Output from setting up the cradle Cradle {cradleRootDir = "C:\\Users\\Name\\Projects\\te mp", cradleOptsProg = CradleAction: Stack} > Using main module: 1. Package `temp' component temp:bench:temp-benchmarks with main-is file: C:\Users\Name\Projects\temp\benchmark\Main.hs > temp> Benchmark running disabled by --no-run-benchmarks flag. > The following GHC options are incompatible with GHCi and have not been passed to it: -t hreaded > Configuring GHCi with the following packages: temp > C:\Users\Name\Projects\temp\.stack-work\install\8806197a\pkgdb;C:\sr\snapshots\8cc3784 8\pkgdb;C:\Users\Name\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.5\lib\package. conf.d [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-28bd9d46 a3ea4b0fafdfb3f52bcdb88ca5102382 [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-28bd9d46 a3ea4b0fafdfb3f52bcdb88ca5102382 [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-28bd9d46 a3ea4b0fafdfb3f52bcdb88ca5102382 [INFO] Making new HscEnv[main,main,main] [INFO] Consulting the cradle for "test-suite\\Main.hs" Output from setting up the cradle Cradle {cradleRootDir = "C:\\Users\\Name\\Projects\\te mp", cradleOptsProg = CradleAction: Stack} > Using main module: 1. Package `temp' component temp:test:temp-test-suite with main-is f ile: C:\Users\Name\Projects\temp\test-suite\Main.hs > temp> configure (lib + test) > Configuring temp-0.0.0... > temp> initial-build-steps (lib + test) > temp> Test running disabled by --no-run-tests flag. > Completed 2 action(s). > The following GHC options are incompatible with GHCi and have not been passed to it: -t hreaded > Configuring GHCi with the following packages: temp > C:\Users\Name\Projects\temp\.stack-work\install\8806197a\pkgdb;C:\sr\snapshots\8cc3784 8\pkgdb;C:\Users\Name\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.5\lib\package. conf.d [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-425d0aca 49ac56edcf4797fe94c6ef768d23946b [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-425d0aca 49ac56edcf4797fe94c6ef768d23946b [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-425d0aca 49ac56edcf4797fe94c6ef768d23946b [INFO] Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-425d0aca 49ac56edcf4797fe94c6ef768d23946b [INFO] Making new HscEnv[main,main,main,main] [INFO] finish: User TypeCheck (took 0.09s)Completed (4 files worked, 0 files failed) ```

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: ``` ## versionsvim version: NVIM v0.5.0-731-ge3afb30e6node version: v12.3.1coc.nvim version: 0.0.79-b71489207acoc.nvim directory: C:\Users\Name\vimfiles\plugged\coc.nvimterm: undefinedplatform: win32## Output channel: languageserver.haskellModule "C:\Program Files\Neovim\bin\a" is loaded by Cradle: Cradle {cradleRootDir = "C:\\Program Files\\Neovim\\bin", cradleOptsProg = CradleAction: Default} Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 0.5.0.0, Git revision 14497f2503a2a0d389fabf3b146d674b9af41a34 (dirty) x86_64 ghc-8.10.1 Current directory: C:\Program Files\Neovim\bin Operating system: mingw32 Arguments: ["--lsp"] Cradle directory: C:\Program Files\Neovim\bin Cradle type: Default Tool versions found on the $PATH cabal: 3.2.0.0 stack: 2.3.3 ghc: 8.6.5 Consulting the cradle to get project GHC version... Project GHC version: 8.6.5 haskell-language-server exe candidates: ["haskell-language-server-8.6.5.exe","haskell-language-server-8.6.exe","haskell-language-server.exe"] Launching haskell-language-server exe at:C:\Users\Name\AppData\Roaming\local\bin\haskell-language-server-8.6.5.exe haskell-language-server version: 0.5.0.0 (GHC: 8.6.5) (PATH: C:\Users\Name\AppData\Roaming\local\bin\haskell-language-server-8.6.5.exe) (GIT hash: 14497f2503a2a0d389fabf3b146d674b9af41a34) 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 "importLens",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"] in directory: C:\Program Files\Neovim\bin If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option! Started LSP server in 0.00s 2020-10-06 16:03:14.0315665 [ThreadId 13] - Registering ide configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 1625159137 "file:///C:/Users/Name/Projects/temp"], clientSettings = hashed (Just (Object (fromList [("languageServerHaskell",Object (fromList [("hlintOn",Bool True),("templateOn",Bool True)]))])))} 2020-10-06 16:03:14.0315665 [ThreadId 13] - Opened text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:14.0471926 [ThreadId 39] - Consulting the cradle for "library\\Example.hs" Output from setting up the cradle Cradle {cradleRootDir = "C:\\Users\\Name\\Projects\\temp", cradleOptsProg = CradleAction: Stack} > Configuring GHCi with the following packages: temp > C:\Users\Name\Projects\temp\.stack-work\install\8806197a\pkgdb;C:\sr\snapshots\8cc37848\pkgdb;C:\Users\Name\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.5\lib\package.conf.d 2020-10-06 16:03:16.198249 [ThreadId 39] - Using interface files cache dir: C:\Users\Name\AppData\Local\ghcide\main-7371f5c9457a0df89cb8d03189c4d9bbbdfd2df6 2020-10-06 16:03:16.198249 [ThreadId 39] - Making new HscEnv[main] 2020-10-06 16:03:16.4300119 [ThreadId 151] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:16.4300119 [ThreadId 152] - finish: codeLens (took 0.00s) 2020-10-06 16:03:16.4300119 [ThreadId 158] - finish: (took 0.00s) 2020-10-06 16:03:19.9483187 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:20.0645611 [ThreadId 221] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:20.0656117 [ThreadId 222] - finish: codeLens (took 0.00s) 2020-10-06 16:03:20.0656117 [ThreadId 228] - finish: (took 0.00s) 2020-10-06 16:03:20.296481 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:20.3497984 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:20.4127517 [ThreadId 349] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:20.4127517 [ThreadId 350] - finish: codeLens (took 0.00s) 2020-10-06 16:03:20.4127517 [ThreadId 355] - finish: (took 0.00s) 2020-10-06 16:03:20.4500811 [ThreadId 368] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:20.4500811 [ThreadId 369] - finish: codeLens (took 0.00s) 2020-10-06 16:03:20.4500811 [ThreadId 371] - finish: (took 0.00s) 2020-10-06 16:03:20.8716875 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:20.9724993 [ThreadId 437] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:20.9724993 [ThreadId 438] - finish: codeLens (took 0.00s) 2020-10-06 16:03:20.9724993 [ThreadId 443] - finish: (took 0.00s) 2020-10-06 16:03:21.2041886 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:21.3104345 [ThreadId 491] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:21.3104345 [ThreadId 492] - finish: codeLens (took 0.00s) 2020-10-06 16:03:21.3104345 [ThreadId 507] - finish: (took 0.00s) 2020-10-06 16:03:21.4266994 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:21.5266877 [ThreadId 555] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:21.5423118 [ThreadId 556] - finish: codeLens (took 0.00s) 2020-10-06 16:03:21.5423118 [ThreadId 571] - finish: (took 0.00s) 2020-10-06 16:03:21.6116988 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:21.7330619 [ThreadId 652] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:21.7330619 [ThreadId 653] - finish: codeLens (took 0.00s) 2020-10-06 16:03:21.7330619 [ThreadId 658] - finish: (took 0.00s) 2020-10-06 16:03:22.1064006 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:22.2066925 [ThreadId 738] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:22.2066925 [ThreadId 739] - finish: codeLens (took 0.00s) 2020-10-06 16:03:22.2066925 [ThreadId 744] - finish: (took 0.00s) 2020-10-06 16:03:22.7785252 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:22.8946703 [ThreadId 806] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:22.8946703 [ThreadId 807] - finish: codeLens (took 0.00s) 2020-10-06 16:03:22.8946703 [ThreadId 812] - finish: (took 0.00s) 2020-10-06 16:03:23.2819363 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:23.3982133 [ThreadId 892] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:23.3982133 [ThreadId 893] - finish: codeLens (took 0.00s) 2020-10-06 16:03:23.3982133 [ThreadId 898] - finish: (took 0.00s) 2020-10-06 16:03:23.5836767 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:23.652724 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:23.69956 [ThreadId 1018] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:23.69956 [ThreadId 1019] - finish: codeLens (took 0.00s) 2020-10-06 16:03:23.69956 [ThreadId 1024] - finish: (took 0.00s) 2020-10-06 16:03:23.7544703 [ThreadId 1028] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:23.7544703 [ThreadId 1029] - finish: codeLens (took 0.00s) 2020-10-06 16:03:23.7544703 [ThreadId 1031] - finish: (took 0.00s) 2020-10-06 16:03:24.0429134 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:24.1407348 [ThreadId 1080] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:24.1407348 [ThreadId 1081] - finish: codeLens (took 0.00s) 2020-10-06 16:03:24.1407348 [ThreadId 1096] - finish: (took 0.00s) 2020-10-06 16:03:24.8897567 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:24.9900685 [ThreadId 1176] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:24.9900685 [ThreadId 1177] - finish: codeLens (took 0.00s) 2020-10-06 16:03:24.9900685 [ThreadId 1182] - finish: (took 0.00s) 2020-10-06 16:03:25.4600465 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:25.5616325 [ThreadId 1262] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:25.5616325 [ThreadId 1263] - finish: codeLens (took 0.00s) 2020-10-06 16:03:25.5616325 [ThreadId 1268] - finish: (took 0.00s) 2020-10-06 16:03:26.3486783 [ThreadId 1272] - DocumentHighlight request at position 11:11 in file: c:\Users\Name\Projects\temp\library\Example.hs 2020-10-06 16:03:26.4332198 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:26.5499071 [ThreadId 1340] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:26.5499071 [ThreadId 1341] - finish: codeLens (took 0.00s) 2020-10-06 16:03:26.5499071 [ThreadId 1346] - finish: (took 0.00s) 2020-10-06 16:03:27.2148235 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:27.3314972 [ThreadId 1412] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:27.3314972 [ThreadId 1413] - finish: codeLens (took 0.00s) 2020-10-06 16:03:27.3314972 [ThreadId 1418] - finish: (took 0.00s) 2020-10-06 16:03:27.8563494 [ThreadId 1422] - DocumentHighlight request at position 10:11 in file: c:\Users\Name\Projects\temp\library\Example.hs 2020-10-06 16:03:28.0732769 [ThreadId 1431] - finish: Formatter (took 0.00s) 2020-10-06 16:03:28.0732769 [ThreadId 1434] - finish: Ormolu (took 0.00s) 2020-10-06 16:03:28.0883492 [ThreadId 13] - Modified text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:28.1910446 [ThreadId 1497] - Plugin.makeCodeLens (ideLogger) 2020-10-06 16:03:28.1910446 [ThreadId 1498] - finish: codeLens (took 0.00s) 2020-10-06 16:03:28.1910446 [ThreadId 1503] - finish: (took 0.00s) 2020-10-06 16:03:28.1910446 [ThreadId 13] - Saved text document: file:///c%3A/Users/Name/Projects/temp/library/Example.hs 2020-10-06 16:03:28.206309 [ThreadId 1561] - Typechecking reverse dependencies forNormalizedFilePath "C:\\Users\\Name\\Projects\\temp\\library\\Example.hs": [] 2020-10-06 16:03:28.7230231 [ThreadId 1567] - DocumentHighlight request at position 9:11 in file: c:\Users\Name\Projects\temp\library\Example.hs 2020-10-06 16:03:29.4183198 [ThreadId 1576] - finish: CodeAction (took 0.00s) 2020-10-06 16:03:29.6208031 [ThreadId 1582] - finish: CodeAction:PackageExports (took 0.19s) 2020-10-06 16:03:29.6208031 [ThreadId 1583] - finish: importLens (took 0.00s) 2020-10-06 16:03:29.6208031 [ThreadId 1585] - finish: retrie (took 0.00s) 2020-10-06 16:03:29.6208031 [ThreadId 1587] - finish: tactic (took 0.00s) 2020-10-06 16:03:29.6208031 [ThreadId 1592] - finish: tactic (took 0.00s) 2020-10-06 16:03:29.6208031 [ThreadId 1593] - finish: tactic (took 0.00s) 2020-10-06 16:03:34.6036553 [ThreadId 1600] - finish: Retrie.GhcSessionDeps (took 0.00s) fromList [NormalizedFilePath "C:\\Users\\Name\\Projects\\temp\\library\\Example.hs"] 2020-10-06 16:03:34.6036553 [ThreadId 1602] - finish: Retrie.getBinds (took 0.00s) haskell-language-server-8.6.5.exe: could not detect mingw toolchain [Error - 16:03:34] Request workspace/executeCommand failed. Message: ExitFailure 1 Code: -32603 ```
jneira commented 4 years ago

Hi, trying to reproduce it i've hit another issue #533 I think i would hit yours before that but it was not the case in my environment, i've used ghc-8.10.1.

jneira commented 4 years ago

@Tarmean have you tried to apply the retrie rule directly using the executable? does it throw the same error?

Tarmean commented 4 years ago

Hey, using retrie directly seems to work, at least until it runs into the issue with missing grep and xargs executables you found and does nothing.

shellCmd:
grep -R --include="*.hs" -l '1[[:space:]]\++[[:space:]]\+1' C:\Users\Name\Projects\Scratch
Files:
Done! 0 lines changed.
jneira commented 3 years ago

Another issue throwing the same original error: #615

Tarmean commented 3 years ago

The workaround from https://github.com/haskell/haskell-language-server/issues/591 worked for me as well.

jneira commented 3 years ago

@Tarmean thanks for confirming it

jneira commented 3 years ago

No sure if we could apply the hack of set the ghc libdir usin a en var here to resolve this. The hack is not thread safe and i am not sure if that could make the solution not applicable to retrie

jneira commented 3 years ago

No sure if we could apply the hack of set the ghc libdir usin a en var here to resolve this. The hack is not thread safe and i am not sure if that could make the solution not applicable to retrie

I think trying the above hack might worth

jneira commented 2 years ago

retrie should already have full support for windows, via #2513