@@ -8,6 +8,13 @@ module Ide.Plugin.Config
8
8
getInitialConfig
9
9
, getConfigFromNotification
10
10
, Config (.. )
11
+ , hlintOn
12
+ , diagnosticsOnChange
13
+ , diagnosticsDebounceDuration
14
+ , liquidOn
15
+ , completionSnippetsOn
16
+ , formatOnImportOn
17
+ , formattingProvider
11
18
) where
12
19
13
20
import Control.Applicative
@@ -41,48 +48,63 @@ getInitialConfig (RequestMessage _ _ _ InitializeParams{_initializationOptions =
41
48
-- | We (initially anyway) mirror the hie configuration, so that existing
42
49
-- clients can simply switch executable and not have any nasty surprises. There
43
50
-- will be surprises relating to config options being ignored, initially though.
44
- data Config =
45
- Config
46
- { hlintOn :: Bool
47
- , diagnosticsOnChange :: Bool
48
- , maxNumberOfProblems :: Int
49
- , diagnosticsDebounceDuration :: Int
50
- , liquidOn :: Bool
51
- , completionSnippetsOn :: Bool
52
- , formatOnImportOn :: Bool
53
- , formattingProvider :: T. Text
54
- } deriving (Show ,Eq )
51
+ data Config
52
+ = DefaultConfig
53
+ | UserConfig Bool Bool Int Int Bool Bool Bool T. Text
54
+ deriving (Show , Eq )
55
55
56
56
instance Default Config where
57
- def = Config
58
- { hlintOn = True
59
- , diagnosticsOnChange = True
60
- , maxNumberOfProblems = 100
61
- , diagnosticsDebounceDuration = 350000
62
- , liquidOn = False
63
- , completionSnippetsOn = True
64
- , formatOnImportOn = True
65
- -- , formattingProvider = "brittany"
66
- , formattingProvider = " ormolu"
67
- -- , formattingProvider = "floskell"
68
- -- , formattingProvider = "stylish-haskell"
69
- }
57
+ def = DefaultConfig
58
+
59
+ hlintOn :: Config -> Bool
60
+ hlintOn DefaultConfig = True
61
+ hlintOn (UserConfig h _ _ _ _ _ _ _) = h
62
+
63
+ diagnosticsOnChange :: Config -> Bool
64
+ diagnosticsOnChange DefaultConfig = True
65
+ diagnosticsOnChange (UserConfig _ diag _ _ _ _ _ _) = diag
66
+
67
+ maxNumberOfProblems :: Config -> Int
68
+ maxNumberOfProblems DefaultConfig = 100
69
+ maxNumberOfProblems (UserConfig _ _ m _ _ _ _ _) = m
70
+
71
+ diagnosticsDebounceDuration :: Config -> Int
72
+ diagnosticsDebounceDuration DefaultConfig = 350000
73
+ diagnosticsDebounceDuration (UserConfig _ _ _ d _ _ _ _) = d
74
+
75
+ liquidOn :: Config -> Bool
76
+ liquidOn DefaultConfig = False
77
+ liquidOn (UserConfig _ _ _ _ l _ _ _) = l
78
+
79
+ completionSnippetsOn :: Config -> Bool
80
+ completionSnippetsOn DefaultConfig = True
81
+ completionSnippetsOn (UserConfig _ _ _ _ _ c _ _) = c
82
+
83
+ formatOnImportOn :: Config -> Bool
84
+ formatOnImportOn DefaultConfig = True
85
+ formatOnImportOn (UserConfig _ _ _ _ _ _ f _) = f
86
+
87
+ formattingProvider :: Config -> T. Text
88
+ formattingProvider DefaultConfig = " ormulu"
89
+ formattingProvider (UserConfig _ _ _ _ _ _ _ fp) = fp
70
90
71
91
-- TODO: Add API for plugins to expose their own LSP config options
72
92
instance A. FromJSON Config where
73
93
parseJSON = A. withObject " Config" $ \ v -> do
74
94
-- Officially, we use "haskell" as the section name but for
75
95
-- backwards compatibility we also accept "languageServerHaskell"
76
- s <- v .: " haskell" <|> v .: " languageServerHaskell"
77
- flip (A. withObject " Config.settings" ) s $ \ o -> Config
78
- <$> o .:? " hlintOn" .!= hlintOn def
79
- <*> o .:? " diagnosticsOnChange" .!= diagnosticsOnChange def
80
- <*> o .:? " maxNumberOfProblems" .!= maxNumberOfProblems def
81
- <*> o .:? " diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
82
- <*> o .:? " liquidOn" .!= liquidOn def
83
- <*> o .:? " completionSnippetsOn" .!= completionSnippetsOn def
84
- <*> o .:? " formatOnImportOn" .!= formatOnImportOn def
85
- <*> o .:? " formattingProvider" .!= formattingProvider def
96
+ c <- v .:? " haskell" <|> v .:? " languageServerHaskell"
97
+ case c of
98
+ Nothing -> return def
99
+ Just s -> flip (A. withObject " Config.settings" ) s $ \ o -> UserConfig
100
+ <$> o .:? " hlintOn" .!= hlintOn def
101
+ <*> o .:? " diagnosticsOnChange" .!= diagnosticsOnChange def
102
+ <*> o .:? " maxNumberOfProblems" .!= maxNumberOfProblems def
103
+ <*> o .:? " diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
104
+ <*> o .:? " liquidOn" .!= liquidOn def
105
+ <*> o .:? " completionSnippetsOn" .!= completionSnippetsOn def
106
+ <*> o .:? " formatOnImportOn" .!= formatOnImportOn def
107
+ <*> o .:? " formattingProvider" .!= formattingProvider def
86
108
87
109
-- 2017-10-09 23:22:00.710515298 [ThreadId 11] - ---> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"haskell":{"maxNumberOfProblems":100,"hlintOn":true}}}}
88
110
-- 2017-10-09 23:22:00.710667381 [ThreadId 15] - reactor:got didChangeConfiguration notification:
@@ -94,14 +116,16 @@ instance A.FromJSON Config where
94
116
-- ,("maxNumberOfProblems",Number 100.0)]))])}}
95
117
96
118
instance A. ToJSON Config where
97
- toJSON ( Config h diag m d l c f fp) = object [ " haskell" .= r ]
119
+ toJSON conf = object [ " haskell" .= r conf ]
98
120
where
99
- r = object [ " hlintOn" .= h
100
- , " diagnosticsOnChange" .= diag
101
- , " maxNumberOfProblems" .= m
102
- , " diagnosticsDebounceDuration" .= d
103
- , " liquidOn" .= l
104
- , " completionSnippetsOn" .= c
105
- , " formatOnImportOn" .= f
106
- , " formattingProvider" .= fp
107
- ]
121
+ r conf =
122
+ object
123
+ [ " hlintOn" .= hlintOn conf
124
+ , " diagnosticsOnChange" .= diagnosticsOnChange conf
125
+ , " maxNumberOfProblems" .= maxNumberOfProblems conf
126
+ , " diagnosticsDebounceDuration" .= diagnosticsDebounceDuration conf
127
+ , " liquidOn" .= liquidOn conf
128
+ , " completionSnippetsOn" .= completionSnippetsOn conf
129
+ , " formatOnImportOn" .= formatOnImportOn conf
130
+ , " formattingProvider" .= formattingProvider conf
131
+ ]
0 commit comments