haskell / haskell-language-server

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

Formatting with Brittany does nothing #412

Closed vaclavsvejcar closed 3 years ago

vaclavsvejcar commented 4 years ago

Hello,

first of all, thanks a lot for such amazing project, which makes coding Haskell in VSCode fantastic experience!

I'm facing strange behaviour when trying to format code with Brittany. Any other formatter works just fine from VSCode, but when hitting the shortcut for formatting when Brittany is selected, nothing happens, and I'm getting this weird error message in output log:

/Users/runner/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/settings: openFile: does not exist (No such file or directory)
2020-09-18 17:53:20.552435 [ThreadId 25] - Unexpected exception on request, please report!
Message: RequestMessage {_jsonrpc = "2.0", _id = IdInt 74, _method = TextDocumentFormatting, _params = DocumentFormattingParams {_textDocument = TextDocumentIdentifier {_uri = Uri {getUri = "file:///Users/svejcar/Repos/vcs-ignore/src/Data/VCS/Ignore/Repo/Git.hs"}}, _options = FormattingOptions {_tabSize = 2, _insertSpaces = True}, _workDoneToken = Nothing}}
Exception: ExitFailure 1
[Error - 5:53:20 PM] Request textDocument/formatting failed.
  Message: ExitFailure 1
  Code: -32603 

No idea how it get the /Users/runner/, because that's not my user and such user is not present on my system. Any ideas what could be wrong?

Environment

jneira commented 4 years ago

hi, thanks for the bug report, could you attach the log of a vscode session (it is in the output pane)?

vaclavsvejcar commented 4 years ago

Hi, sure, I'm just not sure which one you need, is it that one under the Haskell combo box?

