-sendNotification :: ToJSON a => ClientMethod -> a -> Session ()
-sendNotification method params = do
- h <- serverIn <$> lift ask
+sendNotification :: ToJSON a
+ => ClientMethod -- ^ The notification method.
+ -> a -- ^ The notification parameters.
+ -> Session ()
+
+-- | Open a virtual file if we send a did open text document notification
+sendNotification TextDocumentDidOpen params = do
+ let params' = fromJust $ decode $ encode params
+ n :: DidOpenTextDocumentNotification
+ n = NotificationMessage "2.0" TextDocumentDidOpen params'
+ oldVFS <- vfs <$> get
+ newVFS <- liftIO $ openVFS oldVFS n
+ modify (\s -> s { vfs = newVFS })
+ sendNotification' n
+
+-- | Close a virtual file if we send a close text document notification
+sendNotification TextDocumentDidClose params = do
+ let params' = fromJust $ decode $ encode params
+ n :: DidCloseTextDocumentNotification
+ n = NotificationMessage "2.0" TextDocumentDidClose params'
+ oldVFS <- vfs <$> get
+ newVFS <- liftIO $ closeVFS oldVFS n
+ modify (\s -> s { vfs = newVFS })
+ sendNotification' n
+
+sendNotification method params = sendNotification' (NotificationMessage "2.0" method params)