在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):haskell/lsp开源软件地址(OpenSource Url):https://github.com/haskell/lsp开源编程语言(OpenSource Language):Haskell 98.7%开源软件介绍(OpenSource Introduction):lspHaskell library for the Microsoft Language Server Protocol. It currently implements all of the 3.15 specification. It is split into three separate packages,
Language servers built on lspExample language serversThere are two example language servers in the {-# LANGUAGE OverloadedStrings #-}
import Language.LSP.Server
import Language.LSP.Types
import Control.Monad.IO.Class
import qualified Data.Text as T
handlers :: Handlers (LspM ())
handlers = mconcat
[ notificationHandler SInitialized $ \_not -> do
let params = ShowMessageRequestParams MtInfo "Turn on code lenses?"
(Just [MessageActionItem "Turn on", MessageActionItem "Don't"])
_ <- sendRequest SWindowShowMessageRequest params $ \res ->
case res of
Right (Just (MessageActionItem "Turn on")) -> do
let regOpts = CodeLensRegistrationOptions Nothing Nothing (Just False)
_ <- registerCapability STextDocumentCodeLens regOpts $ \_req responder -> do
let cmd = Command "Say hello" "lsp-hello-command" Nothing
rsp = List [CodeLens (mkRange 0 0 0 100) (Just cmd) Nothing]
responder (Right rsp)
pure ()
Right _ ->
sendNotification SWindowShowMessage (ShowMessageParams MtInfo "Not turning on code lenses")
Left err ->
sendNotification SWindowShowMessage (ShowMessageParams MtError $ "Something went wrong!\n" <> T.pack (show err))
pure ()
, requestHandler STextDocumentHover $ \req responder -> do
let RequestMessage _ _ _ (HoverParams _doc pos _workDone) = req
Position _l _c' = pos
rsp = Hover ms (Just range)
ms = HoverContents $ markedUpContent "lsp-demo-simple-server" "Hello world"
range = Range pos pos
responder (Right $ Just rsp)
]
main :: IO Int
main = runServer $ ServerDefinition
{ onConfigurationChange = const $ pure $ Right ()
, doInitialize = \env _req -> pure $ Right env
, staticHandlers = handlers
, interpretHandler = \env -> Iso (runLspT env) liftIO
, options = defaultOptions
} Whilst
Examples of using lsp-testSetting up a sessionimport Language.LSP.Test
main = runSession "hie" fullCaps "proj/dir" $ do
doc <- openDoc "Foo.hs" "haskell"
skipMany anyNotification
symbols <- getDocumentSymbols doc Unit tests with HSpecdescribe "diagnostics" $
it "report errors" $ runSession "hie" fullCaps "test/data" $ do
openDoc "Error.hs" "haskell"
[diag] <- waitForDiagnosticsSource "ghcmod"
liftIO $ do
diag ^. severity `shouldBe` Just DsError
diag ^. source `shouldBe` Just "ghcmod" Replaying captured sessionreplaySession "hie" "test/data/renamePass" Parsing with combinatorsskipManyTill loggingNotification publishDiagnosticsNotification
count 4 (message :: Session ApplyWorkspaceEditRequest)
anyRequest <|> anyResponse Try out the example tests in the Whilst writing your tests you may want to debug them to see what's going wrong.
You can set the
TroubleshootingSeeing funny stuff when running lsp-test via stack? If your server is built upon Haskell tooling, keep in mind that stack sets some environment variables related to GHC, and you may want to unset them. Useful linksOther resourcesSee #haskell-language-server on IRC freenode. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论