Skip to content
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 implicit-hie #178

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
packages: .

source-repository-package
type: git
location: https://github.com/Avi-D-coder/implicit-hie.git
tag: 58d729310b9eb627e7e1dfcc3e42862cf1606e44
3 changes: 2 additions & 1 deletion hie-bios.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Library
hslogger >= 1.2 && < 1.4,
file-embed >= 0.0.11 && < 1,
conduit >= 1.3 && < 2,
conduit-extra >= 1.3 && < 2
conduit-extra >= 1.3 && < 2,
implicit-hie


Executable hie-bios
Expand Down
53 changes: 45 additions & 8 deletions src/HIE/Bios/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Control.Applicative ((<|>))
import System.IO.Temp
import System.IO.Error (isPermissionError)
import Data.List
import Data.Maybe
import Data.Ord (Down(..))

import System.PosixCompat.Files
Expand All @@ -49,8 +50,12 @@ import qualified Data.Conduit.Combinators as C
import qualified Data.Conduit as C
import qualified Data.Conduit.Text as C
import qualified Data.Text as T
import Data.Maybe (fromMaybe)
import qualified Data.Text.IO as T
import GHC.Fingerprint (fingerprintString)

import Hie.Cabal.Parser
import Hie.Yaml
import Hie.Locate
----------------------------------------------------------------

-- | Given root\/foo\/bar.hs, return root\/hie.yaml, or wherever the yaml file was found.
Expand Down Expand Up @@ -88,13 +93,13 @@ getCradle :: (b -> Cradle a) -> (CradleConfig b, FilePath) -> Cradle a
getCradle buildCustomCradle (cc, wdir) = addCradleDeps cradleDeps $ case cradleType cc of
Cabal mc -> cabalCradle wdir mc
CabalMulti ms ->
getCradle buildCustomCradle $
getCradle buildCustomCradle
(CradleConfig cradleDeps
(Multi [(p, CradleConfig [] (Cabal (Just c))) | (p, c) <- ms])
, wdir)
Stack mc -> stackCradle wdir mc
StackMulti ms ->
getCradle buildCustomCradle $
getCradle buildCustomCradle
(CradleConfig cradleDeps
(Multi [(p, CradleConfig [] (Stack (Just c))) | (p, c) <- ms])
, wdir)
Expand Down Expand Up @@ -128,9 +133,23 @@ implicitConfig' fp = (\wdir ->
(Bios (wdir </> ".hie-bios") Nothing, wdir)) <$> biosWorkDir fp
-- <|> (Obelisk,) <$> obeliskWorkDir fp
-- <|> (Bazel,) <$> rulesHaskellWorkDir fp
<|> (stackExecutable >> (Stack Nothing,) <$> stackWorkDir fp)
<|> ((Cabal Nothing,) <$> cabalWorkDir fp)

<|> (cabalExecutable >> cabalProjectDir fp >> cabalDistDir fp >>= cabal)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a major bug when I run this on the haskell-language-server repo hie-bios picks cabal before getting here. I tried changing the order so stack is first, but it picks before implicitConfig'

❯ rm -rf dist-newstyle
❯ stack build
❯ hie-bios debug src/Ide/Cradle.hs         
Cradle failed to load
Exit Code: ExitFailure 1
Stderr: Failed to parse result of calling cabal
Resolving dependencies...

From https://github.com/Avi-D-coder/hie-bios
 + 6d95e03...63e6e56 master     -> origin/master  (forced update)
