lsp: Haskell library for the Microsoft Language Server Protocol

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

An implementation of the types, and basic message server to allow language implementors to support the Language Server Protocol for their specific language.

An example of this is for Haskell via the Haskell IDE Engine, at https://github.com/haskell/haskell-ide-engine


[Skip to Readme]

Properties

Versions 1.0.0.0, 1.0.0.1, 1.1.0.0, 1.1.0.0, 1.1.1.0, 1.2.0.0, 1.2.0.1, 1.4.0.0, 1.5.0.0, 1.6.0.0, 2.0.0.0, 2.1.0.0, 2.2.0.0, 2.3.0.0, 2.4.0.0, 2.5.0.0, 2.6.0.0, 2.7.0.0
Change log ChangeLog.md
Dependencies aeson (>=1.0.0.0), async, attoparsec, base (>=4.11 && <4.15), bytestring, containers, data-default, dependent-map, directory, filepath, hashable, hslogger, lens (>=4.15.2), lsp, lsp-types (>=1.1 && <1.2), mtl, network-uri, random, scientific, sorted-list (>=0.2.1 && <0.2.2), stm (>=2.5 && <2.6), text, time, transformers (>=0.5.6 && <0.6), unliftio, unliftio-core (>=0.2.0.0), unordered-containers, uuid (>=1.3) [details]
License MIT
Copyright Alan Zimmerman, 2016-2021
Author Alan Zimmerman
Maintainer alan.zimm@gmail.com
Category Development
Home page https://github.com/alanz/lsp
Source repo head: git clone https://github.com/alanz/lsp
Uploaded by luke_ at 2021-02-14T03:11:14Z

Modules

[Index] [Quick Jump]

Flags

Automatic Flags
NameDescriptionDefault
demo

Build the demo executables

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for lsp-1.1.0.0

[back to package description]

CI Hackage Hackage

lsp

Haskell library for the Microsoft Language Server Protocol. It currently implements all of the 3.15 specification.

It is split into two separate packages, lsp and lsp-types

Language servers built on lsp

Example language servers

There are two example language servers in the example/ folder. Simple.hs provides a minimal example:

{-# 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 Reactor.hs shows how a reactor design can be used to handle all requests on a separate thread, such in a way that we could then execute them on multiple threads without blocking server communication. They can be installed from source with

cabal install lsp-demo-simple-server lsp-demo-reactor-server
stack install :lsp-demo-simple-server :lsp-demo-reactor-server --flag haskell-lsp:demo

Other resources

See #haskell-ide-engine on IRC freenode