on master help sign in
Working on Plugin support for haskell-language-server (#477)

* Working on Plugin support for hls Fix PluginCommand reply type for executeCommand needs * Remove PluginCommand It will move to haskell-language-server instead * Make azure CI hlint happy By removing explicit OverloadedStrings pragma, in favour of the one already enabled in the cabal file. * Remove unneeded 'do' * Fix more nits from review

commit8b328bb7c5f3e09280788b56abd6fb6d0bfb08ce authorAlan Zimmerman <alan.zimm@gmail.com> dateMon 16 Mar 2020, 10:31 (7 years ago) parent111b685
4 files changed+14−12
exe/Main.hs+5−1 src/Development/IDE/LSP/LanguageServer.hs+5−7 src/Development/IDE/LSP/Server.hs+1−1 src/Development/IDE/Plugin/CodeAction.hs+3−3
exe/Main.hs+5−1
@@ -35,6 +35,7 @@ import Development.IDE.Plugin.Completions as Completions
3535import Development.IDE.Plugin.CodeAction as CodeAction
3636import qualified Data.Text as T
3737import qualified Data.Text.IO as T
38+import qualified Language.Haskell.LSP.Core as LSP
3839import Language.Haskell.LSP.Messages
3940import Language.Haskell.LSP.Types (LspId(IdInt))
4041import Data.Version
@@ -84,12 +85,15 @@ main = do
8485 let plugins = Completions.plugin <> CodeAction.plugin
8586 onInitialConfiguration = const $ Right ()
8687 onConfigurationChange = const $ Right ()
88+ options = def { LSP.executeCommandCommands = Just ["typesignature.add"]
89+ , LSP.completionTriggerCharacters = Just "."
90+ }
8791
8892 if argLSP then do
8993 t <- offsetTime
9094 hPutStrLn stderr "Starting LSP server..."
9195 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
9397 t <- t
9498 hPutStrLn stderr $ "Started LSP server in " ++ showDuration t
9599 let options = (defaultIdeOptions $ loadSession dir)
src/Development/IDE/LSP/LanguageServer.hs+5−7
@@ -149,10 +149,10 @@ runLanguageServer options userHandlers onInitialConfig onConfigChange getIdeStat
149149 ResponseAndRequest x@RequestMessage{_id, _params} wrap wrapNewReq act ->
150150 checkCancelled ide clearReqId waitForCancel lspFuncs wrap act x _id _params $
151151 \(res, newReq) -> do
152− sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) (Just res) Nothing
153− case newReq of
154− Nothing -> return ()
155− Just (rm, newReqParams) -> do
152+ case res of
153+ Left e -> sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) Nothing (Just e)
154+ Right r -> sendFunc $ wrap $ ResponseMessage "2.0" (responseId _id) (Just r) Nothing
155+ whenJust newReq $ \(rm, newReqParams) -> do
156156 reqId <- getNextReqId
157157 sendFunc $ wrapNewReq $ RequestMessage "2.0" reqId rm newReqParams
158158 InitialParams x@RequestMessage{_id, _params} act -> do
@@ -222,15 +222,13 @@ data Message c
222222 -- | Used for cases in which we need to send not only a response,
223223 -- but also an additional request to the client.
224224 -- 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)))
226226 | forall m req . (Show m, Show req) => Notification (NotificationMessage m req) (LSP.LspFuncs c -> IdeState -> req -> IO ())
227227 -- | Used for the InitializeRequest only, where the response is generated by the LSP core handler.
228228 | InitialParams InitializeRequest (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
229229
230230modifyOptions :: LSP.Options -> LSP.Options
231231modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS
232− , LSP.executeCommandCommands = Just ["typesignature.add"]
233− , LSP.completionTriggerCharacters = Just "."
234232 }
235233 where
236234 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
2929 (Show m, Show rm, Show req, Show newReqParams, Show newReqBody) =>
3030 (ResponseMessage resp -> LSP.FromServerMessage) -> -- how to wrap a response
3131 (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
3333 Maybe (LSP.Handler (RequestMessage m req resp))
3434 , withInitialize :: (LSP.LspFuncs c -> IdeState -> InitializeParams -> IO ())
3535 -> Maybe (LSP.Handler InitializeRequest)
src/Development/IDE/Plugin/CodeAction.hs+3−3
@@ -103,14 +103,14 @@ executeAddSignatureCommand
103103 :: LSP.LspFuncs c
104104 -> IdeState
105105 -> ExecuteCommandParams
106− -> IO (Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
106+ -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
107107executeAddSignatureCommand _lsp _ideState ExecuteCommandParams{..}
108108 | _command == "typesignature.add"
109109 , Just (List [edit]) <- _arguments
110110 , Success wedit <- fromJSON edit
111− = return (Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams wedit))
111+ = return (Right Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams wedit))
112112 | otherwise
113− = return (Null, Nothing)
113+ = return (Right Null, Nothing)
114114
115115suggestAction
116116 :: Maybe DynFlags