Skip to content

Commit 8c08f37

Browse files
committed
consistent naming
1 parent b2c7ead commit 8c08f37

5 files changed

Lines changed: 32 additions & 26 deletions

File tree

ghcide-test/exe/CradleTests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ runWithExtraFilesMultiComponent' :: SessionLoadingPreferenceConfig -> String ->
321321
runWithExtraFilesMultiComponent' sesLoading dirName action = do
322322
let vfs = mkIdeTestFs [copyDir dirName]
323323
lspConfig :: Config
324-
lspConfig = def { sessionLoading = sesLoading }
324+
lspConfig = def { componentsLoading = sesLoading }
325325
conf :: TestConfig ()
326326
conf = def
327327
{ testPluginDescriptor = dummyPlugin
@@ -367,7 +367,7 @@ assertTypeCheckFailure doc msg = do
367367
setWholeProjectLoading :: Session ()
368368
setWholeProjectLoading = do
369369
setIgnoringConfigurationRequests False
370-
setHlsConfig def{sessionLoading = PreferMultiWholeProjectLoading}
370+
setHlsConfig def{componentsLoading = PreferMultiWholeProjectLoading}
371371

372372
regressionBatchFailureIsolatesBrokenFile :: FilePath -> Session ()
373373
regressionBatchFailureIsolatesBrokenFile dir = do

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Ide.Logger (Pretty (pretty),
7171
vcat, viaShow, (<+>))
7272
import Ide.Types (Config,
7373
SessionLoadingPreferenceConfig (..),
74-
sessionLoading)
74+
componentsLoading)
7575
import Language.LSP.Protocol.Message
7676
import Language.LSP.Server
7777
import System.Directory
@@ -599,11 +599,11 @@ didSessionLoadingPreferenceConfigChange s = do
599599
mLoadingConfig <- liftIO $ readVar biosSessionLoadingVar
600600
case mLoadingConfig of
601601
Nothing -> do
602-
liftIO $ writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
602+
liftIO $ writeVar biosSessionLoadingVar (Just (componentsLoading clientConfig))
603603
pure False
604604
Just loadingConfig -> do
605-
liftIO $ writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
606-
pure (loadingConfig /= sessionLoading clientConfig)
605+
liftIO $ writeVar biosSessionLoadingVar (Just (componentsLoading clientConfig))
606+
pure (loadingConfig /= componentsLoading clientConfig)
607607

608608
newSessionState :: IO SessionState
609609
newSessionState = do
@@ -1018,7 +1018,7 @@ loadCradleWithNotifications recorder sessionState hieYaml cfp = do
10181018
let progMsg = "Setting up " <> T.pack (takeBaseName (cradleRootDir cradle))
10191019
<> " (for " <> T.pack lfpLog <> ")"
10201020

1021-
sessionPref <- asks (sessionLoading . sessionClientConfig)
1021+
sessionPref <- asks (componentsLoading . sessionClientConfig)
10221022
extraToLoads <- liftIO $ getExtraFilesToLoad sessionState cfp
10231023
-- Start loading the file!
10241024
eopts <- mRunLspTCallback lspEnv (\act -> withIndefiniteProgress progMsg Nothing NotCancellable (const act)) $

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ loadGhcSession recorder ghcSessionDepsConfig = do
734734
[ B.encode (hash (sessionVersion res))
735735
-- When the session version changes, reload all session
736736
-- hsc env sessions
737-
, B.encode (show (sessionLoading config))
737+
, B.encode (show (componentsLoading config))
738738
-- The loading config affects session loading.
739739
-- Invalidate all build nodes.
740740
-- Changing the session loading config will increment

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ parseConfig idePlugins defValue = A.withObject "settings" $ \o ->
5151
where
5252
loadingPref o =
5353
(o .:? "componentsLoading"
54-
<|> o .:? "sessionLoading") .!= sessionLoading defValue
54+
<|> o .:? "sessionLoading") .!= componentsLoading defValue
5555

