+
+ where processor :: SessionProcessor ()
+ processor = awaitForever $ \msg -> do
+ processTextChanges msg
+ yield msg
+
+
+processTextChanges :: FromServerMessage -> SessionProcessor ()
+processTextChanges (ReqApplyWorkspaceEdit r) = do
+ List changeParams <- case r ^. params . edit . documentChanges of
+ Just cs -> mapM applyTextDocumentEdit cs
+ Nothing -> case r ^. params . edit . changes of
+ Just cs -> mapM (uncurry applyTextEdit) (List (HashMap.toList cs))
+ Nothing -> return (List [])
+
+ let groupedParams = groupBy (\a b -> (a ^. textDocument == b ^. textDocument)) changeParams
+ mergedParams = map mergeParams groupedParams
+
+ forM_ mergedParams $ \p -> do
+ h <- serverIn <$> lift (lift Reader.ask)
+ let msg = NotificationMessage "2.0" TextDocumentDidChange p
+ liftIO $ B.hPut h $ addHeader (encode msg)
+
+ where applyTextDocumentEdit (TextDocumentEdit docId (List edits)) = do
+ oldVFS <- vfs <$> lift State.get
+ let changeEvents = map (\e -> TextDocumentContentChangeEvent (Just (e ^. range)) Nothing (e ^. newText)) edits
+ params = DidChangeTextDocumentParams docId (List changeEvents)
+ newVFS <- liftIO $ changeVFS oldVFS (fmClientDidChangeTextDocumentNotification params)
+ lift $ State.modify (\s -> s { vfs = newVFS })
+ return params
+
+ applyTextEdit uri edits = applyTextDocumentEdit (TextDocumentEdit (VersionedTextDocumentIdentifier uri 0) edits)
+
+ mergeParams :: [DidChangeTextDocumentParams] -> DidChangeTextDocumentParams
+ mergeParams params = let events = concat (toList (map (toList . (^. contentChanges)) params))
+ in DidChangeTextDocumentParams (head params ^. textDocument) (List events)
+processTextChanges _ = return ()
\ No newline at end of file