Skip to content

Commit b29e37a

Browse files
committed
adding whole-project loading
1 parent 048cb16 commit b29e37a

13 files changed

Lines changed: 49 additions & 35 deletions

File tree

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages:
66
./hls-plugin-api
77
./hls-test-utils
88

9-
index-state: 2026-04-16T00:00:00Z
9+
index-state: 2026-07-03T13:55:55Z
1010

1111
tests: True
1212
test-show-details: direct

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ library
7474
, Glob
7575
, haddock-library >=1.8 && <1.12
7676
, hashable
77-
, hie-bios ^>= 0.19.0
77+
, hie-bios ^>= 0.20.0
7878
, hiedb ^>= 0.8.0.0
7979
, hls-graph == 2.14.0.0
8080
, hls-plugin-api == 2.14.0.0

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ cradleToOptsAndLibDir recorder loadConfig cradle file old_fps = do
10401040
-- noneCradleFoundMessage f = T.pack $ "none cradle found for " <> f <> ", ignoring the file"
10411041
-- Start off by getting the session options
10421042
logWith recorder Debug $ LogCradle cradle
1043-
cradleRes <- HieBios.getCompilerOptions file loadStyle cradle
1043+
cradleRes <- HieBios.getCompilerOptions (TargetWithContext file old_fps) loadStyle cradle
10441044
case cradleRes of
10451045
CradleSuccess r -> do
10461046
-- Now get the GHC lib dir
@@ -1061,8 +1061,9 @@ cradleToOptsAndLibDir recorder loadConfig cradle file old_fps = do
10611061

10621062
where
10631063
loadStyle = case loadConfig of
1064-
PreferSingleComponentLoading -> LoadFile
1065-
PreferMultiComponentLoading -> LoadWithContext old_fps
1064+
PreferSingleComponentLoading -> LoadFile
1065+
PreferMultiComponentLoading -> LoadFileWithContext
1066+
PreferMultiWholeProjectLoading -> LoadUnitsFromCradle
10661067

10671068
-- ----------------------------------------------------------------------------
10681069
-- Utilities

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ stackCradle fp = do
7878
pkgsWithComps <- liftIO $ catMaybes <$> mapM (nestedPkg fp) pkgs
7979
let yaml = fp </> "stack.yaml"
8080
pure $ (,fp) $ case pkgsWithComps of
81-
[] -> Stack (StackType Nothing (Just yaml))
81+
[] -> Stack (StackType Nothing (Just yaml) Nothing)
8282
ps -> StackMulti mempty $ do
8383
Package n cs <- ps
8484
c <- cs
8585
let (prefix, comp) = Implicit.stackComponent n c
86-
pure (prefix, StackType (Just comp) (Just yaml))
86+
pure (prefix, StackType (Just comp) (Just yaml) Nothing)
8787

8888
-- | By default, we generate a simple cabal cradle which is equivalent to the
8989
-- following hie.yaml:
@@ -95,7 +95,7 @@ stackCradle fp = do
9595
--
9696
-- Note, this only works reliable for reasonably modern cabal versions >= 3.2.
9797
simpleCabalCradle :: FilePath -> (CradleTree a, FilePath)
98-
simpleCabalCradle fp = (Cabal $ CabalType Nothing Nothing, fp)
98+
simpleCabalCradle fp = (Cabal $ CabalType Nothing Nothing Nothing, fp)
9999

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

hls-plugin-api/src/Ide/Plugin/Config.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ module Ide.Plugin.Config
1010
, CheckParents(..)
1111
) where
1212

13-
import Control.Lens (preview)
14-
import Data.Aeson hiding (Error)
15-
import qualified Data.Aeson as A
16-
import Data.Aeson.Lens (_String)
17-
import qualified Data.Aeson.Types as A
13+
import Control.Applicative
14+
import Control.Lens (preview)
15+
import Data.Aeson hiding (Error)
16+
import qualified Data.Aeson as A
17+
import Data.Aeson.Lens (_String)
18+
import qualified Data.Aeson.Types as A
1819
import Data.Default
19-
import qualified Data.Map.Strict as Map
20-
import Data.Maybe (fromMaybe)
21-
import qualified Data.Text as T
22-
import GHC.Exts (toList)
20+
import qualified Data.Map.Strict as Map
21+
import Data.Maybe (fromMaybe)
22+
import qualified Data.Text as T
23+
import GHC.Exts (toList)
2324
import Ide.Types
2425

2526
-- ---------------------------------------------------------------------
@@ -42,11 +43,15 @@ parseConfig idePlugins defValue = A.withObject "settings" $ \o ->
4243
<*> o .:? "formattingProvider" .!= formattingProvider defValue
4344
<*> o .:? "cabalFormattingProvider" .!= cabalFormattingProvider defValue
4445
<*> o .:? "maxCompletions" .!= maxCompletions defValue
45-
<*> o .:? "sessionLoading" .!= sessionLoading defValue
46+
<*> loadingPref o
4647
<*> o .:? "linkSourceTo" .!= linkSourceTo defValue
4748
<*> o .:? "linkDocTo" .!=
4849
linkDocTo defValue
4950
<*> A.explicitParseFieldMaybe (parsePlugins idePlugins) o "plugin" .!= plugins defValue
51+
where
52+
loadingPref o =
53+
(o .:? "componentsLoading"
54+
<|> o .:? "sessionLoading") .!= sessionLoading defValue
5055

