Skip to content

Commit b4b5b29

Browse files
committed
[ new ] LSP testing for agda-mode:load
1 parent 4998d83 commit b4b5b29

File tree

8 files changed

+65
-2
lines changed

8 files changed

+65
-2
lines changed

agda-language-server.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: agda-language-server
8-
version: 0.2.6.4.3.0
8+
version: 0.2.7.0.1.0
99
synopsis: An implementation of language server protocal (LSP) for Agda 2.
1010
description: Please see the README on GitHub at <https://github.com/agda/agda-language-server#readme>
1111
category: Development
@@ -171,6 +171,7 @@ test-suite als-test
171171
type: exitcode-stdio-1.0
172172
main-is: Test.hs
173173
other-modules:
174+
Test.LSP
174175
Test.SrcLoc
175176
Agda
176177
Agda.Convert
@@ -216,6 +217,7 @@ test-suite als-test
216217
, directory
217218
, filepath
218219
, lsp >=2
220+
, lsp-test
219221
, lsp-types >=2
220222
, mtl
221223
, network

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ tests:
130130
- test
131131
- src
132132
dependencies:
133+
- lsp-test
133134
- tasty
134135
- tasty-hunit
135136
- tasty-golden

src/Agda.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Agda
88
, runAgda
99
, sendCommand
1010
, getCommandLineOptions
11+
, CommandReq(..)
12+
, CommandRes(..)
1113
) where
1214

1315
import Prelude hiding ( null )
@@ -251,6 +253,7 @@ data CommandReq
251253
| CmdReq String
252254
deriving (Generic)
253255

256+
instance ToJSON CommandReq
254257
instance FromJSON CommandReq
255258

256259
data CommandRes

stack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extra-deps:
1010
- Agda-2.7.0.1
1111
- lsp-2.7.0.0@sha256:2a64b40a69fd9638056ca552d5660203019473061cff1d09dccc0c94e40a275c,3834
1212
- lsp-types-2.3.0.0@sha256:ca17a686bda5dc7ff04105ca7081dce5a90bcd050c8800a13efd68b7f0901f1c,34215
13+
- lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406
1314
- mod-0.2.0.1@sha256:eeb316fef3a8c12f4e83bbeeea748e74d75fca54d4498d574ace92e464adb05a,2409
1415
- row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071
1516

stack.yaml.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ packages:
2525
size: 51996
2626
original:
2727
hackage: lsp-types-2.3.0.0@sha256:ca17a686bda5dc7ff04105ca7081dce5a90bcd050c8800a13efd68b7f0901f1c,34215
28+
- completed:
29+
hackage: lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406
30+
pantry-tree:
31+
sha256: 66797a8efd50812189c410310dc0a9b72858ea3a3e78764e9cedd8f406df2564
32+
size: 1561
33+
original:
34+
hackage: lsp-test-0.17.1.0@sha256:f54757a564b46783cf67b13f4cb4ebc45e43f5afc3604d9757ee387c091b73e9,4406
2835
- completed:
2936
hackage: mod-0.2.0.1@sha256:eeb316fef3a8c12f4e83bbeeea748e74d75fca54d4498d574ace92e464adb05a,2409
3037
pantry-tree:

test/Test.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
module Test where
2+
13
import qualified Test.SrcLoc as SrcLoc
4+
import qualified Test.LSP as LSP
25
import Test.Tasty ( TestTree
36
, defaultMain
47
, testGroup
@@ -8,4 +11,7 @@ main :: IO ()
811
main = defaultMain tests
912

1013
tests :: TestTree
11-
tests = testGroup "Tests" [SrcLoc.tests]
14+
tests = testGroup "Tests"
15+
[SrcLoc.tests,
16+
LSP.tests
17+
]

test/Test/LSP.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Test.LSP (tests) where
3+
4+
import Control.Applicative.Combinators
5+
import Control.Monad.IO.Class
6+
import Language.LSP.Protocol.Message
7+
import Language.LSP.Protocol.Types
8+
import Language.LSP.Test
9+
import Test.Tasty
10+
import Test.Tasty.HUnit
11+
import qualified Data.Aeson as JSON
12+
import Switchboard ( agdaCustomMethod )
13+
import Agda
14+
15+
tests :: TestTree
16+
tests =
17+
testGroup
18+
"LSP"
19+
[ testCase "load" demo
20+
]
21+
22+
demo :: IO ()
23+
demo = runSession "als" fullLatestClientCaps "test/data/" $ do
24+
doc <- openDoc "A.agda" "agda"
25+
26+
-- Use your favourite favourite combinators.
27+
-- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification)
28+
29+
testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )"
30+
31+
-- Or use one of the helper functions
32+
-- getDocumentSymbols doc >>= liftIO . print
33+
34+
-- | Sends a custom method request to the server and expects a response of `CmdRes Nothing`
35+
testCustomMethod :: String -> Session ()
36+
testCustomMethod cmd = do
37+
TResponseMessage _ _ rsp <- request agdaCustomMethod $
38+
JSON.toJSON $ CmdReq cmd
39+
liftIO $ rsp @?= Right (JSON.toJSON (CmdRes Nothing))

test/data/A.agda

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A where
2+
3+
data : Set where
4+
tt :

0 commit comments

Comments
 (0)