Haskell-language-server: Failed to parse results of calling cabal for preprocessed files in build directory

Created on 6 Aug 2020  路  14Comments  路  Source: haskell/haskell-language-server

I have a problem with haskell-language-server. I use alex+happy and they generate files inside the dist-newstyle directory. Cabal can't repl those files because of the "Unrecognized target" error:

Expected a meta-target 'all' or component kind filter or component name or
package name or package directory or package .cabal file or component name or
module name or file, rather than

So hls also refuses to work.

My setup:
vscode
ghc-8.8.4
Kubuntu 20.04

hie-bios bug

Most helpful comment

Ok, 0.5.0 seems to work for me.

All 14 comments

I'm not sure if we have support (yet) for preprocessed files, especially the ones generated in dist-newstyle. Can you provide an example project where this occurs anyway?

I'm not sure if we have support (yet) for preprocessed files, especially the ones generated in dist-newstyle. Can you provide an example project where this occurs anyway?

Can we ignore such files somehow?

Yes, you can specify certain files to ignore with a hie.yaml file in your project root by specifying what component each file should build, or specifying a "none cradle" if it shouldn't be built:

cradle:
  multi:
    - path: "./src"
      config: { cradle: {cabal: {component: "lib:foo"}} }
    - path: "./test"
      config: { cradle: {cabal: {component: "test:blah"}} }
    - path: "dist-newstyle"
      config: { cradle: { none: } }

It didn't work.

"Error in $.cradle: Expected an object with path and component keys"

A configuration that might work could be:

cradle:
    multi:
    - path: "dist-newstyle"
      config: { cradle: { none:  } }
    - path: "./"
      config: 
        cradle:
          cabal:
            - path: "./"
              component: "lib:cabal-test"

            - path: "app/Main.hs"
              component: "cabal-test:exe:cabal-test"

            - path: "test"
              component: "cabal-test:test:cabal-test-test"

@Abbath You can check a complete hie-yaml configuration syntax here (including a example on how to ignore directories): https://github.com/mpickering/hie-bios#ignoring-directories

@jneira didn't work either

@Abbath Would you mind showing some logs?
E.g. show your hie.yaml and the output of haskell-language-server <some-file-path-to-load>

hie.yaml:

cradle:
    multi:
    - path: "dist-newstyle"
      config: { cradle: { none:  } }
    - path: "./"
      config: 
        cradle:
          cabal:
            - path: "./src"
              component: "lib:Calculator"
            - path: "./src-exe"
              component: "exe:Calculator"
            - path: "./src-test"
              component: "test:Test"

logs:

$ /home/a66ath/.vscode-server/data/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-linux-8.8.4 src/Calculator.hs
haskell-language-server version: 0.2.2.0 (GHC: 8.8.4) (PATH: /home/a66ath/.vscode-server/data/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-linux-8.8.4) (GIT hash: e44f618c11b7978264a94beeee00d1f014867f6d)
(haskell-language-server)Ghcide setup tester in /home/a66ath/Calculator/Calculator.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/a66ath/Calculator/Calculator
Found 1 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 "/home/a66ath/Calculator/Calculator/src/Calculator.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/a66ath/Calculator/Calculator", cradleOptsProg = CradleAction: Cabal}
> Resolving dependencies...
> Build profile: -w ghc-8.8.4 -O1
> In order, the following will be built (use -v for more details):
>  - telegram-api-0.7.2.0 (lib) (configuration changed)
>  - telegram-bot-simple-0.2.0 (lib) (configuration changed)
>  - Calculator-0.5.1.0 (lib) (configuration changed)
> Configuring library for telegram-api-0.7.2.0..
> Configuring library for telegram-bot-simple-0.2.0..
> Preprocessing library for telegram-api-0.7.2.0..
> Preprocessing library for telegram-bot-simple-0.2.0..
> Building library for telegram-api-0.7.2.0..
> Building library for telegram-bot-simple-0.2.0..
> Configuring library for Calculator-0.5.1.0..
> Preprocessing library for Calculator-0.5.1.0..
[INFO] Using interface files cache dir: /home/a66ath/.cache/ghcide/Calculator-0.5.1.0-inplace-6ca23d00130b3ce21152f0751d05d3beeea8e402
[INFO] Making new HscEnv[Calculator-0.5.1.0-inplace]
[INFO] Consulting the cradle for "/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/a66ath/Calculator", cradleOptsProg = CradleAction: Cabal}
> cabal: Unrecognised target
> '/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs'.
> Expected a meta-target 'all' or component kind filter or component name or
> package name or package directory or package .cabal file or component name or
> module name or file, rather than
> '/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs'.
>
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs
Hidden:   no
Range:    1:0-2:0
Source:   cradle
Severity: DsError
Message:
  Failed to parse result of calling cabal

  cabal: Unrecognised target
  '/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs'.
  Expected a meta-target 'all' or component kind filter or component name or
  package name or package directory or package .cabal file or component name or
  module name or file, rather than
  '/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs'.



[INFO] finish: User TypeCheck (took 0.19s)
Files that failed:
 * /home/a66ath/Calculator/Calculator/src/Calculator.hs

Completed (0 files worked, 1 file failed)

Thank you! The cradle root directory seems to be off:

