@@ -63,6 +63,9 @@ impl Document {
6363 // very much not guaranteed to result in correct ranges
6464 self . diagnostics . clear ( ) ;
6565
66+ tracing:: debug!( "Changing from {:?}" , self . content) ;
67+ tracing:: debug!( "Applying changes {:?}" , & change. changes) ;
68+
6669 // when we recieive more than one change, we need to push back the changes based on the
6770 // total range of the previous ones. This is because the ranges are always related to the original state.
6871 let mut changes = Vec :: new ( ) ;
@@ -93,6 +96,9 @@ impl Document {
9396
9497 self . version = change. version ;
9598
99+ tracing:: debug!( "Applied changes {:?}" , changes) ;
100+ tracing:: debug!( "Changed to {:?}" , self . content) ;
101+
96102 changes
97103 }
98104
@@ -1663,6 +1669,40 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA
16631669 assert_document_integrity ( & doc) ;
16641670 }
16651671
1672+ #[ test]
1673+ fn test_content_out_of_sync ( ) {
1674+ let path = PgTPath :: new ( "test.sql" ) ;
1675+ let initial_content = "select 1, 2, 2232231313393319 from unknown_users;\n " ;
1676+
1677+ let mut doc = Document :: new ( initial_content. to_string ( ) , 0 ) ;
1678+
1679+ let change1 = ChangeFileParams {
1680+ path : path. clone ( ) ,
1681+ version : 1 ,
1682+ changes : vec ! [
1683+ ChangeParams {
1684+ range: Some ( TextRange :: new( 29 . into( ) , 29 . into( ) ) ) ,
1685+ text: "3" . to_string( ) ,
1686+ } ,
1687+ ChangeParams {
1688+ range: Some ( TextRange :: new( 30 . into( ) , 30 . into( ) ) ) ,
1689+ text: "1" . to_string( ) ,
1690+ } ,
1691+ ] ,
1692+ } ;
1693+
1694+ let changes = doc. apply_file_change ( & change1) ;
1695+
1696+ println ! ( "changes: {:#?}" , changes) ;
1697+
1698+ assert_eq ! (
1699+ doc. content,
1700+ "select 1, 2, 22322313133933193 from unknown_users;\n "
1701+ ) ;
1702+
1703+ assert_document_integrity ( & doc) ;
1704+ }
1705+
16661706 #[ test]
16671707 fn test_comments_only ( ) {
16681708 let path = PgTPath :: new ( "test.sql" ) ;
0 commit comments