5656
-- | Parse the 'PluginConfig'.
5757
-- 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: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ data Config =
180180
, formattingProvider :: !T.Text
181181
, cabalFormattingProvider :: !T.Text
182182
, maxCompletions :: !Int
183-
, sessionLoading :: !SessionLoadingPreferenceConfig
183+
, componentsLoading :: !SessionLoadingPreferenceConfig
184184
, linkSourceTo :: !OptLinkTo
185185
, linkDocTo :: !OptLinkTo
186186
, plugins :: !(Map.Map PluginId PluginConfig)
@@ -193,7 +193,7 @@ instance ToJSON Config where
193193
, "formattingProvider" .= formattingProvider
194194
, "cabalFormattingProvider" .= cabalFormattingProvider
195195
, "maxCompletions" .= maxCompletions
196-
, "componentsLoading" .= sessionLoading
196+
, "componentsLoading" .= componentsLoading
197197
, "linkSourceTo" .= linkSourceTo
198198
, "linkDocTo" .= linkDocTo
199199
, "plugin" .= Map.mapKeysMonotonic (\(PluginId p) -> p) plugins
@@ -209,7 +209,7 @@ instance Default Config where
209209
-- , cabalFormattingProvider = "cabal-fmt"
210210
-- this string value needs to kept in sync with the value provided in HlsPlugins
211211
, maxCompletions = 40
212-
, sessionLoading = PreferMultiComponentLoading
212+
, componentsLoading = PreferMultiComponentLoading
213213
, linkSourceTo = LinkToHackage
214214
, linkDocTo = LinkToHackage
215215
, plugins = mempty
@@ -250,30 +250,36 @@ instance Pretty SessionLoadingPreferenceConfig where
250250
pretty PreferMultiComponentLoading = "Prefer Multiple Components Loading"
251251
pretty PreferMultiWholeProjectLoading = "Prefer Whole Project Loading"
252252

253+
-- | Labels for @SessionLoadingPreferenceConfig@ json format.
254+
singleComponent, multipleComponents, single, multiNeededOnly, multiWholeProject :: T.Text
255+
singleComponent = "singleComponent"
256+
multipleComponents = "multipleComponents"
257+
single = "single"
258+
multiNeededOnly = "multi: needed-only"
259+
multiWholeProject = "multi: whole-project"
260+
253261
instance ToJSON SessionLoadingPreferenceConfig where
254262
toJSON PreferSingleComponentLoading =
255-
String "single"
263+
String single
256264
toJSON PreferMultiComponentLoading =
257-
String "multi: needed-only"
265+
String multiNeededOnly
258266
toJSON PreferMultiWholeProjectLoading =
259-
String "multi: whole-project"
267+
String multiWholeProject
260268

261269
instance FromJSON SessionLoadingPreferenceConfig where
262-
parseJSON (String val) = case val of
263-
"singleComponent" -> pure PreferSingleComponentLoading
264-
"single" -> pure PreferSingleComponentLoading
265-
"multipleComponents" -> pure PreferMultiComponentLoading
266-
"multi: needed-only" -> pure PreferMultiComponentLoading
267-
"multi: whole-project" -> pure PreferMultiWholeProjectLoading
268-
_ -> A.prependFailure "parsing SessionLoadingPreferenceConfig failed, "
270+
parseJSON (String val)
271+
| val `elem` [singleComponent, single] = pure PreferSingleComponentLoading
272+
| val `elem` [multipleComponents, multiNeededOnly] = pure PreferMultiComponentLoading
273+
| val == multiWholeProject = pure PreferMultiWholeProjectLoading
274+
| otherwise = A.prependFailure "parsing SessionLoadingPreferenceConfig failed, "
269275
(A.parseFail $ unwords ["Expected one of", expected, "but got", T.unpack val] )
270276
where
271277
expected = concat ["[", List.intercalate ", " fields, "]"]
272-
fields = map (show @String)
273-
["single", "multi: only-needed", "multi: whole-project"]
278+
fields = map show
279+
[single, multiNeededOnly, multiWholeProject]
274280
++
275-
[ show @String old_value ++ " (deprecated)"
276-
| old_value <- ["singleComponent","multiComponent"]
281+
[ show old_value ++ " (deprecated)"
282+
| old_value <- [singleComponent,multipleComponents]
277283
]
278284
parseJSON o = A.prependFailure "parsing SessionLoadingPreferenceConfig failed, "
279285
(A.typeMismatch "String" o)

0 commit comments

Comments
 (0)