Skip to content

Commit c1c6aec

Browse files
committed
Update to use ghcide-0.1.0 from hackage
1 parent 54b0daa commit c1c6aec

File tree

11 files changed

+128
-95
lines changed

11 files changed

+128
-95
lines changed

.gitmodules

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
[submodule "ghcide"]
2-
path = ghcide
3-
url = https://github.com/digital-asset/ghcide.git
1+
# To remove a submodule you need to:
2+
#
3+
# Delete the relevant section from the .gitmodules file.
4+
# Stage the .gitmodules changes git add .gitmodules
5+
# Delete the relevant section from .git/config.
6+
# Run git rm --cached path_to_submodule (no trailing slash).
7+
# Run rm -rf .git/modules/path_to_submodule
8+
# Commit git commit -m "Removed submodule <name>"
9+
# Delete the now untracked submodule files
10+
# rm -rf path_to_submodule

cabal.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
packages:
22
./
3-
ghcide
3+
-- ghcide
44

55
tests: true
66

@@ -11,4 +11,4 @@ package ghcide
1111

1212
write-ghc-environment-files: never
1313

14-
index-state: 2020-02-03T21:39:42Z
14+
index-state: 2020-02-04T19:45:47Z

exe/Main.hs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,42 @@
88
module Main(main) where
99

1010
import Arguments
11-
import Data.Maybe
12-
import Data.List.Extra
13-
import System.FilePath
1411
import Control.Concurrent.Extra
1512
import Control.Exception
1613
import Control.Monad.Extra
1714
import Control.Monad.IO.Class
1815
import Data.Default
19-
import System.Time.Extra
16+
import Data.List.Extra
17+
import qualified Data.Map.Strict as Map
18+
import Data.Maybe
19+
import qualified Data.Set as Set
20+
import qualified Data.Text as T
21+
import qualified Data.Text.IO as T
2022
import Development.IDE.Core.FileStore
2123
import Development.IDE.Core.OfInterest
22-
import Development.IDE.Core.Service
24+
import Development.IDE.Core.RuleTypes
2325
import Development.IDE.Core.Rules
26+
import Development.IDE.Core.Service
2427
import Development.IDE.Core.Shake
25-
import Development.IDE.Core.RuleTypes
28+
import Development.IDE.GHC.Util
29+
import Development.IDE.LSP.LanguageServer
2630
import Development.IDE.LSP.Protocol
27-
import Development.IDE.Types.Location
31+
import Development.IDE.Plugin
2832
import Development.IDE.Types.Diagnostics
29-
import Development.IDE.Types.Options
33+
import Development.IDE.Types.Location
3034
import Development.IDE.Types.Logger
31-
import Development.IDE.GHC.Util
32-
import Development.IDE.Plugin
33-
import qualified Data.Text as T
34-
import qualified Data.Text.IO as T
35+
import Development.IDE.Types.Options
36+
import Development.Shake (Action, action)
37+
import GHC hiding (def)
38+
import HIE.Bios
3539
import Language.Haskell.LSP.Messages
3640
import Language.Haskell.LSP.Types (LspId(IdInt))
3741
import Linker
38-
import Development.IDE.LSP.LanguageServer
3942
import System.Directory.Extra as IO
40-
import System.IO
4143
import System.Exit
42-
import Development.Shake (Action, action)
43-
import qualified Data.Set as Set
44-
import qualified Data.Map.Strict as Map
45-
46-
import GHC hiding (def)
47-
48-
import HIE.Bios
44+
import System.FilePath
45+
import System.IO
46+
import System.Time.Extra
4947

5048
-- ---------------------------------------------------------------------
5149

@@ -108,7 +106,9 @@ main = do
108106
putStrLn "Report bugs at https://github.com/haskell/haskell-language-server/issues"
109107

110108
putStrLn $ "\nStep 1/6: Finding files to test in " ++ dir
111-
files <- nubOrd <$> expandFiles (argFiles ++ ["." | null argFiles])
109+
files <- expandFiles (argFiles ++ ["." | null argFiles])
110+
-- LSP works with absolute file paths, so try and behave similarly
111+
files <- nubOrd <$> mapM canonicalizePath files
112112
putStrLn $ "Found " ++ show (length files) ++ " files"
113113

114114
putStrLn "\nStep 2/6: Looking for hie.yaml files that control setup"
@@ -131,7 +131,11 @@ main = do
131131
let grab file = fromMaybe (head sessions) $ do
132132
cradle <- Map.lookup file filesToCradles
133133
Map.lookup cradle cradlesToSessions
134-
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) (defaultIdeOptions $ return $ return . grab) vfs
134+
135+
let options =
136+
(defaultIdeOptions $ return $ return . grab)
137+
{ optShakeProfiling = argsShakeProfiling }
138+
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) (logger Info) options vfs
135139

