@@ -118,10 +118,8 @@ import Data.Default
118
118
import Data.List
119
119
import Data.Maybe
120
120
import Language.LSP.Protocol.Types
121
- hiding (capabilities , message , executeCommand , applyEdit , rename , to , id )
122
121
import Language.LSP.Protocol.Message
123
- import qualified Language.LSP.Protocol.Types as LSP
124
- import qualified Language.LSP.Protocol.Message as LSP
122
+ import qualified Language.LSP.Protocol.Lens as L
125
123
import qualified Language.LSP.Protocol.Capabilities as C
126
124
import Language.LSP.VFS
127
125
import Language.LSP.Test.Compat
@@ -229,7 +227,7 @@ runSessionWithHandles' serverProc serverIn serverOut config' caps rootDir sessio
229
227
-- collect them and then...
230
228
(inBetween, initRspMsg) <- manyTill_ anyMessage (responseForId SMethod_Initialize initReqId)
231
229
232
- case initRspMsg ^. LSP . result of
230
+ case initRspMsg ^. L . result of
233
231
Left error -> liftIO $ putStrLn (" Error while initializing: " ++ show error )
234
232
Right _ -> pure ()
235
233
@@ -293,7 +291,7 @@ envOverrideConfig cfg = do
293
291
documentContents :: TextDocumentIdentifier -> Session T. Text
294
292
documentContents doc = do
295
293
vfs <- vfs <$> get
296
- let Just file = vfs ^. vfsMap . at (toNormalizedUri (doc ^. uri))
294
+ let Just file = vfs ^. vfsMap . at (toNormalizedUri (doc ^. L. uri))
297
295
return (virtualFileText file)
298
296
299
297
-- | Parses an ApplyEditRequest, checks that it is for the passed document
@@ -308,14 +306,14 @@ getDocumentEdit doc = do
308
306
documentContents doc
309
307
where
310
308
checkDocumentChanges req =
311
- let changes = req ^. params . edit . documentChanges
309
+ let changes = req ^. L. params . L. edit . L. documentChanges
312
310
maybeDocs = fmap (fmap documentChangeUri) changes
313
311
in case maybeDocs of
314
- Just docs -> (doc ^. uri) `elem` docs
312
+ Just docs -> (doc ^. L. uri) `elem` docs
315
313
Nothing -> False
316
314
checkChanges req =
317
- let mMap = req ^. params . edit . changes
318
- in maybe False (Map. member (doc ^. uri)) mMap
315
+ let mMap = req ^. L. params . L. edit . L. changes
316
+ in maybe False (Map. member (doc ^. L. uri)) mMap
319
317
320
318
-- | Sends a request to the server and waits for its response.
321
319
-- Will skip any messages in between the request and the response
@@ -434,10 +432,10 @@ createDoc file languageId contents = do
434
432
createHits _ = False
435
433
436
434
regHits :: TRegistration Method_WorkspaceDidChangeWatchedFiles -> Bool
437
- regHits reg = foldl' (\ acc w -> acc || watchHits w) False (reg ^. registerOptions . _Just . watchers)
435
+ regHits reg = foldl' (\ acc w -> acc || watchHits w) False (reg ^. L. registerOptions . _Just . L. watchers)
438
436
439
437
clientCapsSupports =
440
- caps ^? workspace . _Just . didChangeWatchedFiles . _Just . dynamicRegistration . _Just
438
+ caps ^? L. workspace . _Just . L. didChangeWatchedFiles . _Just . L. dynamicRegistration . _Just
441
439
== Just True
442
440
shouldSend = clientCapsSupports && foldl' (\ acc r -> acc || regHits r) False regs
443
441
@@ -469,14 +467,14 @@ openDoc' file languageId contents = do
469
467
-- | Closes a text document and sends a textDocument/didOpen notification to the server.
470
468
closeDoc :: TextDocumentIdentifier -> Session ()
471
469
closeDoc docId = do
472
- let params = DidCloseTextDocumentParams (TextDocumentIdentifier (docId ^. uri))
470
+ let params = DidCloseTextDocumentParams (TextDocumentIdentifier (docId ^. L. uri))
473
471
sendNotification SMethod_TextDocumentDidClose params
474
472
475
473
-- | Changes a text document and sends a textDocument/didOpen notification to the server.
476
474
changeDoc :: TextDocumentIdentifier -> [TextDocumentContentChangeEvent ] -> Session ()
477
475
changeDoc docId changes = do
478
476
verDoc <- getVersionedDoc docId
479
- let params = DidChangeTextDocumentParams (verDoc & version +~ 1 ) changes
477
+ let params = DidChangeTextDocumentParams (verDoc & L. version +~ 1 ) changes
480
478
sendNotification SMethod_TextDocumentDidChange params
481
479
482
480
-- | Gets the Uri for the file corrected to the session directory.
@@ -490,7 +488,7 @@ getDocUri file = do
490
488
waitForDiagnostics :: Session [Diagnostic ]
491
489
waitForDiagnostics = do
492
490
diagsNot <- skipManyTill anyMessage (message SMethod_TextDocumentPublishDiagnostics )
493
- let diags = diagsNot ^. params . LSP . diagnostics
491
+ let diags = diagsNot ^. L. params . L . diagnostics
494
492
return diags
495
493
496
494
-- | The same as 'waitForDiagnostics', but will only match a specific
@@ -504,15 +502,15 @@ waitForDiagnosticsSource src = do
504
502
else return res
505
503
where
506
504
matches :: Diagnostic -> Bool
507
- matches d = d ^. source == Just (T. pack src)
505
+ matches d = d ^. L. source == Just (T. pack src)
508
506
509
507
-- | Expects a 'PublishDiagnosticsNotification' and throws an
510
508
-- 'UnexpectedDiagnostics' exception if there are any diagnostics
511
509
-- returned.
512
510
noDiagnostics :: Session ()
513
511
noDiagnostics = do
514
512
diagsNot <- message SMethod_TextDocumentPublishDiagnostics
515
- when (diagsNot ^. params . LSP . diagnostics /= [] ) $ liftIO $ throw UnexpectedDiagnostics
513
+ when (diagsNot ^. L. params . L . diagnostics /= [] ) $ liftIO $ throw UnexpectedDiagnostics
516
514
517
515
-- | Returns the symbols in a document.
518
516
getDocumentSymbols :: TextDocumentIdentifier -> Session (Either [SymbolInformation ] [DocumentSymbol ])
@@ -530,10 +528,10 @@ getCodeActions doc range = do
530
528
ctx <- getCodeActionContextInRange doc range
531
529
rsp <- request SMethod_TextDocumentCodeAction (CodeActionParams Nothing Nothing doc range ctx)
532
530
533
- case rsp ^. result of
531
+ case rsp ^. L. result of
534
532
Right (InL xs) -> return xs
535
533
Right (InR _) -> return []
536
- Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP .id ) error )
534
+ Left error -> throw (UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. L .id ) error )
537
535
538
536
-- | Returns all the code actions in a document by
539
537
-- querying the code actions at each of the current
@@ -547,7 +545,7 @@ getAllCodeActions doc = do
547
545
where
548
546
go :: CodeActionContext -> [Command |? CodeAction ] -> Diagnostic -> Session [Command |? CodeAction ]
549
547
go ctx acc diag = do
550
- TResponseMessage _ rspLid res <- request SMethod_TextDocumentCodeAction (CodeActionParams Nothing Nothing doc (diag ^. range) ctx)
548
+ TResponseMessage _ rspLid res <- request SMethod_TextDocumentCodeAction (CodeActionParams Nothing Nothing doc (diag ^. L. range) ctx)
551
549
552
550
case res of
553
551
Left e -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) e)
@@ -582,7 +580,7 @@ getCodeActionContext doc = do
582
580
-- | Returns the current diagnostics that have been sent to the client.
583
581
-- Note that this does not wait for more to come in.
584
582
getCurrentDiagnostics :: TextDocumentIdentifier -> Session [Diagnostic ]
585
- getCurrentDiagnostics doc = fromMaybe [] . Map. lookup (toNormalizedUri $ doc ^. uri) . curDiagnostics <$> get
583
+ getCurrentDiagnostics doc = fromMaybe [] . Map. lookup (toNormalizedUri $ doc ^. L. uri) . curDiagnostics <$> get
586
584
587
585
-- | Returns the tokens of all progress sessions that have started but not yet ended.
588
586
getIncompleteProgressSessions :: Session (Set. Set ProgressToken )
@@ -591,8 +589,8 @@ getIncompleteProgressSessions = curProgressSessions <$> get
591
589
-- | Executes a command.
592
590
executeCommand :: Command -> Session ()
593
591
executeCommand cmd = do
594
- let args = decode $ encode $ fromJust $ cmd ^. arguments
595
- execParams = ExecuteCommandParams Nothing (cmd ^. command) args
592
+ let args = decode $ encode $ fromJust $ cmd ^. L. arguments
593
+ execParams = ExecuteCommandParams Nothing (cmd ^. L. command) args
596
594
void $ sendRequest SMethod_WorkspaceExecuteCommand execParams
597
595
598
596
-- | Executes a code action.
@@ -601,8 +599,8 @@ executeCommand cmd = do
601
599
-- be applied first.
602
600
executeCodeAction :: CodeAction -> Session ()
603
601
executeCodeAction action = do
604
- maybe (return () ) handleEdit $ action ^. edit
605
- maybe (return () ) executeCommand $ action ^. command
602
+ maybe (return () ) handleEdit $ action ^. L. edit
603
+ maybe (return () ) executeCommand $ action ^. L. command
606
604
607
605
where handleEdit :: WorkspaceEdit -> Session ()
608
606
handleEdit e =
@@ -627,14 +625,14 @@ applyEdit doc edit = do
627
625
628
626
caps <- asks sessionCapabilities
629
627
630
- let supportsDocChanges = fromMaybe False $ caps ^? LSP . workspace . _Just . LSP . workspaceEdit . _Just . documentChanges . _Just
628
+ let supportsDocChanges = fromMaybe False $ caps ^? L . workspace . _Just . L . workspaceEdit . _Just . L. documentChanges . _Just
631
629
632
630
let wEdit = if supportsDocChanges
633
631
then
634
632
let docEdit = TextDocumentEdit (review _versionedTextDocumentIdentifier verDoc) [InL edit]
635
633
in WorkspaceEdit Nothing (Just [InL docEdit]) Nothing
636
634
else
637
- let changes = Map. singleton (doc ^. uri) [edit]
635
+ let changes = Map. singleton (doc ^. L. uri) [edit]
638
636
in WorkspaceEdit (Just changes) Nothing Nothing
639
637
640
638
let req = TRequestMessage " " (IdInt 0 ) SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wEdit)
@@ -650,7 +648,7 @@ getCompletions doc pos = do
650
648
651
649
case getResponseResult rsp of
652
650
InL items -> return items
653
- InR (InL c) -> return $ c ^. LSP . items
651
+ InR (InL c) -> return $ c ^. L . items
654
652
InR (InR _) -> return []
655
653
656
654
-- | Returns the references for the position in the document.
@@ -723,9 +721,9 @@ getHighlights doc pos =
723
721
-- Returns the result if successful.
724
722
getResponseResult :: (ToJSON (ErrorData m )) => TResponseMessage m -> MessageResult m
725
723
getResponseResult rsp =
726
- case rsp ^. result of
724
+ case rsp ^. L. result of
727
725
Right x -> x
728
- Left err -> throw $ UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. LSP .id ) err
726
+ Left err -> throw $ UnexpectedResponseError (SomeLspId $ fromJust $ rsp ^. L .id ) err
729
727
730
728
-- | Applies formatting to the specified document.
731
729
formatDoc :: TextDocumentIdentifier -> FormattingOptions -> Session ()
@@ -743,7 +741,7 @@ formatRange doc opts range = do
743
741
744
742
applyTextEdits :: TextDocumentIdentifier -> [TextEdit ] -> Session ()
745
743
applyTextEdits doc edits =
746
- let wEdit = WorkspaceEdit (Just (Map. singleton (doc ^. uri) edits)) Nothing Nothing
744
+ let wEdit = WorkspaceEdit (Just (Map. singleton (doc ^. L. uri) edits)) Nothing Nothing
747
745
-- Send a dummy message to updateState so it can do bookkeeping
748
746
req = TRequestMessage " " (IdInt 0 ) SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wEdit)
749
747
in updateState (FromServerMess SMethod_WorkspaceApplyEdit req)
0 commit comments