@@ -29,6 +29,7 @@ module Language.LSP.Test.Session
29
29
, bumpTimeoutId
30
30
, logMsg
31
31
, LogMsgType (.. )
32
+ , documentChangeUri
32
33
)
33
34
34
35
where
@@ -296,6 +297,14 @@ updateStateC = awaitForever $ \msg -> do
296
297
updateState msg
297
298
yield msg
298
299
300
+ -- extract Uri out from DocumentChange
301
+ -- didn't put this in `lsp-types` because TH was getting in the way
302
+ documentChangeUri :: DocumentChange -> Uri
303
+ documentChangeUri (InL x) = x ^. textDocument . uri
304
+ documentChangeUri (InR (InL x)) = x ^. uri
305
+ documentChangeUri (InR (InR (InL x))) = x ^. oldUri
306
+ documentChangeUri (InR (InR (InR x))) = x ^. uri
307
+
299
308
updateState :: (MonadIO m , HasReader SessionContext m , HasState SessionState m )
300
309
=> FromServerMessage -> m ()
301
310
@@ -323,8 +332,8 @@ updateState (FromServerMess SWorkspaceApplyEdit r) = do
323
332
-- First, prefer the versioned documentChanges field
324
333
allChangeParams <- case r ^. params . edit . documentChanges of
325
334
Just (List cs) -> do
326
- mapM_ (checkIfNeedsOpened . ( ^. textDocument . uri) ) cs
327
- return $ map getParams cs
335
+ mapM_ (checkIfNeedsOpened . documentChangeUri ) cs
336
+ return $ mapMaybe getParamsFromDocumentChange cs
328
337
-- Then fall back to the changes field
329
338
Nothing -> case r ^. params . edit . changes of
330
339
Just cs -> do
@@ -371,10 +380,16 @@ updateState (FromServerMess SWorkspaceApplyEdit r) = do
371
380
let (newVFS,_) = openVFS (vfs s) msg
372
381
return $ s { vfs = newVFS }
373
382
374
- getParams (TextDocumentEdit docId (List edits)) =
383
+ getParamsFromTextDocumentEdit :: TextDocumentEdit -> DidChangeTextDocumentParams
384
+ getParamsFromTextDocumentEdit (TextDocumentEdit docId (List edits)) =
375
385
let changeEvents = map (\ e -> TextDocumentContentChangeEvent (Just (e ^. range)) Nothing (e ^. newText)) edits
376
386
in DidChangeTextDocumentParams docId (List changeEvents)
377
387
388
+ getParamsFromDocumentChange :: DocumentChange -> Maybe DidChangeTextDocumentParams
389
+ getParamsFromDocumentChange (InL textDocumentEdit) = Just $ getParamsFromTextDocumentEdit textDocumentEdit
390
+ getParamsFromDocumentChange _ = Nothing
391
+
392
+
378
393
-- For a uri returns an infinite list of versions [n,n+1,n+2,...]
379
394
-- where n is the current version
380
395
textDocumentVersions uri = do
@@ -387,8 +402,8 @@ updateState (FromServerMess SWorkspaceApplyEdit r) = do
387
402
vers <- textDocumentVersions uri
388
403
pure $ map (\ (v, e) -> TextDocumentEdit v (List [e])) $ zip vers edits
389
404
390
- getChangeParams uri (List edits) =
391
- map <$> pure getParams <*> textDocumentEdits uri (reverse edits)
405
+ getChangeParams uri (List edits) = do
406
+ map <$> pure getParamsFromTextDocumentEdit <*> textDocumentEdits uri (reverse edits)
392
407
393
408
mergeParams :: [DidChangeTextDocumentParams ] -> DidChangeTextDocumentParams
394
409
mergeParams params = let events = concat (toList (map (toList . (^. contentChanges)) params))
0 commit comments