Skip to content

Commit c20d322

Browse files
committed
Move ghcide LspConfig into Ide.Plugin.Config
1 parent 03b0536 commit c20d322

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
136136
} <- getShakeExtras
137137

138138
IdeOptions{ optTesting = IdeTesting optTesting
139-
, optCheckProject = CheckProject checkProject
139+
, optCheckProject = checkProject
140140
, optCustomDynFlags
141141
, optExtensions
142142
} <- getIdeOptions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Development.IDE.Core.RuleTypes
4040
import Development.IDE.Types.Options
4141
import qualified Data.Rope.UTF16 as Rope
4242
import Development.IDE.Import.DependencyInformation
43+
import Ide.Plugin.Config (CheckParents(..))
4344

4445
#ifdef mingw32_HOST_OS
4546
import qualified System.Directory as Dir

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import qualified Data.Text as Text
3333
import Development.IDE.Core.FileStore (setSomethingModified, setFileModified, typecheckParents)
3434
import Development.IDE.Core.FileExists (modifyFileExists, watchedGlobs)
3535
import Development.IDE.Core.OfInterest
36+
import Ide.Plugin.Config (CheckParents(CheckOnClose))
3637

3738

3839
whenUriFile :: Uri -> (NormalizedFilePath -> IO ()) -> IO ()

ghcide/src/Development/IDE/Types/Options.hs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ module Development.IDE.Types.Options
2121
, defaultIdeOptions
2222
, IdeResult
2323
, IdeGhcSession(..)
24-
, LspConfig(..)
25-
, defaultLspConfig
26-
, CheckProject(..)
27-
, CheckParents(..)
2824
, OptHaddockParse(..)
2925
) where
3026

27+
import Data.Default
3128
import Development.Shake
3229
import Development.IDE.GHC.Util
3330
import GHC hiding (parseModule, typecheckModule)
@@ -36,8 +33,7 @@ import qualified Language.Haskell.LSP.Types.Capabilities as LSP
3633
import qualified Data.Text as T
3734
import Development.IDE.Types.Diagnostics
3835
import Control.DeepSeq (NFData(..))
39-
import Data.Aeson
40-
import GHC.Generics
36+
import Ide.Plugin.Config
4137

4238
data IdeGhcSession = IdeGhcSession
4339
{ loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
@@ -89,7 +85,7 @@ data IdeOptions = IdeOptions
8985
-- features such as diagnostics and go-to-definition, in
9086
-- situations in which they would become unavailable because of
9187
-- the presence of type errors, holes or unbound variables.
92-
, optCheckProject :: CheckProject
88+
, optCheckProject :: !Bool
9389
-- ^ Whether to typecheck the entire project on load
9490
, optCheckParents :: CheckParents
9591
-- ^ When to typecheck reverse dependencies of a file
@@ -106,29 +102,6 @@ data IdeOptions = IdeOptions
106102
data OptHaddockParse = HaddockParse | NoHaddockParse
107103
deriving (Eq,Ord,Show,Enum)
108104

109-
newtype CheckProject = CheckProject { shouldCheckProject :: Bool }
110-
deriving stock (Eq, Ord, Show)
111-
deriving newtype (FromJSON,ToJSON)
112-
data CheckParents
113-
-- Note that ordering of constructors is meaningful and must be monotonically
114-
-- increasing in the scenarios where parents are checked
115-
= NeverCheck
116-
| CheckOnClose
117-
| CheckOnSaveAndClose
118-
| AlwaysCheck
119-
deriving stock (Eq, Ord, Show, Generic)
120-
deriving anyclass (FromJSON, ToJSON)
121-
122-
data LspConfig
123-
= LspConfig
124-
{ checkParents :: CheckParents
125-
, checkProject :: CheckProject
126-
} deriving stock (Eq, Ord, Show, Generic)
127-
deriving anyclass (FromJSON, ToJSON)
128-
129-
defaultLspConfig :: LspConfig
130-
defaultLspConfig = LspConfig CheckOnSaveAndClose (CheckProject True)
131-
132105
data IdePreprocessedSource = IdePreprocessedSource
133106
{ preprocWarnings :: [(GHC.SrcSpan, String)]
134107
-- ^ Warnings emitted by the preprocessor.
@@ -163,8 +136,8 @@ defaultIdeOptions session = IdeOptions
163136
,optKeywords = haskellKeywords
164137
,optDefer = IdeDefer True
165138
,optTesting = IdeTesting False
166-
,optCheckProject = checkProject defaultLspConfig
167-
,optCheckParents = checkParents defaultLspConfig
139+
,optCheckProject = checkProject def
140+
,optCheckParents = checkParents def
168141
,optHaddockParse = HaddockParse
169142
,optCustomDynFlags = id
170143
}

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

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DeriveAnyClass #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE DerivingStrategies #-}
15
{-# LANGUAGE FlexibleInstances #-}
26
{-# LANGUAGE OverloadedStrings #-}
37
{-# LANGUAGE TypeFamilies #-}
@@ -7,6 +11,7 @@ module Ide.Plugin.Config
711
, getConfigFromNotification
812
, Config(..)
913
, PluginConfig(..)
14+
, CheckParents(..)
1015
) where
1116

1217
import Control.Applicative
@@ -16,6 +21,7 @@ import Data.Default
1621
import qualified Data.Text as T
1722
import Language.Haskell.LSP.Types
1823
import qualified Data.Map as Map
24+
import GHC.Generics (Generic)
1925

2026
-- ---------------------------------------------------------------------
2127

@@ -37,13 +43,25 @@ getInitialConfig (RequestMessage _ _ _ InitializeParams{_initializationOptions =
3743
A.Error err -> Left $ T.pack err
3844

3945
-- ---------------------------------------------------------------------
46+
data CheckParents
47+
-- Note that ordering of constructors is meaningful and must be monotonically
48+
-- increasing in the scenarios where parents are checked
49+
= NeverCheck
50+
| CheckOnClose
51+
| CheckOnSaveAndClose
52+
| AlwaysCheck
53+
deriving stock (Eq, Ord, Show, Generic)
54+
deriving anyclass (FromJSON, ToJSON)
55+
4056

4157
-- | We (initially anyway) mirror the hie configuration, so that existing
4258
-- clients can simply switch executable and not have any nasty surprises. There
4359
-- will be surprises relating to config options being ignored, initially though.
4460
data Config =
4561
Config
46-
{ hlintOn :: !Bool
62+
{ checkParents :: CheckParents
63+
, checkProject :: !Bool
64+
, hlintOn :: !Bool
4765
, diagnosticsOnChange :: !Bool
4866
, maxNumberOfProblems :: !Int
4967
, diagnosticsDebounceDuration :: !Int
@@ -56,7 +74,9 @@ data Config =
5674

5775
instance Default Config where
5876
def = Config
59-
{ hlintOn = True
77+
{ checkParents = CheckOnSaveAndClose
78+
, checkProject = True
79+
, hlintOn = True
6080
, diagnosticsOnChange = True
6181
, maxNumberOfProblems = 100
6282
, diagnosticsDebounceDuration = 350000
@@ -77,15 +97,17 @@ instance A.FromJSON Config where
7797
-- backwards compatibility we also accept "languageServerHaskell"
7898
s <- v .: "haskell" <|> v .: "languageServerHaskell"
7999
flip (A.withObject "Config.settings") s $ \o -> Config
80-
<$> o .:? "hlintOn" .!= hlintOn def
81-
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange def
82-
<*> o .:? "maxNumberOfProblems" .!= maxNumberOfProblems def
83-
<*> o .:? "diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
84-
<*> o .:? "liquidOn" .!= liquidOn def
85-
<*> o .:? "completionSnippetsOn" .!= completionSnippetsOn def
86-
<*> o .:? "formatOnImportOn" .!= formatOnImportOn def
87-
<*> o .:? "formattingProvider" .!= formattingProvider def
88-
<*> o .:? "plugin" .!= plugins def
100+
<$> (o .:? "checkParents" <|> v .:? "checkParents") .!= checkParents def
101+
<*> (o .:? "checkProject" <|> v .:? "checkProject") .!= checkProject def
102+
<*> o .:? "hlintOn" .!= hlintOn def
103+
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange def
104+
<*> o .:? "maxNumberOfProblems" .!= maxNumberOfProblems def
105+
<*> o .:? "diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
106+
<*> o .:? "liquidOn" .!= liquidOn def
107+
<*> o .:? "completionSnippetsOn" .!= completionSnippetsOn def
108+
<*> o .:? "formatOnImportOn" .!= formatOnImportOn def
109+
<*> o .:? "formattingProvider" .!= formattingProvider def
110+
<*> o .:? "plugin" .!= plugins def
89111

90112
-- 2017-10-09 23:22:00.710515298 [ThreadId 11] - ---> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"haskell":{"maxNumberOfProblems":100,"hlintOn":true}}}}
91113
-- 2017-10-09 23:22:00.710667381 [ThreadId 15] - reactor:got didChangeConfiguration notification:
@@ -97,17 +119,20 @@ instance A.FromJSON Config where
97119
-- ,("maxNumberOfProblems",Number 100.0)]))])}}
98120

99121
instance A.ToJSON Config where
100-
toJSON (Config h diag m d l c f fp p) = object [ "haskell" .= r ]
122+
toJSON Config{..} =
123+
object [ "haskell" .= r ]
101124
where
102-
r = object [ "hlintOn" .= h
103-
, "diagnosticsOnChange" .= diag
104-
, "maxNumberOfProblems" .= m
105-
, "diagnosticsDebounceDuration" .= d
106-
, "liquidOn" .= l
107-
, "completionSnippetsOn" .= c
108-
, "formatOnImportOn" .= f
109-
, "formattingProvider" .= fp
110-
, "plugin" .= p
125+
r = object [ "checkParents" .= checkParents
126+
, "checkProject" .= checkProject
127+
, "hlintOn" .= hlintOn
128+
, "diagnosticsOnChange" .= diagnosticsOnChange
129+
, "maxNumberOfProblems" .= maxNumberOfProblems
130+
, "diagnosticsDebounceDuration" .= diagnosticsDebounceDuration
131+
, "liquidOn" .= liquidOn
132+
, "completionSnippetsOn" .= completionSnippetsOn
133+
, "formatOnImportOn" .= formatOnImportOn
134+
, "formattingProvider" .= formattingProvider
135+
, "plugin" .= plugins
111136
]
112137

113138
-- ---------------------------------------------------------------------

0 commit comments

Comments
 (0)