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