[client] run command: "/Users/svejcar/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.4.0-darwin-8.8.4 --lsp"
[client] debug command: "/Users/svejcar/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.4.0-darwin-8.8.4 --lsp"
[client] server cwd: undefined
haskell-language-server version: 0.4.0.0 (GHC: 8.8.4) (PATH: /Users/svejcar/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.4.0-darwin-8.8.4) (GIT hash: 0a18edde24923251a148cbbc0ae993a6aac83b9c)
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"]
  in directory: /Users/svejcar/Repos/vcs-ignore
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-09-18 18:32:14.047873 [ThreadId 25] - Opened text document: file:///Users/svejcar/Repos/vcs-ignore/src/Data/VCS/Ignore/Repo/Git.hs
2020-09-18 18:32:14.049393 [ThreadId 74] - Data.HashMap.Internal.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Internal.hs:753:16 in nrdrd-cntnrs-0.2.12.0-5534510c:Data.HashMap.Internal
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-09-18 18:32:14.049989 [ThreadId 77] - Consulting the cradle for "/Users/svejcar/Repos/vcs-ignore/src/Data/VCS/Ignore/Repo/Git.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/svejcar/Repos/vcs-ignore", cradleOptsProg = CradleAction: Stack}
> Configuring GHCi with the following packages: vcs-ignore
> /Users/svejcar/Repos/vcs-ignore/.stack-work/install/x86_64-osx/b0a747ba583e7f5aaa2fbf5fb966aca03092442f703cd512ecb8052d750b4219/8.8.4/pkgdb:/Users/svejcar/.stack/snapshots/x86_64-osx/b0a747ba583e7f5aaa2fbf5fb966aca03092442f703cd512ecb8052d750b4219/8.8.4/pkgdb:/Users/svejcar/.stack/programs/x86_64-osx/ghc-8.8.4/lib/ghc-8.8.4/package.conf.d
2020-09-18 18:32:16.196118 [ThreadId 77] - Using interface files cache dir: /Users/svejcar/.cache/ghcide/main-e37e6fdb07dca35e18d03dad4fa56e132979cb13
2020-09-18 18:32:16.196282 [ThreadId 77] - Making new HscEnv[main]
2020-09-18 18:32:16.496005 [ThreadId 720] - finish: InitialLoad (took 0.28s)
2020-09-18 18:32:16.496801 [ThreadId 720] - finish: CodeAction (took 0.00s)
2020-09-18 18:32:16.498719 [ThreadId 720] - finish: InitialLoad (took 0.00s)
2020-09-18 18:32:16.50556 [ThreadId 720] - finish: InitialLoad (took 0.01s)
2020-09-18 18:32:16.508611 [ThreadId 720] - finish: InitialLoad (took 0.00s)
2020-09-18 18:32:16.511464 [ThreadId 720] - finish: InitialLoad (took 0.00s)
2020-09-18 18:32:16.516943 [ThreadId 720] - finish: InitialLoad (took 0.01s)
2020-09-18 18:32:16.521224 [ThreadId 720] - finish: InitialLoad (took 0.00s)
2020-09-18 18:32:16.704986 [ThreadId 724] - Plugin.makeCodeLens (ideLogger)
2020-09-18 18:32:16.970245 [ThreadId 726] - finish: CodeAction:PackageExports (took 0.45s)
2020-09-18 18:32:16.970496 [ThreadId 726] - finish: codeLens (took 0.00s)
2020-09-18 18:32:16.970818 [ThreadId 726] - finish: importLens (took 0.00s)
2020-09-18 18:32:16.970933 [ThreadId 726] - finish: importLens (took 0.00s)
2020-09-18 18:32:16.971389 [ThreadId 726] - finish: CodeAction (took 0.00s)
2020-09-18 18:32:16.971509 [ThreadId 726] - finish: CodeAction:PackageExports (took 0.00s)
2020-09-18 18:33:12.177162 [ThreadId 732] - DocumentHighlight request at position 24:41 in file: /Users/svejcar/Repos/vcs-ignore/src/Data/VCS/Ignore/Repo/Git.hs
2020-09-18 18:33:12.417301 [ThreadId 734] - finish: CodeAction (took 0.00s)
2020-09-18 18:33:12.417515 [ThreadId 734] - finish: CodeAction:PackageExports (took 0.00s)
2020-09-18 18:33:13.444034 [ThreadId 734] - finish: Formatter (took 0.00s)
/Users/runner/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/settings: openFile: does not exist (No such file or directory)
2020-09-18 18:33:13.44728 [ThreadId 25] - Unexpected exception on request, please report!
Message: RequestMessage {_jsonrpc = "2.0", _id = IdInt 7, _method = TextDocumentFormatting, _params = DocumentFormattingParams {_textDocument = TextDocumentIdentifier {_uri = Uri {getUri = "file:///Users/svejcar/Repos/vcs-ignore/src/Data/VCS/Ignore/Repo/Git.hs"}}, _options = FormattingOptions {_tabSize = 2, _insertSpaces = True}, _workDoneToken = Nothing}}
Exception: ExitFailure 1
[Error - 6:33:13 PM] Request textDocument/formatting failed.
  Message: ExitFailure 1
  Code: -32603 
andys8 commented 4 years ago

No idea how it get the /Users/runner/, because that's not my user

It could be baked into the binary, when it was compiler on a different machine and runner being the user on Ci.

jneira commented 4 years ago

@vaclavsvejcar Well, an ugly workaround could be create that file (/Users/runner/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/settings), copying it from your actual ghc installation, to make brittany happy, while we investigate the bug.

fendor commented 4 years ago

@jneira I think that happens because brittany uses ghc-paths and not our given libdir path. That problem existed in HIE, too.

AtomToast commented 4 years ago

Same issue over here but for me it says:

/opt/ghc/8.8.4/lib/ghc-8.8.4/settings: openFile: does not exist (No such file or directory)

Here is the whole LSP log:

Started LSP server in 0.09s
2020-09-23 16:17:33.115891859 [ThreadId 17] - Opened text document: file:///home/kjell/git/done/src/lib/Lib.hs
2020-09-23 16:17:33.116831214 [ThreadId 49] - Data.HashMap.Internal.(!): key not found
CallStack (from HasCallStack):
  error, called at ./Data/HashMap/Internal.hs:753:16 in unordered-containers-0.2.12.0-2e3fe165d2481c3a755449eca3083a286519fe98ac20523b8f479e0645004f51:Data.HashMap.Internal
  !, called at src/Development/IDE/Import/DependencyInformation.hs:107:40 in ghcide-0.2.0-inplace:Development.IDE.Import.DependencyInformation