Previous HEAD position was b67ebfd Use single file hie-implicit
HEAD is now at 63e6e56 Use single file hie-implicit
Warning: Requested index-state2020-05-05T17:33:00Z is newer than
'hackage.haskell.org'! Falling back to older state (2020-05-02T22:21:20Z).
cabal: Could not resolve dependencies:
[__0] trying: ghcide-0.1.0 (user goal)
[__1] next goal: haskell-lsp-types (dependency of ghcide)
[__1] rejecting: haskell-lsp-types-0.21.0.0, haskell-lsp-types-0.20.0.0,
haskell-lsp-types-0.19.0.0, haskell-lsp-types-0.18.0.0,
haskell-lsp-types-0.17.0.0, haskell-lsp-types-0.16.0.0,
haskell-lsp-types-0.15.0.0, haskell-lsp-types-0.14.0.1,
haskell-lsp-types-0.14.0.0, haskell-lsp-types-0.13.0.0,
haskell-lsp-types-0.12.1.0, haskell-lsp-types-0.12.0.0,
haskell-lsp-types-0.11.0.0, haskell-lsp-types-0.10.0.0,
haskell-lsp-types-0.9.0.0, haskell-lsp-types-0.8.2.0,
haskell-lsp-types-0.8.0.1, haskell-lsp-types-0.8.0.0,
haskell-lsp-types-0.7.0.0, haskell-lsp-types-0.6.0.0,
haskell-lsp-types-0.5.0.0, haskell-lsp-types-0.4.0.0,
haskell-lsp-types-0.2.2.0, haskell-lsp-types-0.2.1.0,
haskell-lsp-types-0.15.0.1 (conflict: ghcide => haskell-lsp-types==0.22.*)
[__1] fail (backjumping, conflict set: ghcide, haskell-lsp-types)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ghcide, haskell-lsp-types

<|> (stackExecutable >> stackYamlDir fp >> stackWorkDir fp >>= stack)
<|> (cabalExecutable >> cabalProjectDir fp >>= cabal)
<|> (stackExecutable >> stackYamlDir fp >>= stack)
<|> (cabalExecutable >> cabalFile fp >>= cabal)
where
readPkgs f gp p = do
cfs <- gp p
pkgs <- liftIO $ catMaybes <$> mapM (nestedPkg p) cfs
pure $ concatMap (components f) pkgs
build cn cc gp p = do
c <- cn <$> readPkgs cc gp p
pure (c, p)
cabal :: FilePath -> MaybeT IO (CradleType a, FilePath)
cabal = build CabalMulti cabalComponent cabalPkgs
stack = build StackMulti stackComponent stackYamlPkgs
components f (Package n cs) = map (f n) cs

yamlConfig :: FilePath -> MaybeT IO FilePath
yamlConfig fp = do
Expand Down Expand Up @@ -456,12 +475,25 @@ removeRTS [] = []
removeVerbosityOpts :: [String] -> [String]
removeVerbosityOpts = filter ((&&) <$> (/= "-v0") <*> (/= "-w"))

cabalExecutable :: MaybeT IO FilePath
cabalExecutable = MaybeT $ findExecutable "cabal"

cabalDistDir :: FilePath -> MaybeT IO FilePath
cabalDistDir = findFileUpwards isCabal
where
-- TODO do old style dist builds work?
isCabal name = name == "dist-newstyle" || name == "dist"

cabalWorkDir :: FilePath -> MaybeT IO FilePath
cabalWorkDir = findFileUpwards isCabal
cabalProjectDir :: FilePath -> MaybeT IO FilePath
cabalProjectDir = findFileUpwards isCabal
where
isCabal name = name == "cabal.project"

cabalFile :: FilePath -> MaybeT IO FilePath
cabalFile = findFileUpwards isCabal
where
isCabal = (".cabal" ==) . takeExtension

------------------------------------------------------------------------
-- Stack Cradle
-- Works for by invoking `stack repl` with a wrapper script
Expand Down Expand Up @@ -515,6 +547,11 @@ stackExecutable = MaybeT $ findExecutable "stack"

stackWorkDir :: FilePath -> MaybeT IO FilePath
stackWorkDir = findFileUpwards isStack
where
isStack name = name == ".stack-work"

stackYamlDir :: FilePath -> MaybeT IO FilePath
stackYamlDir = findFileUpwards isStack
where
isStack name = name == "stack.yaml"

Expand Down