136140
putStrLn "\nStep 6/6: Type checking the files"
137141
setFilesOfInterest ide $ Set.fromList $ map toNormalizedFilePath files
@@ -172,7 +176,7 @@ showEvent lock (EventFileDiagnostics (toNormalizedFilePath -> file) diags) =
172176
showEvent lock e = withLock lock $ print e
173177

174178

175-
cradleToSession :: Cradle -> IO HscEnvEq
179+
cradleToSession :: Cradle a -> IO HscEnvEq
176180
cradleToSession cradle = do
177181
cradleRes <- getCompilerOptions "" cradle
178182
opts <- case cradleRes of

ghcide

Lines changed: 0 additions & 1 deletion
This file was deleted.

haskell-language-server.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ library
5151
, filepath
5252
, fuzzy
5353
, ghc
54-
, ghcide
54+
, ghcide >= 0.1
5555
, gitrev
5656
, haddock-library
5757
, hashable
@@ -125,7 +125,7 @@ executable haskell-language-server
125125
, ghcide
126126
, gitrev
127127
, haskell-lsp
128-
, hie-bios >= 0.3.2 && < 0.4
128+
, hie-bios >= 0.4
129129
, hslogger
130130
, haskell-language-server
131131
, optparse-applicative

src/Ide/Cradle.hs

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module Ide.Cradle where
77

88
import Control.Exception
99
import Control.Monad.IO.Class
10-
import Data.Char (toLower)
1110
import Data.Foldable (toList)
1211
import Data.Function ((&))
13-
import Data.List (isPrefixOf, isInfixOf, sortOn, find)
12+
import Data.List (isPrefixOf, sortOn, find)
1413
import Data.List.NonEmpty (NonEmpty)
1514
import qualified Data.List.NonEmpty as NonEmpty
1615
import qualified Data.Map as Map
@@ -25,14 +24,17 @@ import Distribution.Helper (Package, projectPackages, pUnits,
2524
Unit, unitInfo, uiComponents,
2625
ChEntrypoint(..), UnitInfo(..))
2726
import Distribution.Helper.Discover (findProjects, getDefaultDistDir)
28-
import HIE.Bios as BIOS
29-
import HIE.Bios.Types as BIOS
27+
import HIE.Bios as Bios
28+
import qualified HIE.Bios.Cradle as Bios
29+
import HIE.Bios.Types (CradleAction(..))
30+
import qualified HIE.Bios.Types as Bios
3031
import System.Directory (getCurrentDirectory, canonicalizePath, findExecutable)
3132
import System.Exit
3233
import System.FilePath
3334
import System.Log.Logger
3435
import System.Process (readCreateProcessWithExitCode, shell)
3536

37+
3638
-- ---------------------------------------------------------------------
3739

3840
-- | Find the cradle that the given File belongs to.
@@ -45,44 +47,49 @@ import System.Process (readCreateProcessWithExitCode, shell)
4547
-- If no "hie.yaml" can be found, the implicit config is used.
4648
-- The implicit config uses different heuristics to determine the type
4749
-- of the project that may or may not be accurate.
48-
findLocalCradle :: FilePath -> IO Cradle
50+
findLocalCradle :: FilePath -> IO (Cradle CabalHelper)
4951
findLocalCradle fp = do
50-
cradleConf <- BIOS.findCradle fp
51-
crdl <- case cradleConf of
52+
cradleConf <- Bios.findCradle fp
53+
crdl <- case cradleConf of
5254
Just yaml -> do
5355
debugm $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""
54-
BIOS.loadCradle yaml
55-
Nothing -> cabalHelperCradle fp
56+
crdl <- Bios.loadCradle yaml
57+
return $ fmap (const CabalNone) crdl
58+
Nothing -> cabalHelperCradle fp
5659
logm $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl
5760
return crdl
5861

5962
-- | Check if the given cradle is a stack cradle.
6063
-- This might be used to determine the GHC version to use on the project.
6164
-- If it is a stack-cradle, we have to use @"stack path --compiler-exe"@
6265
-- otherwise we may ask `ghc` directly what version it is.
63-
isStackCradle :: Cradle -> Bool
64-
isStackCradle = (`elem` ["stack", "Cabal-Helper-Stack", "Cabal-Helper-Stack-None"])
65-
. BIOS.actionName
66-
. BIOS.cradleOptsProg
66+
isStackCradle :: Cradle CabalHelper -> Bool
67+
isStackCradle crdl = Bios.isStackCradle crdl || cabalHelperStackCradle crdl
68+
where
69+
cabalHelperStackCradle =
70+
(`elem` [Bios.Other Stack, Bios.Other StackNone])
71+
. Bios.actionName
72+
. Bios.cradleOptsProg
73+
6774

