Skip to content

Commit 56ce055

Browse files
committed
fix: comments only
1 parent d439c36 commit 56ce055

File tree

1 file changed

+110
-0
lines changed
  • crates/pgt_workspace/src/workspace/server

1 file changed

+110
-0
lines changed

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

+110
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ impl Document {
137137
diff_size: TextSize,
138138
is_addition: bool,
139139
) -> Affected {
140+
// special case: no previous statements -> always full range
141+
if self.positions.is_empty() {
142+
let full_range = TextRange::new(0.into(), content_size);
143+
return Affected {
144+
affected_range: full_range,
145+
affected_indices: Vec::new(),
146+
prev_index: None,
147+
next_index: None,
148+
full_affected_range: full_range,
149+
};
150+
}
151+
140152
let mut start = change_range.start();
141153
let mut end = change_range.end().min(content_size);
142154

@@ -1422,4 +1434,102 @@ mod tests {
14221434

14231435
assert_document_integrity(&doc);
14241436
}
1437+
1438+
#[test]
1439+
fn test_comments_only() {
1440+
let path = PgTPath::new("test.sql");
1441+
let initial_content = "-- atlas:import async_trigger/setup.sql\n-- atlas:import public/setup.sql\n-- atlas:import private/setup.sql\n-- atlas:import api/setup.sql\n-- atlas:import async_trigger/index.sql\n-- atlas:import public/enums/index.sql\n-- atlas:import public/types/index.sql\n-- atlas:import private/enums/index.sql\n-- atlas:import private/functions/index.sql\n-- atlas:import public/tables/index.sql\n-- atlas:import public/index.sql\n-- atlas:import private/index.sql\n-- atlas:import api/index.sql\n\n\n\n";
1442+
1443+
// Create a new document
1444+
let mut doc = Document::new(initial_content.to_string(), 0);
1445+
1446+
// First change: Delete some text at line 2, character 24-29
1447+
let change1 = ChangeFileParams {
1448+
path: path.clone(),
1449+
version: 3,
1450+
changes: vec![ChangeParams {
1451+
text: "".to_string(),
1452+
range: Some(TextRange::new(
1453+
// Calculate the correct position based on the content
1454+
// Line 2, character 24
1455+
98.into(),
1456+
// Line 2, character 29
1457+
103.into(),
1458+
)),
1459+
}],
1460+
};
1461+
1462+
let _changes1 = doc.apply_file_change(&change1);
1463+
1464+
// Second change: Add 't' at line 2, character 24
1465+
let change2 = ChangeFileParams {
1466+
path: path.clone(),
1467+
version: 4,
1468+
changes: vec![ChangeParams {
1469+
text: "t".to_string(),
1470+
range: Some(TextRange::new(98.into(), 98.into())),
1471+
}],
1472+
};
1473+
1474+
let _changes2 = doc.apply_file_change(&change2);
1475+
1476+
assert_eq!(
1477+
doc.positions.len(),
1478+
0,
1479+
"Document should have no statement after adding 't'"
1480+
);
1481+
1482+
// Third change: Add 'e' at line 2, character 25
1483+
let change3 = ChangeFileParams {
1484+
path: path.clone(),
1485+
version: 5,
1486+
changes: vec![ChangeParams {
1487+
text: "e".to_string(),
1488+
range: Some(TextRange::new(99.into(), 99.into())),
1489+
}],
1490+
};
1491+
1492+
let _changes3 = doc.apply_file_change(&change3);
1493+
assert_eq!(
1494+
doc.positions.len(),
1495+
0,
1496+
"Document should still have no statement"
1497+
);
1498+
1499+
// Fourth change: Add 's' at line 2, character 26
1500+
let change4 = ChangeFileParams {
1501+
path: path.clone(),
1502+
version: 6,
1503+
changes: vec![ChangeParams {
1504+
text: "s".to_string(),
1505+
range: Some(TextRange::new(100.into(), 100.into())),
1506+
}],
1507+
};
1508+
1509+
let _changes4 = doc.apply_file_change(&change4);
1510+
assert_eq!(
1511+
doc.positions.len(),
1512+
0,
1513+
"Document should still have no statement"
1514+
);
1515+
1516+
// Fifth change: Add 't' at line 2, character 27
1517+
let change5 = ChangeFileParams {
1518+
path: path.clone(),
1519+
version: 7,
1520+
changes: vec![ChangeParams {
1521+
text: "t".to_string(),
1522+
range: Some(TextRange::new(101.into(), 101.into())),
1523+
}],
1524+
};
1525+
1526+
let _changes5 = doc.apply_file_change(&change5);
1527+
assert_eq!(
1528+
doc.positions.len(),
1529+
0,
1530+
"Document should still have no statement"
1531+
);
1532+
1533+
assert_document_integrity(&doc);
1534+
}
14251535
}

0 commit comments

Comments
 (0)