Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Formatting with Brittany does nothing #412

Closed
vaclavsvejcar opened this issue Sep 18, 2020 · 11 comments · Fixed by #1225
Closed

Formatting with Brittany does nothing #412

vaclavsvejcar opened this issue Sep 18, 2020 · 11 comments · Fixed by #1225
Labels
can-workaround component: plugins status: blocked Not actionable, because blocked by upstream/GHC etc. type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@vaclavsvejcar
Copy link

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

  • macOS 10.15.6
  • VSCode 1.49.1
  • vscode-haskell 1.1.0
  • HLS 0.4.0.0
  • GHC 8.8.4
@jneira jneira transferred this issue from haskell/vscode-haskell Sep 18, 2020
@jneira jneira added component: plugins type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Sep 18, 2020
@jneira
Copy link
Member

jneira commented Sep 18, 2020

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

@vaclavsvejcar
Copy link
Author

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
Copy link
Collaborator

andys8 commented Sep 22, 2020

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
Copy link
Member

jneira commented Sep 23, 2020

@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.

@jneira jneira added the status: needs info Not actionable, because there's missing information label Sep 23, 2020
@fendor
Copy link
Collaborator

fendor commented Sep 23, 2020

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

@AtomToast
Copy link

AtomToast commented Sep 23, 2020

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
Copy link

@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
Copy link
Member

jneira commented Sep 23, 2020

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
Copy link

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

@jneira jneira removed the status: needs info Not actionable, because there's missing information label Sep 23, 2020
@vaclavsvejcar
Copy link
Author

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
Copy link
Member

jneira commented Sep 25, 2020

@jneira jneira added the status: blocked Not actionable, because blocked by upstream/GHC etc. label Sep 25, 2020
pepeiborra added a commit that referenced this issue Dec 27, 2020
* parse lsp client configuration to track workspace roots

* Only use Watched files on workspace files

* Apply suggestions from code review

Co-Authored-By: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* Add tests for watched files

Left as future work: adding tests for workspace folder notifications

* Add a test for file creation outside workspace

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
@jneira jneira linked a pull request Jan 18, 2021 that will close this issue
@mergify mergify bot closed this as completed in #1225 Jan 19, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
can-workaround component: plugins status: blocked Not actionable, because blocked by upstream/GHC etc. type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants