Skip to content

Commit e39c054

Browse files
committed
Use default config on missing configuration section
On serving initialize request, deserializing HIE configuration embedded in InitializeParam passed by client will result in an error if during 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 759901f commit e39c054

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,22 @@ instance A.FromJSON Config where
9797
parseJSON = A.withObject "Config" $ \v -> do
9898
-- Officially, we use "haskell" as the section name but for
9999
-- backwards compatibility we also accept "languageServerHaskell"
100-
s <- v .: "haskell" <|> v .: "languageServerHaskell"
101-
flip (A.withObject "Config.settings") s $ \o -> Config
102-
<$> (o .:? "checkParents" <|> v .:? "checkParents") .!= checkParents def
103-
<*> (o .:? "checkProject" <|> v .:? "checkProject") .!= checkProject def
104-
<*> o .:? "hlintOn" .!= hlintOn def
105-
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange def
106-
<*> o .:? "maxNumberOfProblems" .!= maxNumberOfProblems def
107-
<*> o .:? "diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
108-
<*> o .:? "liquidOn" .!= liquidOn def
109-
<*> o .:? "completionSnippetsOn" .!= completionSnippetsOn def
110-
<*> o .:? "formatOnImportOn" .!= formatOnImportOn def
111-
<*> o .:? "formattingProvider" .!= formattingProvider def
112-
<*> o .:? "maxCompletions" .!= maxCompletions def
113-
<*> o .:? "plugin" .!= plugins def
100+
c <- v .:? "haskell" <|> v .:? "languageServerHaskell"
101+
case c of
102+
Nothing -> return def
103+
Just s -> flip (A.withObject "Config.settings") s $ \o -> Config
104+
<$> (o .:? "checkParents" <|> v .:? "checkParents") .!= checkParents def
105+
<*> (o .:? "checkProject" <|> v .:? "checkProject") .!= checkProject def
106+
<*> o .:? "hlintOn" .!= hlintOn def
107+
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange def
108+
<*> o .:? "maxNumberOfProblems" .!= maxNumberOfProblems def
109+
<*> o .:? "diagnosticsDebounceDuration" .!= diagnosticsDebounceDuration def
110+
<*> o .:? "liquidOn" .!= liquidOn def
111+
<*> o .:? "completionSnippetsOn" .!= completionSnippetsOn def
112+
<*> o .:? "formatOnImportOn" .!= formatOnImportOn def
113+
<*> o .:? "formattingProvider" .!= formattingProvider def
114+
<*> o .:? "maxCompletions" .!= maxCompletions def
115+
<*> o .:? "plugin" .!= plugins def
114116

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

test/functional/Config.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Config (tests) where
44

55
import Control.Lens hiding (List)
6+
import Control.Applicative.Combinators (skipManyTill)
67
import Control.Monad.IO.Class
78
import Data.Aeson
89
import Data.Default
@@ -24,6 +25,7 @@ tests = testGroup "plugin config" [
2425
-- Note: because the flag is treated generically in the plugin handler, we
2526
-- do not have to test each individual plugin
2627
hlintTests
28+
, configTests
2729
]
2830

2931
hlintTests :: TestTree
@@ -71,6 +73,21 @@ hlintTests = testGroup "hlint plugin enables" [
7173
diags <- waitForDiagnosticsFromSource doc "hlint"
7274
liftIO $ length diags > 0 @? "There are hlint diagnostics"
7375

76+
configTests :: TestTree
77+
configTests = testGroup "config parsing" [
78+
testCase "empty object as user configuration should not send error logMessage" $ runConfigSession "" $ do
79+
let config = object []
80+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
81+
82+
logNot <- skipManyTill Test.anyMessage Test.message :: Session LogMessageNotification
83+
84+
liftIO $ (logNot ^. L.params . L.xtype) > MtError @? "Server sends logMessage with MessageType = Error"
85+
]
86+
where
87+
runConfigSession :: FilePath -> Session a -> IO a
88+
runConfigSession subdir =
89+
failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata" </> subdir)
90+
7491
pluginGlobalOn :: Config -> T.Text -> Bool -> Config
7592
pluginGlobalOn config pid state = config'
7693
where

0 commit comments

Comments
 (0)