on master help sign in
Working on Plugin support for haskell-language-server (#477)
8b328bbAlan Zimmerman
exe/Main.hs+5−1
@@ -35,6 +35,7 @@ import Development.IDE.Plugin.Completions as Completions
35import Development.IDE.Plugin.CodeAction as CodeAction
35import Development.IDE.Plugin.CodeAction as CodeAction
36import qualified Data.Text as T
36import qualified Data.Text as T
37import qualified Data.Text.IO as T
37import qualified Data.Text.IO as T
38+import qualified Language.Haskell.LSP.Core as LSP
38import Language.Haskell.LSP.Messages
39import Language.Haskell.LSP.Messages
39import Language.Haskell.LSP.Types (LspId(IdInt))
40import Language.Haskell.LSP.Types (LspId(IdInt))
40import Data.Version
41import Data.Version
@@ -84,12 +85,15 @@ main = do
84 let plugins = Completions.plugin <> CodeAction.plugin
85 let plugins = Completions.plugin <> CodeAction.plugin
85 onInitialConfiguration = const $ Right ()
86 onInitialConfiguration = const $ Right ()
86 onConfigurationChange = const $ Right ()
87 onConfigurationChange = const $ Right ()
88+ options = def { LSP.executeCommandCommands = Just ["typesignature.add"]
89+ , LSP.completionTriggerCharacters = Just "."
90+ }
87
91
88 if argLSP then do
92 if argLSP then do
89 t <- offsetTime
93 t <- offsetTime
90 hPutStrLn stderr "Starting LSP server..."
94 hPutStrLn stderr "Starting LSP server..."
91 hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
95 hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
92− runLanguageServer def (pluginHandler plugins) onInitialConfiguration onConfigurationChange $ \getLspId event vfs caps -> do
96+ runLanguageServer options (pluginHandler plugins) onInitialConfiguration onConfigurationChange $ \getLspId event vfs caps -> do
93 t <- t
97 t <- t
94 hPutStrLn stderr $ "Started LSP server in " ++ showDuration t
98 hPutStrLn stderr $ "Started LSP server in " ++ showDuration t
95 let options = (defaultIdeOptions $ loadSession dir)
99 let options = (defaultIdeOptions $ loadSession dir)
src/Development/IDE/LSP/LanguageServer.hs+5−7
@@ -149,10 +149,10 @@ runLanguageServer options userHandlers onInitialConfig onConfigChange getIdeStat
149 ResponseAndRequest x@RequestMessage{_id, _params} wrap wrapNewReq act ->
149 ResponseAndRequest x@RequestMessage{_id, _params} wrap wrapNewReq act ->
150 checkCancelled ide clearReqId waitForCancel lspFuncs wrap act x _id _params $
150 checkCancelled ide clearReqId waitForCancel lspFuncs wrap act x _id _params $
151 \(res, newReq) -> do
151 \(res, newReq) -> do
152− sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) (Just res) Nothing
152+ case res of
153− case newReq of
153+ Left e -> sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) Nothing (Just e)
154− Nothing -> return ()
154+ Right r -> sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) (Just r) Nothing
155− Just (rm, newReqParams) -> do
155+ whenJust newReq $ \(rm, newReqParams) -> do
156 reqId <- getNextReqId
156 reqId <- getNextReqId
157 sendFunc $ wrapNewReq $ RequestMessage "2.0" reqId rm newReqParams
157 sendFunc $ wrapNewReq $ RequestMessage "2.0" reqId rm newReqParams
158 InitialParams x@RequestMessage{_id, _params} act -> do
158 InitialParams x@RequestMessage{_id, _params} act -> do
@@ -222,15 +222,13 @@ data Message c
222 -- | Used for cases in which we need to send not only a response,
222 -- | Used for cases in which we need to send not only a response,
223 -- but also an additional request to the client.
223 -- but also an additional request to the client.
224 -- For example, 'executeCommand' may generate an 'applyWorkspaceEdit' request.
224 -- For example, 'executeCommand' may generate an 'applyWorkspaceEdit' request.
225− | forall m rm req resp newReqParams newReqBody . (Show m, Show rm, Show req) => ResponseAndRequest (RequestMessage m req resp) (ResponseMessage resp -> FromServerMessage) (RequestMessage rm newReqParams newReqBody -> FromServerMessage) (LSP.LspFuncs c -> IdeState -> req -> IO (resp, Maybe (rm, newReqParams)))
225+ | forall m rm req resp newReqParams newReqBody . (Show m, Show rm, Show req) => ResponseAndRequest (RequestMessage m req resp) (ResponseMessage resp -> FromServerMessage) (RequestMessage rm newReqParams newReqBody -> FromServerMessage) (LSP.LspFuncs c -> IdeState -> req -> IO (Either ResponseError resp, Maybe (rm, newReqParams)))
226 | forall m req . (Show m, Show req) => Notification (NotificationMessage m req) (LSP.LspFuncs c -> IdeState -> req -> IO ())
226 | forall m req . (Show m, Show req) => Notification (NotificationMessage m req) (LSP.LspFuncs c -> IdeState -> req -> IO ())
227 -- | Used for the InitializeRequest only, where the response is generated by the LSP core handler.
227 -- | Used for the InitializeRequest only, where the response is generated by the LSP core handler.
228 | InitialParams InitializeRequest (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
228 | InitialParams InitializeRequest (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
229
229
230modifyOptions :: LSP.Options -> LSP.Options
230modifyOptions :: LSP.Options -> LSP.Options
231modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS
231modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS
232− , LSP.executeCommandCommands = Just ["typesignature.add"]
233− , LSP.completionTriggerCharacters = Just "."
234 }
232 }
235 where
233 where
236 tweakTDS tds = tds{_openClose=Just True, _change=Just TdSyncIncremental, _save=Just $ SaveOptions Nothing}
234 tweakTDS tds = tds{_openClose=Just True, _change=Just TdSyncIncremental, _save=Just $ SaveOptions Nothing}
src/Development/IDE/LSP/Server.hs+1−1
@@ -29,7 +29,7 @@ data WithMessage c = WithMessage
29 (Show m, Show rm, Show req, Show newReqParams, Show newReqBody) =>
29 (Show m, Show rm, Show req, Show newReqParams, Show newReqBody) =>
30 (ResponseMessage resp -> LSP.FromServerMessage) -> -- how to wrap a response
30 (ResponseMessage resp -> LSP.FromServerMessage) -> -- how to wrap a response
31 (RequestMessage rm newReqParams newReqBody -> LSP.FromServerMessage) -> -- how to wrap the additional req
31 (RequestMessage rm newReqParams newReqBody -> LSP.FromServerMessage) -> -- how to wrap the additional req
32− (LSP.LspFuncs c -> IdeState -> req -> IO (resp, Maybe (rm, newReqParams))) -> -- actual work
32+ (LSP.LspFuncs c -> IdeState -> req -> IO (Either ResponseError resp, Maybe (rm, newReqParams))) -> -- actual work
33 Maybe (LSP.Handler (RequestMessage m req resp))
33 Maybe (LSP.Handler (RequestMessage m req resp))
34 , withInitialize :: (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
34 , withInitialize :: (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
35 -> Maybe (LSP.Handler InitializeRequest)
35 -> Maybe (LSP.Handler InitializeRequest)
src/Development/IDE/Plugin/CodeAction.hs+3−3
@@ -103,14 +103,14 @@ executeAddSignatureCommand
103 :: LSP.LspFuncs c
103 :: LSP.LspFuncs c
104 -> IdeState
104 -> IdeState
105 -> ExecuteCommandParams
105 -> ExecuteCommandParams
106− -> IO (Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
106+ -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
107executeAddSignatureCommand _lsp _ideState ExecuteCommandParams{..}
107executeAddSignatureCommand _lsp _ideState ExecuteCommandParams{..}
108 | _command == "typesignature.add"
108 | _command == "typesignature.add"
109 , Just (List [edit]) <- _arguments
109 , Just (List [edit]) <- _arguments
110 , Success wedit <- fromJSON edit
110 , Success wedit <- fromJSON edit
111− = return (Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams wedit))
111+ = return (Right Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams wedit))
112 | otherwise
112 | otherwise
113− = return (Null, Nothing)
113+ = return (Right Null, Nothing)
114
114
115suggestAction
115suggestAction
116 :: Maybe DynFlags
116 :: Maybe DynFlags