-
-
Notifications
You must be signed in to change notification settings - Fork 17
Use cabal-install-parsers and Cabal parser #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use cabal-install-parsers and Cabal parser #13
Conversation
Thanks, I take a look tomorrow. |
So this is the output of this pr on hls repo. cradle:
cabal:
- path: "./src"
component: "lib:haskell-language-server"
- path: "./exe/Main.hs"
component: "haskell-language-server:exe:haskell-language-server"
- path: "./exe/Wrapper.hs"
component: "haskell-language-server:exe:haskell-language-server-wrapper"
- path: "./test/utils"
component: "haskell-language-server:test:func-test"
- path: "./test/functional"
component: "haskell-language-server:test:func-test"
- path: "ghcide/src"
component: "lib:ghcide"
- path: "ghcide/test/preprocessor/Main.hs"
component: "ghcide:exe:ghcide-test-preprocessor"
- path: "ghcide/exe/Main.hs"
component: "ghcide:exe:ghcide"
- path: "ghcide/test/cabal"
component: "ghcide:test:ghcide-tests"
- path: "ghcide/test/exe"
component: "ghcide:test:ghcide-tests"
- path: "ghcide/test/src"
component: "ghcide:test:ghcide-tests" master outputs this: cradle:
cabal:
- path: "./src"
component: "lib:haskell-language-server"
- path: "./exe/Main.hs"
component: "haskell-language-server:exe:haskell-language-server"
- path: "./exe/Arguments.hs"
component: "haskell-language-server:exe:haskell-language-server"
- path: "./exe/Wrapper.hs"
component: "haskell-language-server:exe:haskell-language-server-wrapper"
- path: "./exe/Arguments.hs"
component: "haskell-language-server:exe:haskell-language-server-wrapper"
- path: "./test/functional"
component: "haskell-language-server:test:func-test"
- path: "ghcide/src"
component: "lib:ghcide"
- path: "ghcide/src-ghc86"
component: "lib:ghcide"
- path: "ghcide/src-ghc88"
component: "lib:ghcide"
- path: "ghcide/src-ghc810"
component: "lib:ghcide"
- path: "ghcide/test/preprocessor/Main.hs"
component: "ghcide:exe:ghcide-test-preprocessor"
- path: "ghcide/exe/Main.hs"
component: "ghcide:exe:ghcide"
- path: "ghcide/exe/Utils.hs"
component: "ghcide:exe:ghcide"
- path: "ghcide/exe/Arguments.hs"
component: "ghcide:exe:ghcide"
- path: "ghcide/exe/Paths_ghcide.hs"
component: "ghcide:exe:ghcide"
- path: "ghcide/test/cabal"
component: "ghcide:test:ghcide-tests"
- path: "ghcide/test/exe"
component: "ghcide:test:ghcide-tests"
- path: "ghcide/test/src"
component: "ghcide:test:ghcide-tests"
|
Yes, I did not yet implement By the way, what do you do in the case there are multiple |
Maybe I have not experimented with that case. |
mapM (\p -> if takeExtension p == ".cabal" then pure [p] else cfs p) cd | ||
pure $ concat cf | ||
case rights [cp, cl] of | ||
-- FIXME parse cabal files w/o project file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use here: parseProject "cabal.project" "packages: ./*.cabal ./*/*.cabal"
That is the default value in cabal-install for discovering packages when there is no exist a explicit cabal.project
Maybe a case not taken in account:
|
It seems it does not take in account conditionals (imo it is one of the keys reasons to use Cabal): For a library
exposed-modules: Lib
build-depends: base >=4.12 && <4.15
, bytestring
hs-source-dirs: src
default-language: Haskell2010
if os(windows)
hs-source-dirs: win-src
else
hs-source-dirs: nix-src the hie.yaml generated is): cradle:
cabal:
- path: "./src"
component: "lib:cabal-test"
- path: "./app/Main.hs"
component: "cabal-test:exe:cabal-test"
- path: "./test"
component: "cabal-test:test:cabal-test-test" Not sure how could we handle conditionals:
|
Thanks for the comments, @jneira! Re conditionals. As far as I understand, for every open file hie/hls would try to find matching prefix. Than I suppose that it's the right idea to generate all possible prefixes. In the normal scenario, user won't open files that belong to other conditionals, and therefore those prefixes will never be matched. I believe that resolving of the conditionals does not belong to this project. But of course, I may be wrong, I'm just a bystander :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re conditionals. As far as I understand, for every open file hie/hls would try to find matching prefix. Than I suppose that it's the right idea to generate all possible prefixes. In the normal scenario, user won't open files that belong to other conditionals, and therefore those prefixes will never be matched.
Yeah, that would be my preferred option but i am not sure if include all of them, always, could interfere in some cases with the ide.
I believe that resolving of the conditionals does not belong to this project.
Well, as i wrote in my comment i think that is one of the main points of include Cabal
and cabal-install-parsers
. This project dont have to fully resolve conditionals but imo it should resolve or analyze them up to being able to generate a reliable hie.yaml
.
How about we come up with a definition of reliable first, then? :) |
Well, reliable can be pretty ambiguous term, fortunately we already have two alternatives that can be used a bounds of what can be a reliable way to get a hie-bios configuration:
We have take in account that one of the goals of the library is to being used as the implicit configuration with no More context (apart of the pr linked by @Avi-D-coder above): What would be the improvements in the generated config using this pr instead the actual custom parser? does it handle common stanzas? |
It does, although using them within executable components generates a little bit strange file. For this cabal file common mycommon
hs-source-dirs: common-src
library
import: mycommon
exposed-modules: Lib
build-depends: base >=4.12 && <4.15
, bytestring
hs-source-dirs: src
default-language: Haskell2010
if os(windows)
hs-source-dirs: win-src
else
hs-source-dirs: nix-src
executable cabal-test
import: mycommon
main-is: Main.hs
build-depends: base >=4.12 && <4.15
, cabal-test
, bytestring
hs-source-dirs: app
default-language: Haskell2010 that is the output of this version: cradle:
cabal:
- path: "./common-src"
component: "lib:cabal-test"
- path: "./src"
component: "lib:cabal-test"
- path: "./common-src/Main.hs"
component: "cabal-test:exe:cabal-test"
- path: "./app/Main.hs"
component: "cabal-test:exe:cabal-test"
- path: "./test"
component: "cabal-test:test:cabal-test-test" Observe the Otoh, the actual lib version includes some condition handling! cradle:
cabal:
- path: "./src"
component: "lib:cabal-test"
- path: "./win-src"
component: "lib:cabal-test"
- path: "./nix-src"
component: "lib:cabal-test"
- path: "./app/Main.hs"
component: "cabal-test:exe:cabal-test"
- path: "./test"
component: "cabal-test:test:cabal-test-test" So not handling them would be even a regression. |
For completeness, this is the cradle:
cabal:
- path: "common-src\"
component: "lib:cabal-test"
- path: "src\"
component: "lib:cabal-test"
- path: "win-src\"
component: "lib:cabal-test"
- path: "common-src\"
component: "cabal-test:exe:cabal-test"
- path: "app\"
component: "cabal-test:exe:cabal-test"
- path: "test\"
component: "cabal-test:test:cabal-test-test" As expected, it resolves the conditions with the actual flags values (i am on windows) and handles common stanzas the right way. |
My primary motivation was to make
Right, I haven't yet done traversing of conditional tree. I probably should just use |
That is a really good point.
Well, it is a possible path; it resolves conditions without having to set flags values (you would need a full config execution to get them). Afaik it merges all branches so maybe it gives us what we need. |
Superseded by #48 |
This is a draft PR to provoke discussion.
I came across http://hackage.haskell.org/package/cabal-install-parsers-0.3.0.1/docs/Cabal-Project.html, which was made for
haskell-ci
, and I thought that it could be a good idea to use this parser here instead of hand-written one.What do you think?