Skip to content

Formatting with Brittany Fails When Warnings are Emitted #2005

Closed
@prikhi

Description

@prikhi

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.2.0.0 (GHC: 8.8.4) (PATH: /home/prikhi/.local/bin/haskell-language-server-wrapper) (GIT hash: b8bb06eb1b117943f4436a6fdafe5c09e76cac1c)
Tool versions found on the $PATH
cabal:		3.2.0.0
stack:		2.7.1
ghc:		8.10.5

Which OS do you use:
ArchLinux

Which lsp-client do you use:
Neovim + coc.nvim

Steps to reproduce

Chang formatter to brittany & attempt to format a file that contains type operators in a multi-line expression:

{-# LANGUAGE TypeOperators #-}
module HsOpTy where

-- brittany *should* remove the extra spaces between import & module name 
import     GHC.TypeLits

type Foo = 
  Int :
  '[]

See lspitzner/brittany#271 for more repros.
As noted in that issue, if you remove the newlines, formatting proceeds correctly

Expected behaviour

HLS ignores the warnings & uses the formatted text.
This is the behavior brittany's CLI tool exhibits:

$ cat test.hs
{-# LANGUAGE TypeOperators #-}
module HsOpTy where

import     GHC.TypeLits

type Foo =
  Int :
  '[]
$ brittany --write-mode display test.hs >/dev/null
WARNING: encountered unknown syntactical constructs:
  HsOpTy{} at test.hs:(7,3)-(8,5)
  -> falling back on exactprint for this element of the module
$ brittany --write-mode display test.hs 2>/dev/null
{-# LANGUAGE TypeOperators #-}
module HsOpTy where

import GHC.TypeLits

type Foo =
  Int :
  '[]

Actual behaviour

Nothing happens, following output appears in coc's HLS workspace output:

2021-07-08 00:11:10.475037968 [ThreadId 15168] INFO hls:	finish: brittany (took 0.00s)
[Error  - 12:11:10 AM] Request textDocument/formatting failed.
  Message: brittanyCmd: HsOpTy{}
HsOpTy{}
HsOpTy{}

  Code: -32602 

Include debug information

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

Debug output:
can't share actual dump, contains proprietary information...

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

LSP logs:
Found "/home/prikhi/code/backend-2/hie.yaml" for "/home/prikhi/code/backend-2/a"
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.2.0.0, Git revision b8bb06eb1b117943f4436a6fdafe5c09e76cac1c (dirty) (2297 commits) x86_64 ghc-8.8.4
Current directory: /home/prikhi/code/backend-2
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /home/prikhi/code/backend-2
Cradle type: Stack

Tool versions found on the $PATH
cabal:		3.2.0.0
stack:		2.7.1
ghc:		8.10.5


Consulting the cradle to get project GHC version...
Project GHC version: 8.8.4
haskell-language-server exe candidates: ["haskell-language-server-8.8.4","haskell-language-server"]
Launching haskell-language-server exe at:/home/prikhi/.local/bin/haskell-language-server-8.8.4
haskell-language-server version: 1.2.0.0 (GHC: 8.8.4) (PATH: /home/prikhi/.local/bin/haskell-language-server-8.8.4) (GIT hash: b8bb06eb1b117943f4436a6fdafe5c09e76cac1c)
Starting (haskell-language-server)LSP server...
  with arguments: GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "pragmas",PluginId "floskell",PluginId "fourmolu",PluginId "tactics",PluginId "ormolu",PluginId "stylish-haskell",PluginId "retrie",PluginId "brittany",PluginId "class",PluginId "haddockComments",PluginId "eval",PluginId "importLens",PluginId "refineImports",PluginId "moduleName",PluginId "hlint",PluginId "splice",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-code-actions-imports-exports",PluginId "ghcide-code-actions-type-signatures",PluginId "ghcide-code-actions-bindings",PluginId "ghcide-code-actions-fill-holes",PluginId "ghcide-completions",PluginId "ghcide-type-lenses",PluginId "ghcide-core"]
  in directory: /home/prikhi/code/backend-2
 Starting LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
Started LSP server in 0.00s
setInitialDynFlags cradle: Cradle {cradleRootDir = "/home/prikhi/code/backend-2", cradleOptsProg = CradleAction: Stack}
2021-07-08 00:09:22.425059367 [ThreadId 5] INFO hls:	Registering ide configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 4597480009621044856 "file:///home/prikhi/code/backend-2"], clientSettings = hashed (Just (Object (fromList [("haskell",Object (fromList [("hlintOn",Bool True),("formatOnImportOn",Bool True),("formattingProvider",String "brittany")]))])))}
2021-07-08 00:09:22.478204734 [ThreadId 89] INFO hls:	Consulting the cradle for "src/Api.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/prikhi/code/backend-2", cradleOptsProg = CradleAction: Stack}
> horrorscopeapp> configure (lib)
> Configuring horrorscopeapp-0.1.0.0...
> horrorscopeapp> initial-build-steps (lib)
> The following GHC options are incompatible with GHCi and have not been passed to it: -Werror
> Configuring GHCi with the following packages: horrorscopeapp
> /home/prikhi/code/backend-2/.stack-work/install/x86_64-linux-tinfo6/a6768a29cf9d734944d8ba2d6d60991c59641ad9d318a0f6ffa7df794775f31e/8.8.4/pkgdb:/home/prikhi/.stack/snapshots/x86_64-linux-tinfo6/a6768a29cf9d734944d8ba2d6d60991c59641ad9d318a0f6ffa7df794775f31e/8.8.4/pkgdb:/home/prikhi/.stack/programs/x86_64-linux/ghc-tinfo6-8.8.4/lib/ghc-8.8.4/package.conf.d
2021-07-08 00:09:26.458398216 [ThreadId 89] INFO hls:	Using interface files cache dir: /home/prikhi/.cache/ghcide/main-7f306e53217a845a4abeedac27a777551d74e0c3
2021-07-08 00:09:26.458763864 [ThreadId 89] INFO hls:	Making new HscEnv[main]
2021-07-08 00:10:46.055551279 [ThreadId 4709] INFO hls:	finish: brittany (took 0.00s)
[Error  - 12:10:46 AM] Request textDocument/formatting failed.
  Message: brittanyCmd: HsOpTy{}
HsOpTy{}
HsOpTy{}

  Code: -32602 
2021-07-08 00:11:02.181722538 [ThreadId 13441] INFO hls:	Typechecking reverse dependencies for NormalizedFilePath "/home/prikhi/code/backend-2/src/Api.hs": Just [NormalizedFilePath "/home/prikhi/code/backend-2/src/Interpret.hs",NormalizedFilePath "/home/prikhi/code/backend-2/src/Context.hs"]
2021-07-08 00:11:10.475037968 [ThreadId 15168] INFO hls:	finish: brittany (took 0.00s)
[Error  - 12:11:10 AM] Request textDocument/formatting failed.
  Message: brittanyCmd: HsOpTy{}
HsOpTy{}
HsOpTy{}

  Code: -32602 


Metadata

Metadata

Assignees

No one assigned

    Labels

    component: formattersstatus: blockedNot actionable, because blocked by upstream/GHC etc.type: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions