1
+ {-# LANGUAGE RecordWildCards #-}
2
+ {-# LANGUAGE DeriveAnyClass #-}
3
+ {-# LANGUAGE DeriveGeneric #-}
4
+ {-# LANGUAGE DerivingStrategies #-}
1
5
{-# LANGUAGE FlexibleInstances #-}
2
6
{-# LANGUAGE OverloadedStrings #-}
3
7
{-# LANGUAGE TypeFamilies #-}
@@ -7,6 +11,7 @@ module Ide.Plugin.Config
7
11
, getConfigFromNotification
8
12
, Config (.. )
9
13
, PluginConfig (.. )
14
+ , CheckParents (.. )
10
15
) where
11
16
12
17
import Control.Applicative
@@ -16,6 +21,7 @@ import Data.Default
16
21
import qualified Data.Text as T
17
22
import Language.Haskell.LSP.Types
18
23
import qualified Data.Map as Map
24
+ import GHC.Generics (Generic )
19
25
20
26
-- ---------------------------------------------------------------------
21
27
@@ -37,13 +43,25 @@ getInitialConfig (RequestMessage _ _ _ InitializeParams{_initializationOptions =
37
43
A. Error err -> Left $ T. pack err
38
44
39
45
-- ---------------------------------------------------------------------
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
+
40
56
41
57
-- | We (initially anyway) mirror the hie configuration, so that existing
42
58
-- clients can simply switch executable and not have any nasty surprises. There
43
59
-- will be surprises relating to config options being ignored, initially though.
44
60
data Config =
45
61
Config
46
- { hlintOn :: ! Bool
62
+ { checkParents :: CheckParents
63
+ , checkProject :: ! Bool
64
+ , hlintOn :: ! Bool
47
65
, diagnosticsOnChange :: ! Bool
48
66
, maxNumberOfProblems :: ! Int
49
67
, diagnosticsDebounceDuration :: ! Int
@@ -56,7 +74,9 @@ data Config =
56
74
57
75
instance Default Config where
58
76
def = Config
59
- { hlintOn = True
77
+ { checkParents = CheckOnSaveAndClose
78
+ , checkProject = True
79
+ , hlintOn = True
60
80
, diagnosticsOnChange = True
61
81
, maxNumberOfProblems = 100
62
82
, diagnosticsDebounceDuration = 350000
@@ -77,15 +97,17 @@ instance A.FromJSON Config where
77
97
-- backwards compatibility we also accept "languageServerHaskell"
78
98
s <- v .: " haskell" <|> v .: " languageServerHaskell"
79
99
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
89
111
90
112
-- 2017-10-09 23:22:00.710515298 [ThreadId 11] - ---> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"haskell":{"maxNumberOfProblems":100,"hlintOn":true}}}}
91
113
-- 2017-10-09 23:22:00.710667381 [ThreadId 15] - reactor:got didChangeConfiguration notification:
@@ -97,17 +119,20 @@ instance A.FromJSON Config where
97
119
-- ,("maxNumberOfProblems",Number 100.0)]))])}}
98
120
99
121
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 ]
101
124
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
111
136
]
112
137
113
138
-- ---------------------------------------------------------------------
0 commit comments