5156
-- | Parse the 'PluginConfig'.
5257
-- Since we need to fall back to default values if we do not find one in the input,

hls-plugin-api/src/Ide/Types.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ instance ToJSON Config where
192192
, "formattingProvider" .= formattingProvider
193193
, "cabalFormattingProvider" .= cabalFormattingProvider
194194
, "maxCompletions" .= maxCompletions
195-
, "sessionLoading" .= sessionLoading
195+
, "componentsLoading" .= sessionLoading
196196
, "linkSourceTo" .= linkSourceTo
197197
, "linkDocTo" .= linkDocTo
198198
, "plugin" .= Map.mapKeysMonotonic (\(PluginId p) -> p) plugins
@@ -240,22 +240,30 @@ data SessionLoadingPreferenceConfig
240240
--
241241
-- The cradle can decide how to handle these situations, and whether
242242
-- to honour the preference at all.
243+
| PreferMultiWholeProjectLoading
244+
-- ^ Prefer loading all the components specified in the cradle, if possible.
243245
deriving stock (Eq, Ord, Show, Generic)
244246

245247
instance Pretty SessionLoadingPreferenceConfig where
246-
pretty PreferSingleComponentLoading = "Prefer Single Component Loading"
247-
pretty PreferMultiComponentLoading = "Prefer Multiple Components Loading"
248+
pretty PreferSingleComponentLoading = "Prefer Single Component Loading"
249+
pretty PreferMultiComponentLoading = "Prefer Multiple Components Loading"
250+
pretty PreferMultiWholeProjectLoading = "Prefer Whole Project Loading"
248251

249252
instance ToJSON SessionLoadingPreferenceConfig where
250253
toJSON PreferSingleComponentLoading =
251-
String "singleComponent"
254+
String "single"
252255
toJSON PreferMultiComponentLoading =
253-
String "multipleComponents"
256+
String "multi: needed-only"
257+
toJSON PreferMultiWholeProjectLoading =
258+
String "multi: whole-project"
254259

255260
instance FromJSON SessionLoadingPreferenceConfig where
256261
parseJSON (String val) = case val of
257262
"singleComponent" -> pure PreferSingleComponentLoading
263+
"single" -> pure PreferSingleComponentLoading
258264
"multipleComponents" -> pure PreferMultiComponentLoading
265+
"multi: needed-only" -> pure PreferMultiComponentLoading
266+
"multi: whole-project" -> pure PreferMultiWholeProjectLoading
259267
_ -> A.prependFailure "parsing SessionLoadingPreferenceConfig failed, "
260268
(A.parseFail $ "Expected one of \"singleComponent\" or \"multipleComponents\" but got " <> T.unpack val )
261269
parseJSON o = A.prependFailure "parsing SessionLoadingPreferenceConfig failed, "

stack-lts24.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extra-deps:
2121
- hiedb-0.8.0.0
2222
- hie-compat-0.3.1.2
2323
- implicit-hie-0.1.4.0
24-
- hie-bios-0.19.0
24+
- hie-bios-0.20.0
2525
- hw-fingertree-0.1.2.1
2626
- monad-dijkstra-0.1.1.5
2727
- unordered-containers-0.2.21

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extra-deps:
2222
- hiedb-0.8.0.0
2323
- hie-compat-0.3.1.2
2424
- implicit-hie-0.1.4.0
25-
- hie-bios-0.19.0
25+
- hie-bios-0.20.0
2626
- hw-fingertree-0.1.2.1
2727
- monad-dijkstra-0.1.1.5
2828
- unordered-containers-0.2.21

test/testdata/schema/ghc910/default-config.golden.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cabalFormattingProvider": "cabal-gild",
33
"checkParents": "CheckOnSave",
44
"checkProject": true,
5+
"componentsLoading": "multi: needed-only",
56
"formattingProvider": "ormolu",
67
"linkDocTo": "LinkToHackage",
78
"linkSourceTo": "LinkToHackage",
@@ -159,6 +160,5 @@
159160
"stan": {
160161
"globalOn": false
161162
}
162-
},
163-
"sessionLoading": "multipleComponents"
163+
}
164164
}

test/testdata/schema/ghc912/default-config.golden.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cabalFormattingProvider": "cabal-gild",
33
"checkParents": "CheckOnSave",
44
"checkProject": true,
5+
"componentsLoading": "multi: needed-only",
56
"formattingProvider": "ormolu",
67
"linkDocTo": "LinkToHackage",
78
"linkSourceTo": "LinkToHackage",
@@ -163,6 +164,5 @@
163164
"splice": {
164165
"globalOn": true
165166
}
166-
},
167-
"sessionLoading": "multipleComponents"
167+
}
168168
}

0 commit comments

Comments
 (0)