Skip to content

Commit

Permalink
Mappings for capabilities (#581)
Browse files Browse the repository at this point in the history
* Add golden tests for client cap generation

* Add mappings for capabilities

* Fix commment
  • Loading branch information
michaelpj authored May 25, 2024
1 parent 89799f7 commit fb8363a
Show file tree
Hide file tree
Showing 15 changed files with 1,416 additions and 333 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ hie
.hie
hie.yaml
.envrc
**/.golden/*/actual
4 changes: 2 additions & 2 deletions lsp-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and [lsp-types](https://hackage.haskell.org/package/lsp-types)

```haskell
import Language.LSP.Test
main = runSession "hie" fullCaps "proj/dir" $ do
main = runSession "hie" fullLatestClientCaps "proj/dir" $ do
doc <- openDoc "Foo.hs" "haskell"
skipMany anyNotification
symbols <- getDocumentSymbols doc
Expand All @@ -19,7 +19,7 @@ main = runSession "hie" fullCaps "proj/dir" $ do
### Unit tests with HSpec
```haskell
describe "diagnostics" $
it "report errors" $ runSession "hie" fullCaps "test/data" $ do
it "report errors" $ runSession "hie" fullLatestClientCaps "test/data" $ do
openDoc "Error.hs" "haskell"
[diag] <- waitForDiagnosticsSource "ghcmod"
liftIO $ do
Expand Down
2 changes: 1 addition & 1 deletion lsp-test/bench/SimpleBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ main = do

i <- newIORef (0 :: Integer)

Test.runSessionWithHandles hinWrite houtRead Test.defaultConfig Test.fullCaps "." $ do
Test.runSessionWithHandles hinWrite houtRead Test.defaultConfig Test.fullLatestClientCaps "." $ do
start <- liftIO offsetTime
replicateM_ n $ do
v <- liftIO $ readIORef i
Expand Down
2 changes: 1 addition & 1 deletion lsp-test/example/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Language.LSP.Protocol.Types
import Language.LSP.Test

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

-- Use your favourite favourite combinators.
Expand Down
10 changes: 5 additions & 5 deletions lsp-test/func-test/FuncTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ spec = do
updater $ ProgressAmount (Just 75) (Just "step3")
liftIO $ waitBarrier b3

runSessionWithServer logger definition Test.defaultConfig Test.fullCaps "." $ do
runSessionWithServer logger definition Test.defaultConfig Test.fullLatestClientCaps "." $ do
Test.sendRequest (SMethod_CustomMethod (Proxy @"something")) J.Null

-- Wait until we have seen a begin messsage. This means that the token setup
Expand Down Expand Up @@ -144,7 +144,7 @@ spec = do
-- Wait around to be cancelled, set the MVar only if we are
liftIO $ threadDelay (5 * 1000000) `Control.Exception.catch` (\(e :: ProgressCancelledException) -> modifyMVar_ wasCancelled (\_ -> pure True))

runSessionWithServer logger definition Test.defaultConfig Test.fullCaps "." $ do
runSessionWithServer logger definition Test.defaultConfig Test.fullLatestClientCaps "." $ do
Test.sendRequest (SMethod_CustomMethod (Proxy @"something")) J.Null

-- Wait until we have created the progress so the updates will be sent individually
Expand Down Expand Up @@ -190,7 +190,7 @@ spec = do
takeMVar killVar
Control.Exception.throwIO AsyncCancelled

runSessionWithServer logger definition Test.defaultConfig Test.fullCaps "." $ do
runSessionWithServer logger definition Test.defaultConfig Test.fullLatestClientCaps "." $ do
-- First make sure that we get a $/progress begin notification
skipManyTill Test.anyMessage $ do
x <- Test.message SMethod_Progress
Expand Down Expand Up @@ -235,7 +235,7 @@ spec = do
updater $ ProgressAmount (Just 75) (Just "step3")
liftIO $ waitBarrier b3

runSessionWithServer logger definition Test.defaultConfig Test.fullCaps "." $ do
runSessionWithServer logger definition Test.defaultConfig Test.fullLatestClientCaps "." $ do
Test.sendRequest SMethod_TextDocumentCodeLens (CodeLensParams (Just $ ProgressToken $ InR "hello") Nothing (TextDocumentIdentifier $ Uri "."))

-- First make sure that we get a $/progress begin notification
Expand Down Expand Up @@ -318,7 +318,7 @@ spec = do
ps = DidChangeWorkspaceFoldersParams ev
in Test.sendNotification SMethod_WorkspaceDidChangeWorkspaceFolders ps

runSessionWithServer logger definition config Test.fullCaps "." $ do
runSessionWithServer logger definition config Test.fullLatestClientCaps "." $ do
changeFolders [wf1] []
changeFolders [wf2] [wf1]

Expand Down
6 changes: 3 additions & 3 deletions lsp-test/src/Language/LSP/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Language.LSP.Test (
-- ** Config
SessionConfig (..),
defaultConfig,
C.fullCaps,
C.fullLatestClientCaps,

-- ** Exceptions
module Language.LSP.Test.Exceptions,
Expand Down Expand Up @@ -181,7 +181,7 @@ import System.Process (CreateProcess, ProcessHandle)

{- | Starts a new session.
> runSession "hie" fullCaps "path/to/root/dir" $ do
> runSession "hie" fullLatestClientCaps "path/to/root/dir" $ do
> doc <- openDoc "Desktop/simple.hs" "haskell"
> diags <- waitForDiagnostics
> let pos = Position 12 5
Expand Down Expand Up @@ -243,7 +243,7 @@ runSessionWithConfigCustomProcess modifyCreateProcess config' serverExe caps roo
> (houtRead, houtWrite) <- createPipe
>
> forkIO $ void $ runServerWithHandles hinRead houtWrite serverDefinition
> runSessionWithHandles hinWrite houtRead defaultConfig fullCaps "." $ do
> runSessionWithHandles hinWrite houtRead defaultConfig fullLatestClientCaps "." $ do
> -- ...
-}
runSessionWithHandles ::
Expand Down
2 changes: 1 addition & 1 deletion lsp-test/src/Language/LSP/Test/Replay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ replaySession serverExe sessionDir = do
runSessionWithHandles serverIn serverOut serverProc
(listenServer serverMsgs requestMap reqSema rspSema passSema mainThread)
def
fullCaps
fullLatestClientCaps
sessionDir
(return ()) -- No finalizer cleanup
(sendMessages clientMsgs reqSema rspSema)
Expand Down
Loading

0 comments on commit fb8363a

Please sign in to comment.