6875
-- | Check if the given cradle is a cabal cradle.
6976
-- This might be used to determine the GHC version to use on the project.
7077
-- If it is a stack-cradle, we have to use @"stack path --compiler-exe"@
7178
-- otherwise we may ask @ghc@ directly what version it is.
72-
isCabalCradle :: Cradle -> Bool
73-
isCabalCradle =
74-
(`elem`
75-
[ "cabal"
76-
, "Cabal-Helper-Cabal-V1"
77-
, "Cabal-Helper-Cabal-V2"
78-
, "Cabal-Helper-Cabal-V1-Dir"
79-
, "Cabal-Helper-Cabal-V2-Dir"
80-
, "Cabal-Helper-Cabal-V2-None"
81-
, "Cabal-Helper-Cabal-None"
82-
]
83-
)
84-
. BIOS.actionName
85-
. BIOS.cradleOptsProg
79+
isCabalCradle :: Cradle CabalHelper -> Bool
80+
isCabalCradle crdl = Bios.isCabalCradle crdl || cabalHelperCabalCradle crdl
81+
where
82+
cabalHelperCabalCradle =
83+
(`elem` [Bios.Other CabalV2, Bios.Other CabalNone])
84+
. Bios.actionName
85+
. Bios.cradleOptsProg
86+
87+
data CabalHelper
88+
= Stack
89+
| StackNone
90+
| CabalV2
91+
| CabalNone
92+
deriving (Show, Eq, Ord)
8693

8794
-- | Execute @ghc@ that is based on the given cradle.
8895
-- Output must be a single line. If an error is raised, e.g. the command
@@ -91,7 +98,7 @@ isCabalCradle =
9198
--
9299
-- E.g. for a stack cradle, we use @stack ghc@ and for a cabal cradle
93100
-- we are taking the @ghc@ that is on the path.
94-
execProjectGhc :: Cradle -> [String] -> IO (Maybe String)
101+
execProjectGhc :: Cradle CabalHelper -> [String] -> IO (Maybe String)
95102
execProjectGhc crdl args = do
96103
isStackInstalled <- isJust <$> findExecutable "stack"
97104
-- isCabalInstalled <- isJust <$> findExecutable "cabal"
@@ -147,7 +154,7 @@ tryCommand cmd = do
147154

148155

