Skip to content

Commit

Permalink
Merge pull request #76 from fwcd/fix-config-parsing
Browse files Browse the repository at this point in the history
Fix config parsing
  • Loading branch information
fwcd authored Dec 4, 2024
2 parents 28a798e + 51c1bb3 commit f741e02
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 36 deletions.
7 changes: 3 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import qualified Language.LSP.Server as S
import qualified Language.LSP.Protocol.Types as J
import qualified Curry.LanguageServer.Config as CFG
import Curry.LanguageServer.Handlers
import Curry.LanguageServer.Handlers.Config (onConfigChange)
import Curry.LanguageServer.Handlers.Initialize (initializeHandler)
import Curry.LanguageServer.Handlers.Workspace.Command (commands)
import Curry.LanguageServer.Monad (runLSM, newLSStateVar)
Expand All @@ -29,10 +30,8 @@ runLanguageServer = do
, S.parseConfig = \_old v -> case A.fromJSON v of
A.Error e -> Left $ T.pack e
A.Success cfg -> Right (cfg :: CFG.Config)
, S.configSection = "curry"
-- TODO: Handle configuration changes (ideally from here, not in the didChangeConfiguration handler)
-- See https://hackage.haskell.org/package/lsp-2.7.0.0/docs/Language-LSP-Server.html#t:ServerDefinition
, S.onConfigChange = const $ pure ()
, S.configSection = "curry.languageServer"
, S.onConfigChange = onConfigChange
, S.doInitialize = \env req -> runLSM (initializeHandler req) state env >> return (Right env)
, S.staticHandlers = handlers
, S.interpretHandler = \env -> S.Iso (\lsm -> runLSM lsm state env) liftIO
Expand Down
2 changes: 1 addition & 1 deletion curry-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ library
Curry.LanguageServer.FileLoader
Curry.LanguageServer.Handlers
Curry.LanguageServer.Handlers.Cancel
Curry.LanguageServer.Handlers.Config
Curry.LanguageServer.Handlers.Diagnostics
Curry.LanguageServer.Handlers.Initialize
Curry.LanguageServer.Handlers.TextDocument.CodeAction
Expand All @@ -45,7 +46,6 @@ library
Curry.LanguageServer.Handlers.TextDocument.Notifications
Curry.LanguageServer.Handlers.TextDocument.SignatureHelp
Curry.LanguageServer.Handlers.Workspace.Command
Curry.LanguageServer.Handlers.Workspace.Notifications
Curry.LanguageServer.Handlers.Workspace.Symbol
Curry.LanguageServer.Index.Convert
Curry.LanguageServer.Index.Resolve
Expand Down
21 changes: 7 additions & 14 deletions src/Curry/LanguageServer/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Data.Aeson
( FromJSON (..)
, ToJSON (..)
, (.!=)
, (.:)
, (.:?)
, withObject
, object
Expand Down Expand Up @@ -40,9 +39,7 @@ instance Default Config where
}

instance FromJSON Config where
parseJSON = withObject "Config" $ \o -> do
c <- o .: "curry"
l <- c .: "languageServer"
parseJSON = withObject "Config" $ \l -> do
forceRecompilation <- l .:? "forceRecompilation" .!= (def @Config).forceRecompilation
importPaths <- l .:? "importPaths" .!= (def @Config).importPaths
libraryPaths <- l .:? "libraryPaths" .!= (def @Config).libraryPaths
Expand All @@ -53,16 +50,12 @@ instance FromJSON Config where

instance ToJSON Config where
toJSON Config {..} = object
["curry" .= object
[ "languageServer" .= object
[ "forceRecompilation" .= forceRecompilation
, "importPaths" .= importPaths
, "libraryPaths" .= libraryPaths
, "logLevel" .= logLevel
, "curryPath" .= curryPath
, "useSnippetCompletions" .= useSnippetCompletions
]
]
[ "forceRecompilation" .= forceRecompilation
, "importPaths" .= importPaths
, "libraryPaths" .= libraryPaths
, "logLevel" .= logLevel
, "curryPath" .= curryPath
, "useSnippetCompletions" .= useSnippetCompletions
]

instance FromJSON LogLevel where
Expand Down
2 changes: 0 additions & 2 deletions src/Curry/LanguageServer/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Curry.LanguageServer.Handlers.TextDocument.Notifications (didOpenHandler,
import Curry.LanguageServer.Handlers.TextDocument.Hover (hoverHandler)
import Curry.LanguageServer.Handlers.TextDocument.SignatureHelp (signatureHelpHandler)
import Curry.LanguageServer.Handlers.Workspace.Command (executeCommandHandler)
import Curry.LanguageServer.Handlers.Workspace.Notifications (didChangeConfigurationHandler)
import Curry.LanguageServer.Handlers.Workspace.Symbol (workspaceSymbolHandler)
import Curry.LanguageServer.Monad (LSM)
import qualified Language.LSP.Protocol.Types as J
Expand All @@ -35,6 +34,5 @@ handlers _caps = mconcat
, didChangeHandler
, didSaveHandler
, didCloseHandler
, didChangeConfigurationHandler
, cancelHandler
]
12 changes: 12 additions & 0 deletions src/Curry/LanguageServer/Handlers/Config.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{-# LANGUAGE OverloadedStrings #-}
module Curry.LanguageServer.Handlers.Config
( onConfigChange
) where

import Curry.LanguageServer.Config (Config (..))
import Curry.LanguageServer.Monad (LSM)
import Curry.LanguageServer.Utils.Logging (infoM)

onConfigChange :: Config -> LSM ()
onConfigChange cfg = do

Check warning on line 11 in src/Curry/LanguageServer/Handlers/Config.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Defined but not used: ‘cfg’

Check warning on line 11 in src/Curry/LanguageServer/Handlers/Config.hs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Defined but not used: ‘cfg’

Check warning on line 11 in src/Curry/LanguageServer/Handlers/Config.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Defined but not used: `cfg'
infoM "Changed configuration"
15 changes: 0 additions & 15 deletions src/Curry/LanguageServer/Handlers/Workspace/Notifications.hs

This file was deleted.

0 comments on commit f741e02

Please sign in to comment.