@@ -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 ,
@@ -1381,7 +1387,7 @@ impl Document {
13811387 & mut self ,
13821388 transaction : & Transaction ,
13831389 view_id : ViewId ,
1384- emit_lsp_notification : bool ,
1390+ emit_lsp_notification : Option < EmitLspNotification > ,
13851391 ) -> bool {
13861392 use helix_core:: Assoc ;
13871393
@@ -1530,7 +1536,7 @@ impl Document {
15301536 view : view_id,
15311537 old_text : & old_doc,
15321538 changes,
1533- ghost_transaction : ! emit_lsp_notification,
1539+ emit_lsp_notification,
15341540 } ) ;
15351541
15361542 // if specified, the current selection should instead be replaced by transaction.selection
@@ -1552,7 +1558,7 @@ impl Document {
15521558 & mut self ,
15531559 transaction : & Transaction ,
15541560 view_id : ViewId ,
1555- emit_lsp_notification : bool ,
1561+ emit_lsp_notification : Option < EmitLspNotification > ,
15561562 ) -> bool {
15571563 // store the state just before any changes are made. This allows us to undo to the
15581564 // state just before a transaction was applied.
@@ -1575,14 +1581,20 @@ impl Document {
15751581 }
15761582 /// Apply a [`Transaction`] to the [`Document`] to change its text.
15771583 pub fn apply ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1578- self . apply_inner ( transaction, view_id, true )
1584+ self . apply_inner ( transaction, view_id, Some ( EmitLspNotification :: Async ) )
1585+ }
1586+
1587+ /// Apply a [`Transaction`] to the [`Document`] to change its text and
1588+ /// emit the lsp notifcation synchronously
1589+ pub fn apply_sync_notification ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1590+ self . apply_inner ( transaction, view_id, Some ( EmitLspNotification :: Sync ) )
15791591 }
15801592
15811593 /// Apply a [`Transaction`] to the [`Document`] to change its text
15821594 /// without notifying the language servers. This is useful for temporary transactions
15831595 /// that must not influence the server.
15841596 pub fn apply_temporary ( & mut self , transaction : & Transaction , view_id : ViewId ) -> bool {
1585- self . apply_inner ( transaction, view_id, false )
1597+ self . apply_inner ( transaction, view_id, None )
15861598 }
15871599
15881600 fn undo_redo_impl ( & mut self , view : & mut View , undo : bool ) -> bool {
@@ -1594,7 +1606,7 @@ impl Document {
15941606 let mut history = self . history . take ( ) ;
15951607 let txn = if undo { history. undo ( ) } else { history. redo ( ) } ;
15961608 let success = if let Some ( txn) = txn {
1597- self . apply_impl ( txn, view. id , true )
1609+ self . apply_impl ( txn, view. id , Some ( EmitLspNotification :: Async ) )
15981610 } else {
15991611 false
16001612 } ;
@@ -1650,7 +1662,12 @@ impl Document {
16501662 savepoint
16511663 }
16521664
1653- pub fn restore ( & mut self , view : & mut View , savepoint : & SavePoint , emit_lsp_notification : bool ) {
1665+ pub fn restore (
1666+ & mut self ,
1667+ view : & mut View ,
1668+ savepoint : & SavePoint ,
1669+ emit_lsp_notification : Option < EmitLspNotification > ,
1670+ ) {
16541671 assert_eq ! (
16551672 savepoint. view, view. id,
16561673 "Savepoint must not be used with a different view!"
@@ -1683,7 +1700,7 @@ impl Document {
16831700 } ;
16841701 let mut success = false ;
16851702 for txn in txns {
1686- if self . apply_impl ( & txn, view. id , true ) {
1703+ if self . apply_impl ( & txn, view. id , Some ( EmitLspNotification :: Async ) ) {
16871704 success = true ;
16881705 }
16891706 }
0 commit comments