2020-09-23 16:17:33.117666904 [ThreadId 53] - Consulting the cradle for "/home/kjell/git/done/src/lib/Lib.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/kjell/git/done", cradleOptsProg = CradleAction: Cabal}
2020-09-23 16:17:35.124103558 [ThreadId 62] - Plugin.makeCodeLens (ideLogger)
> Resolving dependencies...
> Build profile: -w ghc-8.8.4 -O1
> In order, the following will be built (use -v for more details):
>  - done-0.1.0.0 (lib) (configuration changed)
> Configuring library for done-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library for done-0.1.0.0..
2020-09-23 16:17:41.248329734 [ThreadId 53] - Using interface files cache dir: /home/kjell/.cache/ghcide/done-0.1.0.0-inplace-ff925d4da6d67c8d9968d1fcfd6557a1202d8565
2020-09-23 16:17:41.248713461 [ThreadId 53] - Making new HscEnv[done-0.1.0.0-inplace]
2020-09-23 16:17:42.370673022 [ThreadId 403] - finish: codeLens (took 1.11s)
2020-09-23 16:17:42.371719972 [ThreadId 410] - finish: InitialLoad (took 0.00s)
2020-09-23 16:17:42.371926763 [ThreadId 410] - finish: importLens (took 0.00s)
2020-09-23 16:17:42.372086743 [ThreadId 410] - finish: importLens (took 0.00s)
2020-09-23 16:17:42.372463143 [ThreadId 413] - Plugin.makeCodeLens (ideLogger)
2020-09-23 16:17:42.372779796 [ThreadId 410] - finish: codeLens (took 0.00s)
2020-09-23 16:17:42.373086547 [ThreadId 410] - finish: importLens (took 0.00s)
2020-09-23 16:17:42.373241974 [ThreadId 410] - finish: importLens (took 0.00s)
2020-09-23 16:17:53.828555386 [ThreadId 410] - finish: Formatter (took 0.00s)
/opt/ghc/8.8.4/lib/ghc-8.8.4/settings: openFile: does not exist (No such file or directory)
2020-09-23 16:17:53.834339932 [ThreadId 17] - Unexpected exception on request, please report!
Message: RequestMessage {_jsonrpc = "2.0", _id = IdInt 3, _method = TextDocumentFormatting, _params = DocumentFormattingParams {_textDocument = TextDocumentIdentifier {_uri = Uri {getUri = "file:///home/kjell/git/done/src/lib/Lib.hs"}}, _options = FormattingOptions {_tabSize = 2, _insertSpaces = True}, _workDoneToken = Nothing}}
Exception: ExitFailure 1
[Error  - 4:17:53 PM] Request textDocument/formatting failed.
  Message: ExitFailure 1
  Code: -32603
2020-09-23 16:19:53.517319514 [ThreadId 419] - Plugin.makeCodeLens (ideLogger)
2020-09-23 16:19:53.517807261 [ThreadId 410] - finish: codeLens (took 0.00s)
2020-09-23 16:19:53.518305858 [ThreadId 410] - finish: importLens (took 0.00s)
2020-09-23 16:19:53.518485996 [ThreadId 410] - finish: importLens (took 0.00s)

Note: this is not with vscode but with neovim and coc.nvim

AtomToast commented 4 years ago

@vaclavsvejcar Well, an ugly workaround could be create that file (/Users/runner/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/settings), copying it from your actual ghc installation, to make brittany happy, while we investigate the bug.

I can also confirm that this works. I just created a symlink at /opt/ghc/8.8.4 pointing to the actual directory of my ghc installation and formatting with brittany works now. However this doesn't feel like an actual solution

jneira commented 4 years ago

However this doesn't feel like an actual solution

absolutely it does not, only a temporary workaround to not have to wait to the fix

AtomToast commented 4 years ago

I am currently in a project and we have a nice setup with nix that just sets up everything for everyone, having to manually create symlinks to potentially random locations on the system adds a lot of complexity. What I am trying to say is that this potential bandaid hopefully shouldn't drop the importance of the issue since often temporary solutions quickly become quite permanent

vaclavsvejcar commented 4 years ago

I can confirm as well that ln -s /Users/svejcar/.stack/programs/x86_64-osx/ghc-8.8.4/ /Users/runner/.ghcup/ghc/8.8.4 works for me, even though it's ugly and unfortunate that some user (or CI) specific path is baked somewhere inside the binary.

jneira commented 4 years ago