Skip to content

Commit b632ac2

Browse files
committed
Merge remote-tracking branch 'origin/master' into ghc-9.0.1-with-lsp-1.2
2 parents 7812a9b + 0da4168 commit b632ac2

File tree

34 files changed

+148
-101
lines changed

34 files changed

+148
-101
lines changed

exe/Wrapper.hs

Lines changed: 23 additions & 26 deletions
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

ghcide/ghcide.cabal

Lines changed: 3 additions & 3 deletions
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 || == 9.0.1
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,

ghcide/include/ghc-api-version.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 36 additions & 14 deletions
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)
@@ -84,12 +83,10 @@ import Control.Concurrent.STM (atomically)
8483
import Control.Concurrent.STM.TQueue
8584
import qualified Data.HashSet as Set
8685
import Database.SQLite.Simple
87-
import HIE.Bios.Cradle (yamlConfig)
86+
import GHC.LanguageExtensions (Extension (EmptyCase))
8887
import HieDb.Create
8988
import HieDb.Types
9089
import HieDb.Utils
91-
import Maybes (MaybeT (runMaybeT))
92-
import GHC.LanguageExtensions (Extension(EmptyCase))
9390

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

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

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

402-
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
424+
cradle <- loadCradle hieYaml dir
403425

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

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 0 additions & 1 deletion
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.

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 0 additions & 1 deletion
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.

ghcide/src/Development/IDE/Core/Tracing.hs

Lines changed: 1 addition & 2 deletions
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

ghcide/src/Development/IDE/GHC/CPP.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
{-# LANGUAGE NamedFieldPuns #-}
1313
{-# LANGUAGE NondecreasingIndentation #-}
1414
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
15-
#include "ghc-api-version.h"
1615

1716
-----------------------------------------------------------------------------
1817
--

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{-# LANGUAGE PatternSynonyms #-}
88
{-# OPTIONS -Wno-dodgy-imports -Wno-incomplete-uni-patterns #-}
99
{-# OPTIONS -Wno-missing-signatures #-} -- TODO: Remove!
10-
#include "ghc-api-version.h"
1110

1211
-- | Attempt at hiding the GHC version differences we can.
1312
module Development.IDE.GHC.Compat(

ghcide/src/Development/IDE/GHC/Orphans.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{-# LANGUAGE CPP #-}
55
{-# LANGUAGE FlexibleInstances #-}
66
{-# OPTIONS_GHC -Wno-orphans #-}
7-
#include "ghc-api-version.h"
87

98
-- | Orphan instances for GHC.
109
-- Note that the 'NFData' instances may not be law abiding.

ghcide/src/Development/IDE/Import/FindImports.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
-- SPDX-License-Identifier: Apache-2.0
33

44
{-# LANGUAGE CPP #-}
5-
#include "ghc-api-version.h"
65

76
module Development.IDE.Import.FindImports
87
( locateModule

ghcide/src/Development/IDE/LSP/Outline.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{-# LANGUAGE DuplicateRecordFields #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE RankNTypes #-}
6-
#include "ghc-api-version.h"
76

87
module Development.IDE.LSP.Outline
98
( moduleOutline

ghcide/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
{-# LANGUAGE CPP #-}
55
{-# LANGUAGE DuplicateRecordFields #-}
6-
#include "ghc-api-version.h"
76

87
-- | Go to the definition of a variable.
98

ghcide/src/Development/IDE/Plugin/Completions.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE RankNTypes #-}
33
{-# LANGUAGE TypeFamilies #-}
4-
#include "ghc-api-version.h"
54

65
module Development.IDE.Plugin.Completions
76
( descriptor

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE GADTs #-}
33
{-# LANGUAGE MultiWayIf #-}
44

5-
#include "ghc-api-version.h"
65

76
-- Mostly taken from "haskell-ide-engine"
87
module Development.IDE.Plugin.Completions.Logic (

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
{-# LANGUAGE CPP #-}
55
{-# LANGUAGE GADTs #-}
6-
#include "ghc-api-version.h"
76

87
-- | Gives information about symbols at a given point in DAML files.
98
-- These are all pure functions that should execute quickly.

ghcide/src/Development/IDE/Spans/Common.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DeriveAnyClass #-}
33
{-# LANGUAGE DerivingStrategies #-}
4-
#include "ghc-api-version.h"
54

65
module Development.IDE.Spans.Common (
76
showGhc

ghcide/src/Development/IDE/Spans/Documentation.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
-- SPDX-License-Identifier: Apache-2.0
44

55
{-# LANGUAGE CPP #-}
6-
#include "ghc-api-version.h"
76

87
module Development.IDE.Spans.Documentation (
98
getDocumentation

ghcide/test/exe/Main.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{-# LANGUAGE PolyKinds #-}
1212
{-# LANGUAGE TypeOperators #-}
1313
{-# OPTIONS_GHC -Wno-deprecations -Wno-unticked-promoted-constructors #-}
14-
#include "ghc-api-version.h"
1514

1615
module Main (main) where
1716

haskell-language-server.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tested-with: GHC == 8.6.4 || == 8.6.5 || == 8.8.2 || == 8.8.3 || == 8.8.4
1818
extra-source-files:
1919
README.md
2020
ChangeLog.md
21-
include/ghc-api-version.h
2221
test/testdata/**/*.project
2322
test/testdata/**/*.cabal
2423
test/testdata/**/*.yaml
@@ -475,7 +474,8 @@ test-suite func-test
475474
test-suite wrapper-test
476475
type: exitcode-stdio-1.0
477476
build-tool-depends:
478-
haskell-language-server:haskell-language-server-wrapper -any
477+
haskell-language-server:haskell-language-server-wrapper -any,
478+
haskell-language-server:haskell-language-server -any
479479

480480
default-language: Haskell2010
481481
build-depends:

0 commit comments

Comments
 (0)