Skip to content
Merged
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
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
/tags
/cabal.project.local
/cabal.project.local~
cabal.sandbox.config
.stack-work
stack*.yaml.lock
/.dir-locals.el
/.vscode
/.ghc.environment*
/lsp-types/cabal.project.local
/lsp-types/cabal.project.local~
*.swp
*.swo
*.orig
*.DS_Store
.hspec-failures
/lsp-types/dist/
/lsp-types/dist-newstyle/
/lsp-types/TAGS
/lsp-types/tags
/lsp-types/ctags
hie
.hie
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
![CI](https://github.com/alanz/lsp/workflows/Haskell%20CI/badge.svg)
[![Hackage](https://img.shields.io/hackage/v/lsp?label=lsp)](https://hackage.haskell.org/package/lsp)
[![Hackage](https://img.shields.io/hackage/v/lsp?label=lsp-types)](https://hackage.haskell.org/package/lsp-types)
[![Hackage](https://img.shields.io/hackage/v/lsp?label=lsp-test)](https://hackage.haskell.org/package/lsp-test)

# lsp
Haskell library for the Microsoft Language Server Protocol.
It currently implements all of the [3.15 specification](https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/).

It is split into two separate packages, `lsp` and `lsp-types`
It is split into three separate packages, `lsp`, `lsp-types`, and `lsp-test`:
- `lsp-types` provides *type-safe* definitions that match up with the
typescript definitions laid out in the specification
- `lsp` is a library for building language servers, handling:
Expand All @@ -17,14 +18,14 @@ typescript definitions laid out in the specification
- Dynamic registration of capabilities
- Cancellable requests and progress notifications
- Publishing and flushing of diagnostics
- `lsp-test` is a functional testing framework for Language Server Protocol servers.

## Language servers built on lsp
- [ghcide](https://github.com/haskell/ghcide)
- [haskell-language-server](https://github.com/haskell/haskell-language-server)
- [dhall-lsp-server](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server#readme)

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

```haskell
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -80,12 +81,61 @@ 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

## Examples of using lsp-test

### Setting up a session

```haskell
import Language.LSP.Test
main = runSession "hie" fullCaps "proj/dir" $ do
doc <- openDoc "Foo.hs" "haskell"
skipMany anyNotification
symbols <- getDocumentSymbols doc
```

### Unit tests with HSpec

```haskell
describe "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 session
```haskell
replaySession "hie" "test/data/renamePass"
```

### Parsing with combinators
```haskell
skipManyTill loggingNotification publishDiagnosticsNotification
count 4 (message :: Session ApplyWorkspaceEditRequest)
anyRequest <|> anyResponse
```

Try out the example tests in the `lsp-test/example` directory with `cabal test`.
For more examples check the [Wiki](https://github.com/bubba/lsp-test/wiki/Introduction), or see this [introductory blog post](https://lukelau.me/haskell/posts/lsp-test/).

Whilst writing your tests you may want to debug them to see what's going wrong.
You can set the `logMessages` and `logStdErr` options in `SessionConfig` to see what the server is up to.
There are also corresponding environment variables so you can turn them on from the command line:
```
LSP_TEST_LOG_MESSAGES=1 LSP_TEST_LOG_STDERR=1 cabal test
```

## Troubleshooting
Seeing 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.](https://github.com/alanz/haskell-ide-engine/blob/bfb16324d396da71000ef81d51acbebbdaa854ab/test/utils/TestUtils.hs#L290-L298)

## Useful links

- https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
- [Language Server Protocol Specification](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md)

## Other resources

See #haskell-ide-engine on IRC freenode
See #haskell-language-server on IRC freenode.

2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

15 changes: 0 additions & 15 deletions bench/simple-bench.cabal

This file was deleted.

6 changes: 2 additions & 4 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
packages:
./
./lsp
./lsp-types/
./lsp-test/
./lsp-test/example
./func-test/
./bench/

package lsp
flags: +demo

tests: True
benchmarks: True
test-show-details: direct
haddock-quickjump: True
18 changes: 10 additions & 8 deletions hie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
# https://github.com/digital-asset/ghcide/issues/113
cradle:
cabal:
- path: "./lsp-test/test"
component: "lsp-test:test:tests"
- path: "./lsp-test"
component: "lsp-test"
- path: "./lsp-test/test"
component: "lsp-test:test:tests"
- path: "./lsp-test/func-test"
component: "lsp-test:test:func-test"
- path: "./lsp-test/bench"
component: "lsp-test:bench:simple-bench"
- path: "./lsp-types"
component: "lsp-types"
- path: "./src"
- path: "./lsp"
component: "lsp"
- path: "./test"
- path: "./lsp/test"
component: "unit-test"
- path: "./func-test"
component: "func-test"
- path: "./example/Reactor.hs"
- path: "./lsp/example/Reactor.hs"
component: "lsp-demo-reactor-server"
- path: "./example/Simple.hs"
- path: "./lsp/example/Simple.hs"
component: "lsp-demo-simple-server"
22 changes: 0 additions & 22 deletions lsp-test/.gitignore

This file was deleted.

53 changes: 0 additions & 53 deletions lsp-test/README.md

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion lsp-test/example/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Control.Monad.IO.Class
import Language.LSP.Test
import Language.LSP.Types

main = runSession "lsp-demo-reactor-server" fullCaps "../test/data/" $ do
main = runSession "lsp-demo-reactor-server" fullCaps "test/data/" $ do
doc <- openDoc "Rename.hs" "haskell"

-- Use your favourite favourite combinators.
Expand Down
2 changes: 0 additions & 2 deletions lsp-test/example/cabal.project

This file was deleted.

12 changes: 0 additions & 12 deletions lsp-test/example/example.cabal

This file was deleted.

File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions lsp-test/hie.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions lsp-test/lsp-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,39 @@ test-suite tests
, mtl
, aeson
default-language: Haskell2010

test-suite func-test
main-is: FuncTest.hs
hs-source-dirs: func-test
type: exitcode-stdio-1.0
build-depends: base <4.15
, lsp-test
, lsp
, data-default
, process
, lens
, unliftio
, hspec
, async
default-language: Haskell2010

test-suite example
main-is: Test.hs
hs-source-dirs: example
type: exitcode-stdio-1.0
build-depends: base
, lsp-test
, parser-combinators
build-tool-depends: lsp:lsp-demo-reactor-server

benchmark simple-bench
main-is: SimpleBench.hs
hs-source-dirs: bench
type: exitcode-stdio-1.0
build-depends: base <4.15
, lsp-test
, lsp
, process
, extra
default-language: Haskell2010
ghc-options: -Wall -O2 -eventlog -rtsopts
1 change: 0 additions & 1 deletion lsp-types/.hlint.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion lsp-types/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Revision history for haskell-lsp-types
# Revision history for lsp-types

## 1.1.0.0

Expand Down
13 changes: 0 additions & 13 deletions lsp-types/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions lsp-types/Setup.hs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions stack-8.4.2.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
resolver: nightly-2018-05-30 # last nightly for GHC 8.4.2

packages:
- '.'
- ./lsp
- ./lsp-types
- ./func-test
- ./lsp-test

extra-deps:
- rope-utf16-splay-0.3.1.0
Expand Down
4 changes: 2 additions & 2 deletions stack-8.4.3.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
resolver: lts-12.5 # GHC 8.4.3

packages:
- '.'
- ./lsp
- ./lsp-types
- ./func-test
- ./lsp-test

extra-deps:
- rope-utf16-splay-0.3.1.0
Expand Down
Loading