Skip to content

Commit 7c40949

Browse files
authored
Merge branch 'master' into progressreport-redo
2 parents 85815ca + 0da4168 commit 7c40949

File tree

34 files changed

+197
-150
lines changed

34 files changed

+197
-150
lines changed

Diff for: exe/Wrapper.hs

+23-26
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import Data.Default
88
import Data.Foldable
99
import Data.List
1010
import Data.Void
11-
import Development.IDE.Session (findCradle)
12-
import HIE.Bios hiding (findCradle)
13-
import HIE.Bios.Environment
11+
import qualified Development.IDE.Session as Session
12+
import qualified HIE.Bios.Environment as HieBios
1413
import HIE.Bios.Types
1514
import Ide.Arguments
1615
import Ide.Version
@@ -44,6 +43,9 @@ main = do
4443
VersionMode PrintNumericVersion ->
4544
putStrLn haskellLanguageServerNumericVersion
4645

46+
BiosMode PrintCradleType ->
47+
print =<< findProjectCradle
48+
4749
_ -> launchHaskellLanguageServer args
4850

4951
launchHaskellLanguageServer :: Arguments -> IO ()
@@ -53,9 +55,11 @@ launchHaskellLanguageServer parsedArgs = do
5355
_ -> pure ()
5456

5557
d <- getCurrentDirectory
58+
59+
-- search for the project cradle type
60+
cradle <- findProjectCradle
5661

57-
-- Get the cabal directory from the cradle
58-
cradle <- findLocalCradle (d </> "a")
62+
-- Get the root directory from the cradle
5963
setCurrentDirectory $ cradleRootDir cradle
6064

6165
case parsedArgs of
@@ -114,7 +118,7 @@ getRuntimeGhcVersion' cradle = do
114118
Direct -> checkToolExists "ghc"
115119
_ -> pure ()
116120

117-
ghcVersionRes <- getRuntimeGhcVersion cradle
121+
ghcVersionRes <- HieBios.getRuntimeGhcVersion cradle
118122
case ghcVersionRes of
119123
CradleSuccess ver -> do
120124
return ver
@@ -129,23 +133,16 @@ getRuntimeGhcVersion' cradle = do
129133
die $ "Cradle requires " ++ exe ++ " but couldn't find it" ++ "\n"
130134
++ show cradle
131135

132-
-- | Find the cradle that the given File belongs to.
133-
--
134-
-- First looks for a "hie.yaml" file in the directory of the file
135-
-- or one of its parents. If this file is found, the cradle
136-
-- is read from the config. If this config does not comply to the "hie.yaml"
137-
-- specification, an error is raised.
138-
--
139-
-- If no "hie.yaml" can be found, the implicit config is used.
140-
-- The implicit config uses different heuristics to determine the type
141-
-- of the project that may or may not be accurate.
142-
findLocalCradle :: FilePath -> IO (Cradle Void)
143-
findLocalCradle fp = do
144-
cradleConf <- findCradle def fp
145-
crdl <- case cradleConf of
146-
Just yaml -> do
147-
hPutStrLn stderr $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""
148-
loadCradle yaml
149-
Nothing -> loadImplicitCradle fp
150-
hPutStrLn stderr $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl
151-
return crdl
136+
findProjectCradle :: IO (Cradle Void)
137+
findProjectCradle = do
138+
d <- getCurrentDirectory
139+
140+
let initialFp = (d </> "a")
141+
hieYaml <- Session.findCradle def initialFp
142+
143+
-- Some log messages
144+
case hieYaml of
145+
Just yaml -> hPutStrLn stderr $ "Found \"" ++ yaml ++ "\" for \"" ++ initialFp ++ "\""
146+
Nothing -> hPutStrLn stderr "No 'hie.yaml' found. Try to discover the project type!"
147+
148+
Session.loadCradle def hieYaml d

