implicit-hie icon indicating copy to clipboard operation
implicit-hie copied to clipboard

Parsing `cabal.project` fails when its content is "packages: ..." without a trailing newline

Open kztk-m opened this issue 1 year ago • 2 comments

gen-hie fails to parse cabal.project when it consists only of the field "packages" without a trailing newline.

Suppose that the current directly contains proj, which contains proj.cabal with certain content.

$ ls 
proj
$ ls proj 
LICENSE     app/        proj.cabal

Then, if we generate cabal.project whose content is "packages: ..." without a trailing newline, gen-hie fails to parse the file.

$ echo -n "packages: proj/*.cabal" > cabal.project
$ gen-hie
Used cabal
 No .cabal files found under/Users/kztk/prog/haskell/cabal_package_f
 You may need to run stack build.

On the other hand, if the cabal.project has a trailing newline, everything works as expected.

$ echo  "packages: proj/*.cabal" > cabal.project
$ gen-hie 
cradle:
  cabal:
    - path: "proj/app/Main.hs"
      component: "proj:exe:proj"

I confirmed the above issue with implicit-hie 0.1.4.0.

I suspect this issue would be caused by the function field called by extractPkgs in src/Hie/Cabal/Parser.hs, which requires the newline in the end by calling skipToNextLine.

kztk-m avatar Feb 20 '24 11:02 kztk-m

Thank you for the report. PRs welcome!

Avi-D-coder avatar Feb 20 '24 15:02 Avi-D-coder

I have created the PR https://github.com/Avi-D-coder/implicit-hie/pull/55#issue-2146007723 for this issue.

kztk-m avatar Feb 21 '24 07:02 kztk-m