Skip to content

Commit d248d56

Browse files
committed
progress
1 parent 1502679 commit d248d56

File tree

1 file changed

+16
-14
lines changed
  • crates/pgt_workspace/src/workspace/server

1 file changed

+16
-14
lines changed

crates/pgt_workspace/src/workspace/server/change.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ 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-
6966
// when we recieive more than one change, we need to push back the changes based on the
7067
// total range of the previous ones. This is because the ranges are always related to the original state.
68+
// BUT: only for the statement range changes, not for the text changes
69+
// this is why we pass both varaints to apply_change
7170
let mut changes = Vec::new();
7271

7372
let mut offset: i64 = 0;
@@ -89,16 +88,13 @@ impl Document {
8988
change
9089
};
9190

92-
changes.extend(self.apply_change(adjusted_change));
91+
changes.extend(self.apply_change(adjusted_change, change));
9392

94-
offset += change.change_size();
93+
offset += adjusted_change.change_size();
9594
}
9695

9796
self.version = change.version;
9897

99-
tracing::debug!("Applied changes {:?}", changes);
100-
tracing::debug!("Changed to {:?}", self.content);
101-
10298
changes
10399
}
104100

@@ -246,9 +242,17 @@ impl Document {
246242
}
247243

248244
/// Applies a single change to the document and returns the affected statements
249-
fn apply_change(&mut self, change: &ChangeParams) -> Vec<StatementChange> {
245+
///
246+
/// * `change`: The range-adjusted change to use for statement changes
247+
/// * `original_change`: The original change to use for text changes (yes, this is a bit confusing, and we might want to refactor this entire thing at some point.)
248+
fn apply_change(
249+
&mut self,
250+
change: &ChangeParams,
251+
original_change: &ChangeParams,
252+
) -> Vec<StatementChange> {
250253
// if range is none, we have a full change
251254
if change.range.is_none() {
255+
// doesnt matter what change since range is null
252256
return self.apply_full_change(change);
253257
}
254258

@@ -261,7 +265,7 @@ impl Document {
261265

262266
let change_range = change.range.unwrap();
263267
let previous_content = self.content.clone();
264-
let new_content = change.apply_to_text(&self.content);
268+
let new_content = original_change.apply_to_text(&self.content);
265269

266270
// we first need to determine the affected range and all affected statements, as well as
267271
// the index of the prev and the next statement, if any. The full affected range is the
@@ -1691,13 +1695,11 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA
16911695
],
16921696
};
16931697

1694-
let changes = doc.apply_file_change(&change1);
1695-
1696-
println!("changes: {:#?}", changes);
1698+
let _changes = doc.apply_file_change(&change1);
16971699

16981700
assert_eq!(
16991701
doc.content,
1700-
"select 1, 2, 22322313133933193 from unknown_users;\n"
1702+
"select 1, 2, 223223131339331931 from unknown_users;\n"
17011703
);
17021704

17031705
assert_document_integrity(&doc);

0 commit comments

Comments
 (0)