Diff for: ghcide/ghcide.cabal

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description:
1414
homepage: https://github.com/haskell/haskell-language-server/tree/master/ghcide#readme
1515
bug-reports: https://github.com/haskell/haskell-language-server/issues
1616
tested-with: GHC == 8.6.4 || == 8.6.5 || == 8.8.2 || == 8.8.3 || == 8.8.4 || == 8.10.2 || == 8.10.3 || == 8.10.4
17-
extra-source-files: include/ghc-api-version.h README.md CHANGELOG.md
17+
extra-source-files: README.md CHANGELOG.md
1818
test/data/**/*.project
1919
test/data/**/*.cabal
2020
test/data/**/*.yaml
@@ -334,9 +334,9 @@ test-suite ghcide-tests
334334
extra,
335335
filepath,
336336
--------------------------------------------------------------
337-
-- The MIN_GHC_API_VERSION macro relies on MIN_VERSION pragmas
337+
-- The MIN_VERSION_ghc macro relies on MIN_VERSION pragmas
338338
-- which require depending on ghc. So the tests need to depend
339-
-- on ghc if they need to use MIN_GHC_API_VERSION. Maybe a
339+
-- on ghc if they need to use MIN_VERSION_ghc. Maybe a
340340
-- better solution can be found, but this is a quick solution
341341
-- which works for now.
342342
ghc,

Diff for: ghcide/include/ghc-api-version.h

-12
This file was deleted.

Diff for: ghcide/session-loader/Development/IDE/Session.hs

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE TypeFamilies #-}
3-
#include "ghc-api-version.h"
43

