Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove onInitialConfiguration from InitializeCallbacks #211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion haskell-lsp.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ test-suite haskell-lsp-test
VspSpec
WorkspaceEditSpec
WorkspaceFoldersSpec
InitialConfigurationSpec
build-depends: base
, QuickCheck
, aeson
Expand Down
50 changes: 19 additions & 31 deletions src/Language/Haskell/LSP/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,7 @@ data LspFuncs c =
-- specific configuration data the language server needs to use.
data InitializeCallbacks config =
InitializeCallbacks
{ onInitialConfiguration :: J.InitializeRequest -> Either T.Text config
-- ^ Invoked on the first message from the language client, containg the client configuration
-- This callback should return either the parsed configuration data or an error indicating
-- what went wrong. The parsed configuration object will be stored internally and passed to
-- hanlder functions as context.
, onConfigurationChange :: J.DidChangeConfigurationNotification-> Either T.Text config
{ onConfigurationChange :: J.DidChangeConfigurationNotification-> Either T.Text config
-- ^ Invoked whenever the clients sends a message with a changed client configuration.
-- This callback should return either the parsed configuration data or an error indicating
-- what went wrong. The parsed configuration object will be stored internally and passed to
Expand Down Expand Up @@ -434,13 +429,21 @@ handleInitialConfig
-> TVar (LanguageContextData config)
-> J.Value
-> IO ()
handleInitialConfig (InitializeCallbacks { onInitialConfiguration, onStartup }) mh tvarDat json
= handleMessageWithConfigChange ReqInitialize
onInitialConfiguration
(Just $ initializeRequestHandler' onStartup mh tvarDat)
tvarDat
json
handleInitialConfig (InitializeCallbacks { onStartup }) mh tvarDat json
= case J.fromJSON json of
J.Success req -> do
ctx <- readTVarIO tvarDat
captureFromClient (ReqInitialize req) (resCaptureFile ctx)

initializeRequestHandler' onStartup mh tvarDat req

J.Error err -> do
let msg =
T.pack
$ unwords
$ ["haskell-lsp:parse error.", show json, show err]
++ _ERR_MSG_URL
sendErrorLog tvarDat msg

hc
:: (Show config)
Expand All @@ -450,29 +453,13 @@ hc
-> J.Value
-> IO ()
hc (InitializeCallbacks { onConfigurationChange }) mh tvarDat json =
handleMessageWithConfigChange NotDidChangeConfiguration
onConfigurationChange
mh
tvarDat
json

handleMessageWithConfigChange
:: (J.FromJSON reqParams, Show reqParams, Show err)
=> (reqParams -> FromClientMessage) -- ^ The notification message from the client to expect
-> (reqParams -> Either err config) -- ^ A function to parse the config out of the request
-> Maybe (reqParams -> IO ()) -- ^ The upstream handler for the client request
-> TVar (LanguageContextData config) -- ^ The context data containing the current configuration
-> J.Value -- ^ The raw reqeust data
-> IO ()
handleMessageWithConfigChange notification parseConfig mh tvarDat json =
-- logs $ "haskell-lsp:hc DidChangeConfigurationNotification entered"
case J.fromJSON json of
J.Success req -> do
ctx <- readTVarIO tvarDat

captureFromClient (notification req) (resCaptureFile ctx)
captureFromClient (NotDidChangeConfiguration req) (resCaptureFile ctx)

case parseConfig req of
case onConfigurationChange req of
Left err -> do
let
msg =
Expand All @@ -493,7 +480,8 @@ handleMessageWithConfigChange notification parseConfig mh tvarDat json =
sendErrorLog tvarDat msg

-- | Updates the list of workspace folders and then delegates back to 'hh'
hwf :: Maybe (Handler J.DidChangeWorkspaceFoldersNotification) -> TVar (LanguageContextData config) -> J.Value -> IO ()
hwf :: Maybe (Handler J.DidChangeWorkspaceFoldersNotification)
-> TVar (LanguageContextData config) -> J.Value -> IO ()
hwf h tvarDat json = do
case J.fromJSON json :: J.Result J.DidChangeWorkspaceFoldersNotification of
J.Success (J.NotificationMessage _ _ params) -> atomically $ do
Expand Down
65 changes: 0 additions & 65 deletions test/InitialConfigurationSpec.hs

This file was deleted.

1 change: 0 additions & 1 deletion test/WorkspaceFoldersSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ spec =

let initCb :: InitializeCallbacks ()
initCb = InitializeCallbacks
(const $ Left "")
(const $ Left "")
(\lf -> putMVar lfVar lf >> return Nothing)
handlers = def
Expand Down