Skip to content

Commit a125697

Browse files
committed
Use default config on missing configuration section
On serving initialize request, the deserialization of HIE configuration embedded in InitializeParam passed by client will result in an error if during the deserialization process the server cannot find HIE specific configuration key under initializationOptions. This commit changes the initializationOptions deserialization to return the default configuration if configuration key cannot be found under initializationOptions. Here, setting the key with a value of null will also be considered as part of not found condition to accommodate clients that fills missing user options as null.
1 parent 9f13e8f commit a125697

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ instance A.FromJSON Config where
7373
parseJSON = A.withObject "Config" $ \v -> do
7474
-- Officially, we use "haskell" as the section name but for
7575
-- 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
76+
c <- v .:? "haskell" <|> v .:? "languageServerHaskell"
77+
case c of
78+
Nothing -> return def
79+
Just s -> 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
8688

8789
-- 2017-10-09 23:22:00.710515298 [ThreadId 11] - ---> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"haskell":{"maxNumberOfProblems":100,"hlintOn":true}}}}
8890
-- 2017-10-09 23:22:00.710667381 [ThreadId 15] - reactor:got didChangeConfiguration notification:

0 commit comments

Comments
 (0)