149156
-- | Get the directory of the libdir based on the project ghc.
150-
getProjectGhcLibDir :: Cradle -> IO (Maybe FilePath)
157+
getProjectGhcLibDir :: Cradle CabalHelper -> IO (Maybe FilePath)
151158
getProjectGhcLibDir crdl =
152159
execProjectGhc crdl ["--print-libdir"] >>= \case
153160
Nothing -> do
@@ -444,7 +451,7 @@ the compiler options obtained from Cabal-Helper are relative to the package
444451
source directory, which is "\/Repo\/SubRepo".
445452
446453
-}
447-
cabalHelperCradle :: FilePath -> IO Cradle
454+
cabalHelperCradle :: FilePath -> IO (Cradle CabalHelper)
448455
cabalHelperCradle file = do
449456
projM <- findCabalHelperEntryPoint file
450457
case projM of
@@ -454,7 +461,7 @@ cabalHelperCradle file = do
454461
return
455462
Cradle { cradleRootDir = cwd
456463
, cradleOptsProg =
457-
CradleAction { actionName = "Direct"
464+
CradleAction { actionName = Bios.Direct
458465
, runCradle = \_ _ ->
459466
return
460467
$ CradleSuccess
@@ -470,7 +477,7 @@ cabalHelperCradle file = do
470477
let root = projectRootDir proj
471478
-- Create a suffix for the cradle name.
472479
-- Purpose is mainly for easier debugging.
473-
let actionNameSuffix = projectSuffix proj
480+
let actionNameSuffix = projectType proj
474481
debugm $ "Cabal-Helper dirs: " ++ show [root, file]
475482
let dist_dir = getDefaultDistDir proj
476483
env <- mkQueryEnv proj dist_dir
@@ -487,9 +494,7 @@ cabalHelperCradle file = do
487494
return
488495
Cradle { cradleRootDir = root
489496
, cradleOptsProg =
490-
CradleAction { actionName = "Cabal-Helper-"
491-
++ actionNameSuffix
492-
++ "-None"
497+
CradleAction { actionName = Bios.Other (projectNoneType proj)
493498
, runCradle = \_ _ -> return CradleNone
494499
}
495500
}
@@ -504,8 +509,7 @@ cabalHelperCradle file = do
504509
return
505510
Cradle { cradleRootDir = normalisedPackageLocation
506511
, cradleOptsProg =
507-
CradleAction { actionName =
508-
"Cabal-Helper-" ++ actionNameSuffix
512+
CradleAction { actionName = Bios.Other actionNameSuffix
509513
, runCradle = \_ fp -> cabalHelperAction
510514
(Ex proj)
511515
env
@@ -754,12 +758,19 @@ projectRootDir ProjLocV2File { plProjectDirV2 } = plProjectDirV2
754758
projectRootDir ProjLocV2Dir { plProjectDirV2 } = plProjectDirV2
755759
projectRootDir ProjLocStackYaml { plStackYaml } = takeDirectory plStackYaml
756760

757-
projectSuffix :: ProjLoc qt -> FilePath
758-
projectSuffix ProjLocV1CabalFile {} = "Cabal-V1"
759-
projectSuffix ProjLocV1Dir {} = "Cabal-V1-Dir"
760-
projectSuffix ProjLocV2File {} = "Cabal-V2"
761-
projectSuffix ProjLocV2Dir {} = "Cabal-V2-Dir"
762-
projectSuffix ProjLocStackYaml {} = "Stack"
761+
projectType :: ProjLoc qt -> CabalHelper
762+
projectType ProjLocV1CabalFile {} = CabalV2
763+
projectType ProjLocV1Dir {} = CabalV2
764+
projectType ProjLocV2File {} = CabalV2
765+
projectType ProjLocV2Dir {} = CabalV2
766+
projectType ProjLocStackYaml {} = Stack
767+
768+
projectNoneType :: ProjLoc qt -> CabalHelper
769+
projectNoneType ProjLocV1CabalFile {} = CabalNone
770+
projectNoneType ProjLocV1Dir {} = CabalNone
771+
projectNoneType ProjLocV2File {} = CabalNone
772+
projectNoneType ProjLocV2Dir {} = CabalNone
773+
projectNoneType ProjLocStackYaml {} = StackNone
763774

764775
-- ----------------------------------------------------------------------------
765776
--
@@ -870,18 +881,25 @@ relativeTo file sourceDirs =
870881

871882
-- | Returns a user facing display name for the cradle type,
872883
-- e.g. "Stack project" or "GHC session"
873-
cradleDisplay :: IsString a => BIOS.Cradle -> a
884+
cradleDisplay :: IsString a => Cradle CabalHelper -> a
874885
cradleDisplay cradle = fromString result
875-
where
876-
result
877-
| "stack" `isInfixOf` name = "Stack project"
878-
| "cabal-v1" `isInfixOf` name = "Cabal (V1) project"
879-
| "cabal" `isInfixOf` name = "Cabal project"
880-
| "direct" `isInfixOf` name = "GHC session"
881-
| "multi" `isInfixOf` name = "Multi Component project"
882-
| otherwise = "project"
883-
name = map toLower $ BIOS.actionName (BIOS.cradleOptsProg cradle)
884-
886+
where
887+
result
888+
| Bios.isStackCradle cradle
889+
|| name
890+
`elem` [Bios.Other Stack, Bios.Other StackNone]
891+
= "Stack project"
892+
| Bios.isCabalCradle cradle
893+
|| name
894+
`elem` [Bios.Other CabalV2, Bios.Other CabalNone]
895+
= "Cabal project"
896+
| Bios.isDirectCradle cradle
897+
= "GHC session"
898+
| Bios.isMultiCradle cradle
899+
= "Multi Component project"
900+
| otherwise
901+
= "project"
902+
name = Bios.actionName (Bios.cradleOptsProg cradle)
885903

886904
-- ---------------------------------------------------------------------
887905

src/Ide/Version.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Distribution.Text (display)
1212
import Options.Applicative.Simple (simpleVersion)
1313
import Ide.Cradle (execProjectGhc)
1414
import qualified HIE.Bios.Types as Bios
15+
import qualified Ide.Cradle as Bios
1516
import qualified Paths_haskell_language_server as Meta
1617
import System.Directory
1718
import System.Info
@@ -34,7 +35,7 @@ hieVersion =
3435
hieGhcDisplayVersion :: String
3536
hieGhcDisplayVersion = compilerName ++ "-" ++ VERSION_ghc
3637

37-
getProjectGhcVersion :: Bios.Cradle -> IO String
38+
getProjectGhcVersion :: Bios.Cradle Bios.CabalHelper -> IO String
3839
getProjectGhcVersion crdl =
3940
fmap
4041
(fromMaybe "No System GHC Found.")

0 commit comments

Comments
 (0)