54
{-|
65
The logic for setting up a ghcide session by tapping into hie-bios.
@@ -48,6 +47,7 @@ import Development.IDE.GHC.Compat hiding (Target,
4847
TargetFile, TargetModule)
4948
import qualified Development.IDE.GHC.Compat as GHC
5049
import Development.IDE.GHC.Util
50+
import Development.IDE.Graph (Action)
5151
import Development.IDE.Session.VersionCheck
5252
import Development.IDE.Types.Diagnostics
5353
import Development.IDE.Types.Exports
@@ -56,7 +56,6 @@ import Development.IDE.Types.HscEnvEq (HscEnvEq, newHscEnvEq,
5656
import Development.IDE.Types.Location
5757
import Development.IDE.Types.Logger
5858
import Development.IDE.Types.Options
59-
import Development.IDE.Graph (Action)
6059
import GHC.Check
6160
import qualified HIE.Bios as HieBios
6261
import HIE.Bios.Environment hiding (getCacheDir)
@@ -85,12 +84,10 @@ import Control.Concurrent.STM (atomically)
8584
import Control.Concurrent.STM.TQueue
8685
import qualified Data.HashSet as Set
8786
import Database.SQLite.Simple
88-
import HIE.Bios.Cradle (yamlConfig)
87+
import GHC.LanguageExtensions (Extension (EmptyCase))
8988
import HieDb.Create
9089
import HieDb.Types
9190
import HieDb.Utils
92-
import Maybes (MaybeT (runMaybeT))
93-
import GHC.LanguageExtensions (Extension(EmptyCase))
9491

9592
-- | Bump this version number when making changes to the format of the data stored in hiedb
9693
hiedbDataVersion :: String
@@ -100,15 +97,18 @@ data CacheDirs = CacheDirs
10097
{ hiCacheDir, hieCacheDir, oCacheDir :: Maybe FilePath}
10198

10299
data SessionLoadingOptions = SessionLoadingOptions
103-
{ findCradle :: FilePath -> IO (Maybe FilePath)
104-
, loadCradle :: FilePath -> IO (HieBios.Cradle Void)
100+
{ findCradle :: FilePath -> IO (Maybe FilePath)
101+
-- | Load the cradle with an optional 'hie.yaml' location.
102+
-- If a 'hie.yaml' is given, use it to load the cradle.
103+
-- Otherwise, use the provided project root directory to determine the cradle type.
104+
, loadCradle :: Maybe FilePath -> FilePath -> IO (HieBios.Cradle Void)
105105
-- | Given the project name and a set of command line flags,
106106
-- return the path for storing generated GHC artifacts,
107107
-- or 'Nothing' to respect the cradle setting
108-
, getCacheDirs :: String -> [String] -> IO CacheDirs
108+
, getCacheDirs :: String -> [String] -> IO CacheDirs
109109
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
110-
, getInitialGhcLibDir :: IO (Maybe LibDir)
111-
, fakeUid :: InstalledUnitId
110+
, getInitialGhcLibDir :: IO (Maybe LibDir)
111+
, fakeUid :: InstalledUnitId
112112
-- ^ unit id used to tag the internal component built by ghcide
113113
-- To reuse external interface files the unit ids must match,
114114
-- thus make sure to build them with `--this-unit-id` set to the
@@ -118,17 +118,39 @@ data SessionLoadingOptions = SessionLoadingOptions
118118
instance Default SessionLoadingOptions where
119119
def = SessionLoadingOptions
120120
{findCradle = HieBios.findCradle
121-
,loadCradle = HieBios.loadCradle
121+
,loadCradle = loadWithImplicitCradle
122122
,getCacheDirs = getCacheDirsDefault
123123
,getInitialGhcLibDir = getInitialGhcLibDirDefault
124124
,fakeUid = toInstalledUnitId (stringToUnitId "main")
125125
}
126126

127+
-- | Find the cradle for a given 'hie.yaml' configuration.
128+
--
129+
-- If a 'hie.yaml' is given, the cradle is read from the config.
130+
-- If this config does not comply to the "hie.yaml"
131+
-- specification, an error is raised.
132+
--
133+
-- If no location for "hie.yaml" is provided, the implicit config is used
134+
-- using the provided root directory for discovering the project.
135+
-- The implicit config uses different heuristics to determine the type
136+
-- of the project that may or may not be accurate.
137+
loadWithImplicitCradle :: Maybe FilePath
138+
-- ^ Optional 'hie.yaml' location. Will be used if given.
139+
-> FilePath
140+
-- ^ Root directory of the project. Required as a fallback
141+
-- if no 'hie.yaml' location is given.
142+
-> IO (HieBios.Cradle Void)
143+
loadWithImplicitCradle mHieYaml rootDir = do
144+
crdl <- case mHieYaml of
145+
Just yaml -> HieBios.loadCradle yaml
146+
Nothing -> loadImplicitHieCradle $ addTrailingPathSeparator rootDir
147+
return crdl
148+
127149
getInitialGhcLibDirDefault :: IO (Maybe LibDir)
128150
getInitialGhcLibDirDefault = do
129151
dir <- IO.getCurrentDirectory
130-
hieYaml <- runMaybeT $ yamlConfig dir
131-
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios.loadCradle hieYaml
152+
hieYaml <- findCradle def dir
153+
cradle <- loadCradle def hieYaml dir
132154
hPutStrLn stderr $ "setInitialDynFlags cradle: " ++ show cradle
133155
libDirRes <- getRuntimeGhcLibDir cradle
134156
case libDirRes of
@@ -400,7 +422,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
400422
when (isNothing hieYaml) $
401423
logWarning logger $ implicitCradleWarning lfp
402424

403-
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
425+
cradle <- loadCradle hieYaml dir
404426

405427
when optTesting $ mRunLspT lspEnv $
406428
sendNotification (SCustomMethod "ghcide/cradle/loaded") (toJSON cfp)

Diff for: ghcide/src/Development/IDE/Core/Compile.hs

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{-# LANGUAGE CPP #-}
55
{-# LANGUAGE GADTs #-}
66
{-# LANGUAGE RankNTypes #-}
7-
#include "ghc-api-version.h"
87

98
-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
109
-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
@@ -57,7 +56,7 @@ import LoadIface (loadModuleInterface)
5756

5857
import Lexer
5958
import qualified Parser
60-
#if MIN_GHC_API_VERSION(8,10,0)
59+
#if MIN_VERSION_ghc(8,10,0)
6160
import Control.DeepSeq (force, rnf)
6261
#else
6362
import Control.DeepSeq (rnf)
@@ -234,7 +233,7 @@ mkHiFileResultNoCompile session tcm = do
234233
tcGblEnv = tmrTypechecked tcm
235234
details <- makeSimpleDetails hsc_env_tmp tcGblEnv
236235
sf <- finalSafeMode (ms_hspp_opts ms) tcGblEnv
237-
#if MIN_GHC_API_VERSION(8,10,0)
236+
#if MIN_VERSION_ghc(8,10,0)
238237
iface <- mkIfaceTc hsc_env_tmp sf details tcGblEnv
239238
#else
240239
(iface, _) <- mkIfaceTc hsc_env_tmp Nothing sf details tcGblEnv
@@ -268,7 +267,7 @@ mkHiFileResultCompile session' tcm simplified_guts ltype = catchErrs $ do
268267
(guts, details) <- tidyProgram session simplified_guts
269268
(diags, linkable) <- genLinkable session ms guts
270269
pure (linkable, details, diags)
271-
#if MIN_GHC_API_VERSION(8,10,0)
270+
#if MIN_VERSION_ghc(8,10,0)
272271
let !partial_iface = force (mkPartialIface session details simplified_guts)
273272
final_iface <- mkFullIface session partial_iface
274273
#else
@@ -330,14 +329,14 @@ generateObjectCode session summary guts = do
330329
(warnings, dot_o_fp) <-
331330
withWarnings "object" $ \_tweak -> do
332331
let summary' = _tweak summary
333-
#if MIN_GHC_API_VERSION(8,10,0)
332+
#if MIN_VERSION_ghc(8,10,0)
334333
target = defaultObjectTarget $ hsc_dflags session
335334
#else
336335
target = defaultObjectTarget $ targetPlatform $ hsc_dflags session
337336
#endif
338337
session' = session { hsc_dflags = updOptLevel 0 $ (ms_hspp_opts summary') { outputFile = Just dot_o , hscTarget = target}}
339338
(outputFilename, _mStub, _foreign_files) <- hscGenHardCode session' guts
340-
#if MIN_GHC_API_VERSION(8,10,0)
339+
#if MIN_VERSION_ghc(8,10,0)
341340
(ms_location summary')
342341
#else
343342
summary'
@@ -360,7 +359,7 @@ generateByteCode hscEnv summary guts = do
360359
let summary' = _tweak summary
361360
session = hscEnv { hsc_dflags = ms_hspp_opts summary' }
362361
hscInteractive session guts
363-
#if MIN_GHC_API_VERSION(8,10,0)
362+
#if MIN_VERSION_ghc(8,10,0)
364363
(ms_location summary')
365364
#else
366365
summary'
@@ -419,7 +418,7 @@ unnecessaryDeprecationWarningFlags
419418
, Opt_WarnUnusedMatches
420419
, Opt_WarnUnusedTypePatterns
421420
, Opt_WarnUnusedForalls
422-
#if MIN_GHC_API_VERSION(8,10,0)
421+
#if MIN_VERSION_ghc(8,10,0)
423422
, Opt_WarnUnusedRecordWildcards
424423
#endif
425424
, Opt_WarnInaccessibleCode
@@ -738,7 +737,7 @@ getModSummaryFromImports env fp modTime contents = do
738737
msrModSummary =
739738
ModSummary
740739
{ ms_mod = modl
741-
#if MIN_GHC_API_VERSION(8,8,0)
740+
#if MIN_VERSION_ghc(8,8,0)
742741
, ms_hie_date = Nothing
743742
#endif
744743
, ms_hs_date = modTime
@@ -782,7 +781,7 @@ parseHeader
782781
parseHeader dflags filename contents = do
783782
let loc = mkRealSrcLoc (mkFastString filename) 1 1
784783
case unP Parser.parseHeader (mkPState dflags contents loc) of
785-
#if MIN_GHC_API_VERSION(8,10,0)
784+
#if MIN_VERSION_ghc(8,10,0)
786785
PFailed pst ->
787786
throwE $ diagFromErrMsgs "parser" dflags $ getErrorMessages pst dflags
788787
#else
@@ -820,7 +819,7 @@ parseFileContents env customPreprocessor filename ms = do
820819
dflags = ms_hspp_opts ms
821820
contents = fromJust $ ms_hspp_buf ms
822821
case unP Parser.parseModule (mkPState dflags contents loc) of
823-
#if MIN_GHC_API_VERSION(8,10,0)
822+
#if MIN_VERSION_ghc(8,10,0)
824823
PFailed pst -> throwE $ diagFromErrMsgs "parser" dflags $ getErrorMessages pst dflags
825824
#else
826825
PFailed _ locErr msgErr ->

Diff for: ghcide/src/Development/IDE/Core/Rules.hs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE DuplicateRecordFields #-}
66
{-# LANGUAGE FlexibleInstances #-}
77
{-# LANGUAGE TypeFamilies #-}
8-
#include "ghc-api-version.h"
98

109
-- | A Shake implementation of the compiler service, built
1110
-- using the "Shaker" abstraction layer for in-memory use.

Diff for: ghcide/src/Development/IDE/Core/Tracing.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE NoApplicativeDo #-}
22
{-# LANGUAGE CPP #-}
3-
#include "ghc-api-version.h"
43
module Development.IDE.Core.Tracing
54
( otTracedHandler
65
, otTracedAction
@@ -96,7 +95,7 @@ otTracedAction key file success act
9695
return res)
9796
| otherwise = act
9897

99-
#if MIN_GHC_API_VERSION(8,8,0)
98+
#if MIN_VERSION_ghc(8,8,0)
10099
otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
101100
#else
102101
otTracedProvider :: MonadUnliftIO m => PluginId -> String -> m a -> m a

0 commit comments

Comments
 (0)