Cradle 
  { cradleRootDir = "/home/a66ath/Calculator/Calculator"
  , cradleOptsProg = CradleAction: Cabal
  }

and the respective path: Consulting the cradle for "/home/a66ath/Calculator/Calculator/src/Calculator.hs"
while the path with dist-newstyle is:
/home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/HappyParser.hs'

Note the discrepancy between:
/home/a66ath/Calculator/Calculator/
and
/home/a66ath/Calculator/dist-newstyle/

So, my hunch would be that hie.yaml is located in "/home/a66ath/Calculator/Calculator" and it should be located in the parent directory. In general, it should be on the same level as any stack.yaml/cabal.project.
If this hunch is wrong, could you share your project or at least show the project structure in more details? E.g. cabal.project, *.cabal files and directory structure

@fendor ok, it fixed the Unrecognized target problem. But it still breaks on an Alex-generated file.

$ /home/a66ath/.vscode-server/data/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-linux-8.8.4 src/Calculator.hs
haskell-language-server version: 0.2.2.0 (GHC: 8.8.4) (PATH: /home/a66ath/.vscode-server/data/User/globalStorage/haskell.haskell/haskell-language-server-0.2.2-linux-8.8.4) (GIT hash: e44f618c11b7978264a94beeee00d1f014867f6d)
(haskell-language-server)Ghcide setup tester in /home/a66ath/Calculator/Calculator.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/a66ath/Calculator/Calculator
Found 1 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 "/home/a66ath/Calculator/Calculator/src/Calculator.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/a66ath/Calculator", cradleOptsProg = CradleAction: Cabal}
> Resolving dependencies...
> Build profile: -w ghc-8.8.4 -O1
> In order, the following will be built (use -v for more details):
>  - telegram-api-0.7.2.0 (lib) (configuration changed)
>  - telegram-bot-simple-0.2.0 (lib) (configuration changed)
>  - Calculator-0.5.1.0 (lib) (configuration changed)
> Configuring library for telegram-api-0.7.2.0..
> Configuring library for telegram-bot-simple-0.2.0..
> Preprocessing library for telegram-api-0.7.2.0..
> Preprocessing library for telegram-bot-simple-0.2.0..
> Building library for telegram-api-0.7.2.0..
> Building library for telegram-bot-simple-0.2.0..
> Configuring library for Calculator-0.5.1.0..
> Preprocessing library for Calculator-0.5.1.0..
[INFO] Using interface files cache dir: /home/a66ath/.cache/ghcide/Calculator-0.5.1.0-inplace-6ca23d00130b3ce21152f0751d05d3beeea8e402
[INFO] Making new HscEnv[Calculator-0.5.1.0-inplace]
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    38:0-38:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_1 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    39:0-39:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_2 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    40:0-40:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_3 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    41:0-41:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_4 :: p -> String -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    42:0-42:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_5 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    43:0-43:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_6 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    44:0-44:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_7 :: p -> String -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    45:0-45:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_8 :: p -> String -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    46:0-46:13
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_9 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    47:0-47:14
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_10 :: p -> String -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    48:0-48:14
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_action_11 :: p1 -> p2 -> Token
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    60:0-60:21
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alexIndexInt16OffAddr :: AlexAddr -> Int# -> Int#
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    389:0-389:14
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alexScanTokens :: String -> [Token]
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    451:0-451:11
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_accept :: Array Int (AlexAcc user)
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    473:0-473:12
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alex_actions :: Array Int (p -> String -> Token)
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    613:0-613:21
Source:   typecheck
Severity: DsError
Message:  Top-level binding with no type signature:alexIndexInt32OffAddr :: AlexAddr -> Int# -> Int#
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    638:0-638:10
Source:   typecheck
Severity: DsError
Message:
  Top-level binding with no type signature:
  quickIndex :: Array Int (AlexAcc Any) -> Int -> AlexAcc Any
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    654:0-654:8
Source:   typecheck
Severity: DsError
Message:
  Top-level binding with no type signature:
  alexScan :: (AlexPosn, Char, [Byte], String)
  -> Int -> AlexReturn (p -> String -> Token)
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    657:0-657:12
Source:   typecheck
Severity: DsError
Message:
  Top-level binding with no type signature:
  alexScanUser :: t
  -> (AlexPosn, Char, [Byte], String)
  -> Int
  -> AlexReturn (p -> String -> Token)
File:
  /home/a66ath/Calculator/dist-newstyle/build/x86_64-linux/ghc-8.8.4/Calculator-0.5.1.0/build/Calculator/AlexLexer.hs
Hidden:   no
Range:    688:0-688:13
Source:   typecheck
Severity: DsError
Message:
  Top-level binding with no type signature:
  alex_scan_tkn :: t1
  -> t2
  -> Int#
  -> AlexInput
  -> Int#
  -> AlexLastAcc
  -> (AlexLastAcc, (AlexPosn, Char, [Byte], String))
Files that failed:
[INFO] finish: User TypeCheck (took 0.46s) * /home/a66ath/Calculator/Calculator/src/Calculator.hs


Completed (0 files worked, 1 file failed)

I can reproduce the issue. Unfortunately, I currently can not provide an easy fix.
@alanz How do you handle generated files with hls?

@fendor I would say push this to ghcide?

Ok, 0.5.0 seems to work for me.

Was this page helpful?
0 / 5 - 0 ratings