@@ -138,6 +138,12 @@ pub enum DocumentOpenError {
138138 IoError ( #[ from] io:: Error ) ,
139139}
140140
141+ #[ derive( Debug ) ]
142+ pub enum EmitLspNotification {
143+ Async ,
144+ Sync ,
145+ }
146+
141147pub struct Document {
142148 pub ( crate ) id : DocumentId ,
143149 text : Rope ,
@@ -1376,7 +1382,7 @@ impl Document {
13761382 & mut self ,
13771383 transaction : & Transaction ,
13781384 view_id : ViewId ,
1379- emit_lsp_notification : bool ,
1385+ emit_lsp_notification : Option < EmitLspNotification > ,
13801386 ) -> bool {
13811387 use helix_core:: Assoc ;
13821388
@@ -1525,7 +1531,7 @@ impl Document {
15251531 view : view_id,
15261532 old_text : & old_doc,
15271533 changes,
1528- ghost_transaction : ! emit_lsp_notification,
1534+ emit_lsp_notification,
15291535 } ) ;
15301536
15311537 // if specified, the current selection should instead be replaced by transaction.selection
@@ -1547,7 +1553,7 @@ impl Document {
15471553 & mut self ,
15481554 transaction : & Transaction ,
15491555 view_id : ViewId ,
1550- emit_lsp_notification : bool ,
1556+ emit_lsp_notification : Option < EmitLspNotification > ,
15511557 ) -> bool {
15521558 // store the state just before any changes are made. This allows us to undo to the
15531559 // state just before a transaction was applied.
@@ -1570,14 +1576,20 @@ impl Document {
15701576 }
15711577 /// Apply a [`Transaction`] to the [`Document`] to change its text.
15721578 pub fn apply ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1573- self . apply_inner ( transaction, view_id, true )
1579+ self . apply_inner ( transaction, view_id, Some ( EmitLspNotification :: Async ) )
1580+ }
1581+
1582+ /// Apply a [`Transaction`] to the [`Document`] to change its text and
1583+ /// emit the lsp notifcation synchronously
1584+ pub fn apply_sync_notification ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1585+ self . apply_inner ( transaction, view_id, Some ( EmitLspNotification :: Sync ) )
15741586 }
15751587
15761588 /// Apply a [`Transaction`] to the [`Document`] to change its text
15771589 /// without notifying the language servers. This is useful for temporary transactions
15781590 /// that must not influence the server.
15791591 pub fn apply_temporary ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1580- self . apply_inner ( transaction, view_id, false )
1592+ self . apply_inner ( transaction, view_id, None )
15811593 }
15821594
15831595 fn undo_redo_impl ( & mut self , view : & mut View , undo : bool ) -> bool {
@@ -1589,7 +1601,7 @@ impl Document {
15891601 let mut history = self . history . take ( ) ;
15901602 let txn = if undo { history. undo ( ) } else { history. redo ( ) } ;
15911603 let success = if let Some ( txn) = txn {
1592- self . apply_impl ( txn, view. id , true )
1604+ self . apply_impl ( txn, view. id , Some ( EmitLspNotification :: Async ) )
15931605 } else {
15941606 false
15951607 } ;
@@ -1645,7 +1657,12 @@ impl Document {
16451657 savepoint
16461658 }
16471659
1648- pub fn restore ( & mut self , view : & mut View , savepoint : & SavePoint , emit_lsp_notification : bool ) {
1660+ pub fn restore (
1661+ & mut self ,
1662+ view : & mut View ,
1663+ savepoint : & SavePoint ,
1664+ emit_lsp_notification : Option < EmitLspNotification > ,
1665+ ) {
16491666 assert_eq ! (
16501667 savepoint. view, view. id,
16511668 "Savepoint must not be used with a different view!"
@@ -1678,7 +1695,7 @@ impl Document {
16781695 } ;
16791696 let mut success = false ;
16801697 for txn in txns {
1681- if self . apply_impl ( & txn, view. id , true ) {
1698+ if self . apply_impl ( & txn, view. id , Some ( EmitLspNotification :: Async ) ) {
16821699 success = true ;
16831700 }
16841701 }
0 commit comments