Skip to content

Commit

Permalink
Fix lsp-test example (#298)
Browse files Browse the repository at this point in the history
I noticed this was broken doing `cabal build all`.

- Fix compilation of the test.
- Depend on and use `lsp-demo-reactor-server` instead of HLS so it is
actually testable in isolation.
- Teach `lsp-demo-reactor-server` to respond to `TextDocumentSymbol`
(could have changed the example but this was easy enough).
- Ensure that the CI builds and tests it so we won't miss it in future.
  • Loading branch information
michaelpj authored Mar 5, 2021
1 parent 36030e9 commit cd5708b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
${{ runner.os }}-
- name: Build
run: cabal build
run: cabal build all
- name: Test
run: cabal test
- name: Func test
run: cabal test func-test
- name: Test lsp-test
run: cabal test lsp-test
run: cabal test all
8 changes: 8 additions & 0 deletions example/Reactor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ handle = mconcat
range = J.Range pos pos
responder (Right $ Just rsp)

, requestHandler J.STextDocumentDocumentSymbol $ \req responder -> do
liftIO $ debugM "reactor.handle" "Processing a textDocument/documentSymbol request"
let J.DocumentSymbolParams _ _ doc = req ^. J.params
loc = J.Location (doc ^. J.uri) (J.Range (J.Position 0 0) (J.Position 0 0))
sym = J.SymbolInformation "lsp-hello" J.SkFunction Nothing loc Nothing
rsp = J.InR (J.List [sym])
responder (Right rsp)

, requestHandler J.STextDocumentCodeAction $ \req responder -> do
liftIO $ debugM "reactor.handle" $ "Processing a textDocument/codeAction request"
let params = req ^. J.params
Expand Down
5 changes: 3 additions & 2 deletions lsp-test/example/Test.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative.Combinators
import Control.Monad.IO.Class
import Language.LSP.Test
import Language.LSP.Types

main = runSession "haskell-language-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.
skipManyTill loggingNotification (count 2 publishDiagnosticsNotification)
skipManyTill loggingNotification (count 1 publishDiagnosticsNotification)

-- Send requests and notifications and receive responses
rsp <- request STextDocumentDocumentSymbol $
Expand Down
1 change: 1 addition & 0 deletions lsp-test/example/example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ test-suite tests
build-depends: base
, lsp-test
, parser-combinators
build-tool-depends: lsp:lsp-demo-reactor-server

0 comments on commit cd5708b

Please sign in to comment.