1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
mod block_map;
mod fold_map;
mod inlay_map;
mod tab_map;
mod wrap_map;
use crate::EditorStyle;
use crate::{
link_go_to_definition::InlayHighlight, movement::TextLayoutDetails, Anchor, AnchorRangeExt,
InlayId, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
};
pub use block_map::{BlockMap, BlockPoint};
use collections::{BTreeMap, HashMap, HashSet};
use fold_map::FoldMap;
use gpui::{
Font, FontId, HighlightStyle, Hsla, LineLayout, Model, ModelContext, Pixels, ShapedLine,
TextRun, UnderlineStyle, WrappedLine,
};
use inlay_map::InlayMap;
use language::{
language_settings::language_settings, OffsetUtf16, Point, Subscription as BufferSubscription,
};
use lsp::DiagnosticSeverity;
use std::{any::TypeId, borrow::Cow, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
use sum_tree::{Bias, TreeMap};
use tab_map::TabMap;
use theme::{SyntaxTheme, Theme};
use wrap_map::WrapMap;
pub use block_map::{
BlockBufferRows as DisplayBufferRows, BlockChunks as DisplayChunks, BlockContext,
BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, TransformBlock,
};
pub use self::fold_map::{Fold, FoldPoint};
pub use self::inlay_map::{Inlay, InlayOffset, InlayPoint};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FoldStatus {
Folded,
Foldable,
}
const UNNECESSARY_CODE_FADE: f32 = 0.3;
pub trait ToDisplayPoint {
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
}
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
type InlayHighlights = BTreeMap<TypeId, HashMap<InlayId, (HighlightStyle, InlayHighlight)>>;
pub struct DisplayMap {
buffer: Model<MultiBuffer>,
buffer_subscription: BufferSubscription,
fold_map: FoldMap,
inlay_map: InlayMap,
tab_map: TabMap,
wrap_map: Model<WrapMap>,
block_map: BlockMap,
text_highlights: TextHighlights,
inlay_highlights: InlayHighlights,
pub clip_at_line_ends: bool,
}
impl DisplayMap {
pub fn new(
buffer: Model<MultiBuffer>,
font: Font,
font_size: Pixels,
wrap_width: Option<Pixels>,
buffer_header_height: u8,
excerpt_header_height: u8,
cx: &mut ModelContext<Self>,
) -> Self {
let buffer_subscription = buffer.update(cx, |buffer, _| buffer.subscribe());
let tab_size = Self::tab_size(&buffer, cx);
let (inlay_map, snapshot) = InlayMap::new(buffer.read(cx).snapshot(cx));
let (fold_map, snapshot) = FoldMap::new(snapshot);
let (tab_map, snapshot) = TabMap::new(snapshot, tab_size);
let (wrap_map, snapshot) = WrapMap::new(snapshot, font, font_size, wrap_width, cx);
let block_map = BlockMap::new(snapshot, buffer_header_height, excerpt_header_height);
cx.observe(&wrap_map, |_, _, cx| cx.notify()).detach();
DisplayMap {
buffer,
buffer_subscription,
fold_map,
inlay_map,
tab_map,
wrap_map,
block_map,
text_highlights: Default::default(),
inlay_highlights: Default::default(),
clip_at_line_ends: false,
}
}
pub fn snapshot(&mut self, cx: &mut ModelContext<Self>) -> DisplaySnapshot {
let buffer_snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let (inlay_snapshot, edits) = self.inlay_map.sync(buffer_snapshot, edits);
let (fold_snapshot, edits) = self.fold_map.read(inlay_snapshot.clone(), edits);
let tab_size = Self::tab_size(&self.buffer, cx);
let (tab_snapshot, edits) = self.tab_map.sync(fold_snapshot.clone(), edits, tab_size);
let (wrap_snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(tab_snapshot.clone(), edits, cx));
let block_snapshot = self.block_map.read(wrap_snapshot.clone(), edits);
DisplaySnapshot {
buffer_snapshot: self.buffer.read(cx).snapshot(cx),
fold_snapshot,
inlay_snapshot,
tab_snapshot,
wrap_snapshot,
block_snapshot,
text_highlights: self.text_highlights.clone(),
inlay_highlights: self.inlay_highlights.clone(),
clip_at_line_ends: self.clip_at_line_ends,
}
}
pub fn set_state(&mut self, other: &DisplaySnapshot, cx: &mut ModelContext<Self>) {
self.fold(
other
.folds_in_range(0..other.buffer_snapshot.len())
.map(|fold| fold.range.to_offset(&other.buffer_snapshot)),
cx,
);
}
pub fn fold<T: ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,
cx: &mut ModelContext<Self>,
) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let (snapshot, edits) = fold_map.fold(ranges);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
}
pub fn unfold<T: ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,
inclusive: bool,
cx: &mut ModelContext<Self>,
) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let (snapshot, edits) = fold_map.unfold(ranges, inclusive);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
}
pub fn insert_blocks(
&mut self,
blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
cx: &mut ModelContext<Self>,
) -> Vec<BlockId> {
let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
let mut block_map = self.block_map.write(snapshot, edits);
block_map.insert(blocks)
}
pub fn replace_blocks(&mut self, styles: HashMap<BlockId, RenderBlock>) {
self.block_map.replace(styles);
}
pub fn remove_blocks(&mut self, ids: HashSet<BlockId>, cx: &mut ModelContext<Self>) {
let snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
let mut block_map = self.block_map.write(snapshot, edits);
block_map.remove(ids);
}
pub fn highlight_text(
&mut self,
type_id: TypeId,
ranges: Vec<Range<Anchor>>,
style: HighlightStyle,
) {
self.text_highlights
.insert(Some(type_id), Arc::new((style, ranges)));
}
pub fn highlight_inlays(
&mut self,
type_id: TypeId,
highlights: Vec<InlayHighlight>,
style: HighlightStyle,
) {
for highlight in highlights {
self.inlay_highlights
.entry(type_id)
.or_default()
.insert(highlight.inlay, (style, highlight));
}
}
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range<Anchor>])> {
let highlights = self.text_highlights.get(&Some(type_id))?;
Some((highlights.0, &highlights.1))
}
pub fn clear_highlights(&mut self, type_id: TypeId) -> bool {
let mut cleared = self.text_highlights.remove(&Some(type_id)).is_some();
cleared |= self.inlay_highlights.remove(&type_id).is_none();
cleared
}
pub fn set_font(&self, font: Font, font_size: Pixels, cx: &mut ModelContext<Self>) -> bool {
self.wrap_map
.update(cx, |map, cx| map.set_font_with_size(font, font_size, cx))
}
pub fn set_fold_ellipses_color(&mut self, color: Hsla) -> bool {
self.fold_map.set_ellipses_color(color)
}
pub fn set_wrap_width(&self, width: Option<Pixels>, cx: &mut ModelContext<Self>) -> bool {
self.wrap_map
.update(cx, |map, cx| map.set_wrap_width(width, cx))
}
pub fn current_inlays(&self) -> impl Iterator<Item = &Inlay> {
self.inlay_map.current_inlays()
}
pub fn splice_inlays(
&mut self,
to_remove: Vec<InlayId>,
to_insert: Vec<Inlay>,
cx: &mut ModelContext<Self>,
) {
if to_remove.is_empty() && to_insert.is_empty() {
return;
}
let buffer_snapshot = self.buffer.read(cx).snapshot(cx);
let edits = self.buffer_subscription.consume().into_inner();
let (snapshot, edits) = self.inlay_map.sync(buffer_snapshot, edits);
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
let tab_size = Self::tab_size(&self.buffer, cx);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
let (snapshot, edits) = self.inlay_map.splice(to_remove, to_insert);
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.read(snapshot, edits);
}
fn tab_size(buffer: &Model<MultiBuffer>, cx: &mut ModelContext<Self>) -> NonZeroU32 {
let language = buffer
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).language());
language_settings(language.as_deref(), None, cx).tab_size
}
#[cfg(test)]
pub fn is_rewrapping(&self, cx: &gpui::AppContext) -> bool {
self.wrap_map.read(cx).is_rewrapping()
}
}
#[derive(Debug, Default)]
pub struct Highlights<'a> {
pub text_highlights: Option<&'a TextHighlights>,
pub inlay_highlights: Option<&'a InlayHighlights>,
pub inlay_highlight_style: Option<HighlightStyle>,
pub suggestion_highlight_style: Option<HighlightStyle>,
}
pub struct HighlightedChunk<'a> {
pub chunk: &'a str,
pub style: Option<HighlightStyle>,
pub is_tab: bool,
}
pub struct DisplaySnapshot {
pub buffer_snapshot: MultiBufferSnapshot,
pub fold_snapshot: fold_map::FoldSnapshot,
inlay_snapshot: inlay_map::InlaySnapshot,
tab_snapshot: tab_map::TabSnapshot,
wrap_snapshot: wrap_map::WrapSnapshot,
block_snapshot: block_map::BlockSnapshot,
text_highlights: TextHighlights,
inlay_highlights: InlayHighlights,
clip_at_line_ends: bool,
}
impl DisplaySnapshot {
#[cfg(test)]
pub fn fold_count(&self) -> usize {
self.fold_snapshot.fold_count()
}
pub fn is_empty(&self) -> bool {
self.buffer_snapshot.len() == 0
}
pub fn buffer_rows(&self, start_row: u32) -> DisplayBufferRows {
self.block_snapshot.buffer_rows(start_row)
}
pub fn max_buffer_row(&self) -> u32 {
self.buffer_snapshot.max_buffer_row()
}
pub fn prev_line_boundary(&self, mut point: Point) -> (Point, DisplayPoint) {
loop {
let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Left);
fold_point.0.column = 0;
inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
point = self.inlay_snapshot.to_buffer_point(inlay_point);
let mut display_point = self.point_to_display_point(point, Bias::Left);
*display_point.column_mut() = 0;
let next_point = self.display_point_to_point(display_point, Bias::Left);
if next_point == point {
return (point, display_point);
}
point = next_point;
}
}
pub fn next_line_boundary(&self, mut point: Point) -> (Point, DisplayPoint) {
loop {
let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Right);
fold_point.0.column = self.fold_snapshot.line_len(fold_point.row());
inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
point = self.inlay_snapshot.to_buffer_point(inlay_point);
let mut display_point = self.point_to_display_point(point, Bias::Right);
*display_point.column_mut() = self.line_len(display_point.row());
let next_point = self.display_point_to_point(display_point, Bias::Right);
if next_point == point {
return (point, display_point);
}
point = next_point;
}
}
// used by line_mode selections and tries to match vim behaviour
pub fn expand_to_line(&self, range: Range<Point>) -> Range<Point> {
let new_start = if range.start.row == 0 {
Point::new(0, 0)
} else if range.start.row == self.max_buffer_row()
|| (range.end.column > 0 && range.end.row == self.max_buffer_row())
{
Point::new(range.start.row - 1, self.line_len(range.start.row - 1))
} else {
self.prev_line_boundary(range.start).0
};
let new_end = if range.end.column == 0 {
range.end
} else if range.end.row < self.max_buffer_row() {
self.buffer_snapshot
.clip_point(Point::new(range.end.row + 1, 0), Bias::Left)
} else {
self.buffer_snapshot.max_point()
};
new_start..new_end
}
fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
let inlay_point = self.inlay_snapshot.to_inlay_point(point);
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
let tab_point = self.tab_snapshot.to_tab_point(fold_point);
let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
let block_point = self.block_snapshot.to_block_point(wrap_point);
DisplayPoint(block_point)
}
fn display_point_to_point(&self, point: DisplayPoint, bias: Bias) -> Point {
self.inlay_snapshot
.to_buffer_point(self.display_point_to_inlay_point(point, bias))
}
pub fn display_point_to_inlay_offset(&self, point: DisplayPoint, bias: Bias) -> InlayOffset {
self.inlay_snapshot
.to_offset(self.display_point_to_inlay_point(point, bias))
}
pub fn anchor_to_inlay_offset(&self, anchor: Anchor) -> InlayOffset {
self.inlay_snapshot
.to_inlay_offset(anchor.to_offset(&self.buffer_snapshot))
}
fn display_point_to_inlay_point(&self, point: DisplayPoint, bias: Bias) -> InlayPoint {
let block_point = point.0;
let wrap_point = self.block_snapshot.to_wrap_point(block_point);
let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
let fold_point = self.tab_snapshot.to_fold_point(tab_point, bias).0;
fold_point.to_inlay_point(&self.fold_snapshot)
}
pub fn display_point_to_fold_point(&self, point: DisplayPoint, bias: Bias) -> FoldPoint {
let block_point = point.0;
let wrap_point = self.block_snapshot.to_wrap_point(block_point);
let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
self.tab_snapshot.to_fold_point(tab_point, bias).0
}
pub fn fold_point_to_display_point(&self, fold_point: FoldPoint) -> DisplayPoint {
let tab_point = self.tab_snapshot.to_tab_point(fold_point);
let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
let block_point = self.block_snapshot.to_block_point(wrap_point);
DisplayPoint(block_point)
}
pub fn max_point(&self) -> DisplayPoint {
DisplayPoint(self.block_snapshot.max_point())
}
/// Returns text chunks starting at the given display row until the end of the file
pub fn text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
self.block_snapshot
.chunks(
display_row..self.max_point().row() + 1,
false,
Highlights::default(),
)
.map(|h| h.text)
}
/// Returns text chunks starting at the end of the given display row in reverse until the start of the file
pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
(0..=display_row).into_iter().rev().flat_map(|row| {
self.block_snapshot
.chunks(row..row + 1, false, Highlights::default())
.map(|h| h.text)
.collect::<Vec<_>>()
.into_iter()
.rev()
})
}
pub fn chunks<'a>(
&'a self,
display_rows: Range<u32>,
language_aware: bool,
inlay_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
) -> DisplayChunks<'a> {
self.block_snapshot.chunks(
display_rows,
language_aware,
Highlights {
text_highlights: Some(&self.text_highlights),
inlay_highlights: Some(&self.inlay_highlights),
inlay_highlight_style,
suggestion_highlight_style,
},
)
}
pub fn highlighted_chunks<'a>(
&'a self,
display_rows: Range<u32>,
language_aware: bool,
editor_style: &'a EditorStyle,
) -> impl Iterator<Item = HighlightedChunk<'a>> {
self.chunks(
display_rows,
language_aware,
Some(editor_style.syntax.inlay_style),
Some(editor_style.syntax.suggestion_style),
)
.map(|chunk| {
let mut highlight_style = chunk
.syntax_highlight_id
.and_then(|id| id.style(&editor_style.syntax));
if let Some(chunk_highlight) = chunk.highlight_style {
if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(chunk_highlight);
} else {
highlight_style = Some(chunk_highlight);
}
}
let mut diagnostic_highlight = HighlightStyle::default();
if chunk.is_unnecessary {
diagnostic_highlight.fade_out = Some(UNNECESSARY_CODE_FADE);
}
if let Some(severity) = chunk.diagnostic_severity {
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
let diagnostic_color =
super::diagnostic_style(severity, true, &editor_style.diagnostic_style);
diagnostic_highlight.underline = Some(UnderlineStyle {
color: Some(diagnostic_color),
thickness: 1.0.into(),
wavy: true,
});
}
}
if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(diagnostic_highlight);
} else {
highlight_style = Some(diagnostic_highlight);
}
HighlightedChunk {
chunk: chunk.text,
style: highlight_style,
is_tab: chunk.is_tab,
}
})
}
pub fn layout_row(
&self,
display_row: u32,
TextLayoutDetails {
text_system,
editor_style,
rem_size,
}: &TextLayoutDetails,
) -> Arc<LineLayout> {
let mut runs = Vec::new();
let mut line = String::new();
let range = display_row..display_row + 1;
for chunk in self.highlighted_chunks(range, false, &editor_style) {
line.push_str(chunk.chunk);
let text_style = if let Some(style) = chunk.style {
Cow::Owned(editor_style.text.clone().highlight(style))
} else {
Cow::Borrowed(&editor_style.text)
};
runs.push(text_style.to_run(chunk.chunk.len()))
}
if line.ends_with('\n') {
line.pop();
if let Some(last_run) = runs.last_mut() {
last_run.len -= 1;
if last_run.len == 0 {
runs.pop();
}
}
}
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
text_system
.layout_line(&line, font_size, &runs)
.expect("we expect the font to be loaded because it's rendered by the editor")
}
pub fn x_for_display_point(
&self,
display_point: DisplayPoint,
text_layout_details: &TextLayoutDetails,
) -> Pixels {
let line = self.layout_row(display_point.row(), text_layout_details);
line.x_for_index(display_point.column() as usize)
}
pub fn display_column_for_x(
&self,
display_row: u32,
x: Pixels,
details: &TextLayoutDetails,
) -> u32 {
let layout_line = self.layout_row(display_row, details);
layout_line.closest_index_for_x(x) as u32
}
pub fn chars_at(
&self,
mut point: DisplayPoint,
) -> impl Iterator<Item = (char, DisplayPoint)> + '_ {
point = DisplayPoint(self.block_snapshot.clip_point(point.0, Bias::Left));
self.text_chunks(point.row())
.flat_map(str::chars)
.skip_while({
let mut column = 0;
move |char| {
let at_point = column >= point.column();
column += char.len_utf8() as u32;
!at_point
}
})
.map(move |ch| {
let result = (ch, point);
if ch == '\n' {
*point.row_mut() += 1;
*point.column_mut() = 0;
} else {
*point.column_mut() += ch.len_utf8() as u32;
}
result
})
}
pub fn reverse_chars_at(
&self,
mut point: DisplayPoint,
) -> impl Iterator<Item = (char, DisplayPoint)> + '_ {
point = DisplayPoint(self.block_snapshot.clip_point(point.0, Bias::Left));
self.reverse_text_chunks(point.row())
.flat_map(|chunk| chunk.chars().rev())
.skip_while({
let mut column = self.line_len(point.row());
if self.max_point().row() > point.row() {
column += 1;
}
move |char| {
let at_point = column <= point.column();
column = column.saturating_sub(char.len_utf8() as u32);
!at_point
}
})
.map(move |ch| {
if ch == '\n' {
*point.row_mut() -= 1;
*point.column_mut() = self.line_len(point.row());
} else {
*point.column_mut() = point.column().saturating_sub(ch.len_utf8() as u32);
}
(ch, point)
})
}
pub fn column_to_chars(&self, display_row: u32, target: u32) -> u32 {
let mut count = 0;
let mut column = 0;
for (c, _) in self.chars_at(DisplayPoint::new(display_row, 0)) {
if column >= target {
break;
}
count += 1;
column += c.len_utf8() as u32;
}
count
}
pub fn column_from_chars(&self, display_row: u32, char_count: u32) -> u32 {
let mut column = 0;
for (count, (c, _)) in self.chars_at(DisplayPoint::new(display_row, 0)).enumerate() {
if c == '\n' || count >= char_count as usize {
break;
}
column += c.len_utf8() as u32;
}
column
}
pub fn clip_point(&self, point: DisplayPoint, bias: Bias) -> DisplayPoint {
let mut clipped = self.block_snapshot.clip_point(point.0, bias);
if self.clip_at_line_ends {
clipped = self.clip_at_line_end(DisplayPoint(clipped)).0
}
DisplayPoint(clipped)
}
pub fn clip_at_line_end(&self, point: DisplayPoint) -> DisplayPoint {
let mut point = point.0;
if point.column == self.line_len(point.row) {
point.column = point.column.saturating_sub(1);
point = self.block_snapshot.clip_point(point, Bias::Left);
}
DisplayPoint(point)
}
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
where
T: ToOffset,
{
self.fold_snapshot.folds_in_range(range)
}
pub fn blocks_in_range(
&self,
rows: Range<u32>,
) -> impl Iterator<Item = (u32, &TransformBlock)> {
self.block_snapshot.blocks_in_range(rows)
}
pub fn intersects_fold<T: ToOffset>(&self, offset: T) -> bool {
self.fold_snapshot.intersects_fold(offset)
}
pub fn is_line_folded(&self, buffer_row: u32) -> bool {
self.fold_snapshot.is_line_folded(buffer_row)
}
pub fn is_block_line(&self, display_row: u32) -> bool {
self.block_snapshot.is_block_line(display_row)
}
pub fn soft_wrap_indent(&self, display_row: u32) -> Option<u32> {
let wrap_row = self
.block_snapshot
.to_wrap_point(BlockPoint::new(display_row, 0))
.row();
self.wrap_snapshot.soft_wrap_indent(wrap_row)
}
pub fn text(&self) -> String {
self.text_chunks(0).collect()
}
pub fn line(&self, display_row: u32) -> String {
let mut result = String::new();
for chunk in self.text_chunks(display_row) {
if let Some(ix) = chunk.find('\n') {
result.push_str(&chunk[0..ix]);
break;
} else {
result.push_str(chunk);
}
}
result
}
pub fn line_indent(&self, display_row: u32) -> (u32, bool) {
let mut indent = 0;
let mut is_blank = true;
for (c, _) in self.chars_at(DisplayPoint::new(display_row, 0)) {
if c == ' ' {
indent += 1;
} else {
is_blank = c == '\n';
break;
}
}
(indent, is_blank)
}
pub fn line_indent_for_buffer_row(&self, buffer_row: u32) -> (u32, bool) {
let (buffer, range) = self
.buffer_snapshot
.buffer_line_for_row(buffer_row)
.unwrap();
let mut indent_size = 0;
let mut is_blank = false;
for c in buffer.chars_at(Point::new(range.start.row, 0)) {
if c == ' ' || c == '\t' {
indent_size += 1;
} else {
if c == '\n' {
is_blank = true;
}
break;
}
}
(indent_size, is_blank)
}
pub fn line_len(&self, row: u32) -> u32 {
self.block_snapshot.line_len(row)
}
pub fn longest_row(&self) -> u32 {
self.block_snapshot.longest_row()
}
pub fn fold_for_line(self: &Self, buffer_row: u32) -> Option<FoldStatus> {
if self.is_line_folded(buffer_row) {
Some(FoldStatus::Folded)
} else if self.is_foldable(buffer_row) {
Some(FoldStatus::Foldable)
} else {
None
}
}
pub fn is_foldable(self: &Self, buffer_row: u32) -> bool {
let max_row = self.buffer_snapshot.max_buffer_row();
if buffer_row >= max_row {
return false;
}
let (indent_size, is_blank) = self.line_indent_for_buffer_row(buffer_row);
if is_blank {
return false;
}
for next_row in (buffer_row + 1)..=max_row {
let (next_indent_size, next_line_is_blank) = self.line_indent_for_buffer_row(next_row);
if next_indent_size > indent_size {
return true;
} else if !next_line_is_blank {
break;
}
}
false
}
pub fn foldable_range(self: &Self, buffer_row: u32) -> Option<Range<Point>> {
let start = Point::new(buffer_row, self.buffer_snapshot.line_len(buffer_row));
if self.is_foldable(start.row) && !self.is_line_folded(start.row) {
let (start_indent, _) = self.line_indent_for_buffer_row(buffer_row);
let max_point = self.buffer_snapshot.max_point();
let mut end = None;
for row in (buffer_row + 1)..=max_point.row {
let (indent, is_blank) = self.line_indent_for_buffer_row(row);
if !is_blank && indent <= start_indent {
let prev_row = row - 1;
end = Some(Point::new(
prev_row,
self.buffer_snapshot.line_len(prev_row),
));
break;
}
}
let end = end.unwrap_or(max_point);
Some(start..end)
} else {
None
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn text_highlight_ranges<Tag: ?Sized + 'static>(
&self,
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
let type_id = TypeId::of::<Tag>();
self.text_highlights.get(&Some(type_id)).cloned()
}
#[cfg(any(test, feature = "test-support"))]
pub fn inlay_highlights<Tag: ?Sized + 'static>(
&self,
) -> Option<&HashMap<InlayId, (HighlightStyle, InlayHighlight)>> {
let type_id = TypeId::of::<Tag>();
self.inlay_highlights.get(&type_id)
}
}
#[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct DisplayPoint(BlockPoint);
impl Debug for DisplayPoint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
"DisplayPoint({}, {})",
self.row(),
self.column()
))
}
}
impl DisplayPoint {
pub fn new(row: u32, column: u32) -> Self {
Self(BlockPoint(Point::new(row, column)))
}
pub fn zero() -> Self {
Self::new(0, 0)
}
pub fn is_zero(&self) -> bool {
self.0.is_zero()
}
pub fn row(self) -> u32 {
self.0.row
}
pub fn column(self) -> u32 {
self.0.column
}
pub fn row_mut(&mut self) -> &mut u32 {
&mut self.0.row
}
pub fn column_mut(&mut self) -> &mut u32 {
&mut self.0.column
}
pub fn to_point(self, map: &DisplaySnapshot) -> Point {
map.display_point_to_point(self, Bias::Left)
}
pub fn to_offset(self, map: &DisplaySnapshot, bias: Bias) -> usize {
let wrap_point = map.block_snapshot.to_wrap_point(self.0);
let tab_point = map.wrap_snapshot.to_tab_point(wrap_point);
let fold_point = map.tab_snapshot.to_fold_point(tab_point, bias).0;
let inlay_point = fold_point.to_inlay_point(&map.fold_snapshot);
map.inlay_snapshot
.to_buffer_offset(map.inlay_snapshot.to_offset(inlay_point))
}
}
impl ToDisplayPoint for usize {
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
map.point_to_display_point(self.to_point(&map.buffer_snapshot), Bias::Left)
}
}
impl ToDisplayPoint for OffsetUtf16 {
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
self.to_offset(&map.buffer_snapshot).to_display_point(map)
}
}
impl ToDisplayPoint for Point {
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
map.point_to_display_point(*self, Bias::Left)
}
}
impl ToDisplayPoint for Anchor {
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint {
self.to_point(&map.buffer_snapshot).to_display_point(map)
}
}
pub fn next_rows(display_row: u32, display_map: &DisplaySnapshot) -> impl Iterator<Item = u32> {
let max_row = display_map.max_point().row();
let start_row = display_row + 1;
let mut current = None;
std::iter::from_fn(move || {
if current == None {
current = Some(start_row);
} else {
current = Some(current.unwrap() + 1)
}
if current.unwrap() > max_row {
None
} else {
current
}
})
}
// #[cfg(test)]
// pub mod tests {
// use super::*;
// use crate::{
// movement,
// test::{editor_test_context::EditorTestContext, marked_display_snapshot},
// };
// use gpui::{AppContext, Hsla};
// use language::{
// language_settings::{AllLanguageSettings, AllLanguageSettingsContent},
// Buffer, Language, LanguageConfig, SelectionGoal,
// };
// use project::Project;
// use rand::{prelude::*, Rng};
// use settings::SettingsStore;
// use smol::stream::StreamExt;
// use std::{env, sync::Arc};
// use theme::SyntaxTheme;
// use util::test::{marked_text_ranges, sample_text};
// use Bias::*;
// #[gpui::test(iterations = 100)]
// async fn test_random_display_map(cx: &mut gpui::TestAppContext, mut rng: StdRng) {
// cx.foreground().set_block_on_ticks(0..=50);
// cx.foreground().forbid_parking();
// let operations = env::var("OPERATIONS")
// .map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
// .unwrap_or(10);
// let font_cache = cx.font_cache().clone();
// let mut tab_size = rng.gen_range(1..=4);
// let buffer_start_excerpt_header_height = rng.gen_range(1..=5);
// let excerpt_header_height = rng.gen_range(1..=5);
// let family_id = font_cache
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 14.0;
// let max_wrap_width = 300.0;
// let mut wrap_width = if rng.gen_bool(0.1) {
// None
// } else {
// Some(rng.gen_range(0.0..=max_wrap_width))
// };
// log::info!("tab size: {}", tab_size);
// log::info!("wrap width: {:?}", wrap_width);
// cx.update(|cx| {
// init_test(cx, |s| s.defaults.tab_size = NonZeroU32::new(tab_size));
// });
// let buffer = cx.update(|cx| {
// if rng.gen() {
// let len = rng.gen_range(0..10);
// let text = util::RandomCharIter::new(&mut rng)
// .take(len)
// .collect::<String>();
// MultiBuffer::build_simple(&text, cx)
// } else {
// MultiBuffer::build_random(&mut rng, cx)
// }
// });
// let map = cx.add_model(|cx| {
// DisplayMap::new(
// buffer.clone(),
// font_id,
// font_size,
// wrap_width,
// buffer_start_excerpt_header_height,
// excerpt_header_height,
// cx,
// )
// });
// let mut notifications = observe(&map, cx);
// let mut fold_count = 0;
// let mut blocks = Vec::new();
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
// log::info!("fold text: {:?}", snapshot.fold_snapshot.text());
// log::info!("tab text: {:?}", snapshot.tab_snapshot.text());
// log::info!("wrap text: {:?}", snapshot.wrap_snapshot.text());
// log::info!("block text: {:?}", snapshot.block_snapshot.text());
// log::info!("display text: {:?}", snapshot.text());
// for _i in 0..operations {
// match rng.gen_range(0..100) {
// 0..=19 => {
// wrap_width = if rng.gen_bool(0.2) {
// None
// } else {
// Some(rng.gen_range(0.0..=max_wrap_width))
// };
// log::info!("setting wrap width to {:?}", wrap_width);
// map.update(cx, |map, cx| map.set_wrap_width(wrap_width, cx));
// }
// 20..=29 => {
// let mut tab_sizes = vec![1, 2, 3, 4];
// tab_sizes.remove((tab_size - 1) as usize);
// tab_size = *tab_sizes.choose(&mut rng).unwrap();
// log::info!("setting tab size to {:?}", tab_size);
// cx.update(|cx| {
// cx.update_global::<SettingsStore, _, _>(|store, cx| {
// store.update_user_settings::<AllLanguageSettings>(cx, |s| {
// s.defaults.tab_size = NonZeroU32::new(tab_size);
// });
// });
// });
// }
// 30..=44 => {
// map.update(cx, |map, cx| {
// if rng.gen() || blocks.is_empty() {
// let buffer = map.snapshot(cx).buffer_snapshot;
// let block_properties = (0..rng.gen_range(1..=1))
// .map(|_| {
// let position =
// buffer.anchor_after(buffer.clip_offset(
// rng.gen_range(0..=buffer.len()),
// Bias::Left,
// ));
// let disposition = if rng.gen() {
// BlockDisposition::Above
// } else {
// BlockDisposition::Below
// };
// let height = rng.gen_range(1..5);
// log::info!(
// "inserting block {:?} {:?} with height {}",
// disposition,
// position.to_point(&buffer),
// height
// );
// BlockProperties {
// style: BlockStyle::Fixed,
// position,
// height,
// disposition,
// render: Arc::new(|_| Empty::new().into_any()),
// }
// })
// .collect::<Vec<_>>();
// blocks.extend(map.insert_blocks(block_properties, cx));
// } else {
// blocks.shuffle(&mut rng);
// let remove_count = rng.gen_range(1..=4.min(blocks.len()));
// let block_ids_to_remove = (0..remove_count)
// .map(|_| blocks.remove(rng.gen_range(0..blocks.len())))
// .collect();
// log::info!("removing block ids {:?}", block_ids_to_remove);
// map.remove_blocks(block_ids_to_remove, cx);
// }
// });
// }
// 45..=79 => {
// let mut ranges = Vec::new();
// for _ in 0..rng.gen_range(1..=3) {
// buffer.read_with(cx, |buffer, cx| {
// let buffer = buffer.read(cx);
// let end = buffer.clip_offset(rng.gen_range(0..=buffer.len()), Right);
// let start = buffer.clip_offset(rng.gen_range(0..=end), Left);
// ranges.push(start..end);
// });
// }
// if rng.gen() && fold_count > 0 {
// log::info!("unfolding ranges: {:?}", ranges);
// map.update(cx, |map, cx| {
// map.unfold(ranges, true, cx);
// });
// } else {
// log::info!("folding ranges: {:?}", ranges);
// map.update(cx, |map, cx| {
// map.fold(ranges, cx);
// });
// }
// }
// _ => {
// buffer.update(cx, |buffer, cx| buffer.randomly_mutate(&mut rng, 5, cx));
// }
// }
// if map.read_with(cx, |map, cx| map.is_rewrapping(cx)) {
// notifications.next().await.unwrap();
// }
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// fold_count = snapshot.fold_count();
// log::info!("buffer text: {:?}", snapshot.buffer_snapshot.text());
// log::info!("fold text: {:?}", snapshot.fold_snapshot.text());
// log::info!("tab text: {:?}", snapshot.tab_snapshot.text());
// log::info!("wrap text: {:?}", snapshot.wrap_snapshot.text());
// log::info!("block text: {:?}", snapshot.block_snapshot.text());
// log::info!("display text: {:?}", snapshot.text());
// // Line boundaries
// let buffer = &snapshot.buffer_snapshot;
// for _ in 0..5 {
// let row = rng.gen_range(0..=buffer.max_point().row);
// let column = rng.gen_range(0..=buffer.line_len(row));
// let point = buffer.clip_point(Point::new(row, column), Left);
// let (prev_buffer_bound, prev_display_bound) = snapshot.prev_line_boundary(point);
// let (next_buffer_bound, next_display_bound) = snapshot.next_line_boundary(point);
// assert!(prev_buffer_bound <= point);
// assert!(next_buffer_bound >= point);
// assert_eq!(prev_buffer_bound.column, 0);
// assert_eq!(prev_display_bound.column(), 0);
// if next_buffer_bound < buffer.max_point() {
// assert_eq!(buffer.chars_at(next_buffer_bound).next(), Some('\n'));
// }
// assert_eq!(
// prev_display_bound,
// prev_buffer_bound.to_display_point(&snapshot),
// "row boundary before {:?}. reported buffer row boundary: {:?}",
// point,
// prev_buffer_bound
// );
// assert_eq!(
// next_display_bound,
// next_buffer_bound.to_display_point(&snapshot),
// "display row boundary after {:?}. reported buffer row boundary: {:?}",
// point,
// next_buffer_bound
// );
// assert_eq!(
// prev_buffer_bound,
// prev_display_bound.to_point(&snapshot),
// "row boundary before {:?}. reported display row boundary: {:?}",
// point,
// prev_display_bound
// );
// assert_eq!(
// next_buffer_bound,
// next_display_bound.to_point(&snapshot),
// "row boundary after {:?}. reported display row boundary: {:?}",
// point,
// next_display_bound
// );
// }
// // Movement
// let min_point = snapshot.clip_point(DisplayPoint::new(0, 0), Left);
// let max_point = snapshot.clip_point(snapshot.max_point(), Right);
// for _ in 0..5 {
// let row = rng.gen_range(0..=snapshot.max_point().row());
// let column = rng.gen_range(0..=snapshot.line_len(row));
// let point = snapshot.clip_point(DisplayPoint::new(row, column), Left);
// log::info!("Moving from point {:?}", point);
// let moved_right = movement::right(&snapshot, point);
// log::info!("Right {:?}", moved_right);
// if point < max_point {
// assert!(moved_right > point);
// if point.column() == snapshot.line_len(point.row())
// || snapshot.soft_wrap_indent(point.row()).is_some()
// && point.column() == snapshot.line_len(point.row()) - 1
// {
// assert!(moved_right.row() > point.row());
// }
// } else {
// assert_eq!(moved_right, point);
// }
// let moved_left = movement::left(&snapshot, point);
// log::info!("Left {:?}", moved_left);
// if point > min_point {
// assert!(moved_left < point);
// if point.column() == 0 {
// assert!(moved_left.row() < point.row());
// }
// } else {
// assert_eq!(moved_left, point);
// }
// }
// }
// }
// #[gpui::test(retries = 5)]
// async fn test_soft_wraps(cx: &mut gpui::TestAppContext) {
// cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX);
// cx.update(|cx| {
// init_test(cx, |_| {});
// });
// let mut cx = EditorTestContext::new(cx).await;
// let editor = cx.editor.clone();
// let window = cx.window.clone();
// cx.update_window(window, |cx| {
// let text_layout_details =
// editor.read_with(cx, |editor, cx| editor.text_layout_details(cx));
// let font_cache = cx.font_cache().clone();
// let family_id = font_cache
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 12.0;
// let wrap_width = Some(64.);
// let text = "one two three four five\nsix seven eight";
// let buffer = MultiBuffer::build_simple(text, cx);
// let map = cx.add_model(|cx| {
// DisplayMap::new(buffer.clone(), font_id, font_size, wrap_width, 1, 1, cx)
// });
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// assert_eq!(
// snapshot.text_chunks(0).collect::<String>(),
// "one two \nthree four \nfive\nsix seven \neight"
// );
// assert_eq!(
// snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Left),
// DisplayPoint::new(0, 7)
// );
// assert_eq!(
// snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Right),
// DisplayPoint::new(1, 0)
// );
// assert_eq!(
// movement::right(&snapshot, DisplayPoint::new(0, 7)),
// DisplayPoint::new(1, 0)
// );
// assert_eq!(
// movement::left(&snapshot, DisplayPoint::new(1, 0)),
// DisplayPoint::new(0, 7)
// );
// let x = snapshot.x_for_point(DisplayPoint::new(1, 10), &text_layout_details);
// assert_eq!(
// movement::up(
// &snapshot,
// DisplayPoint::new(1, 10),
// SelectionGoal::None,
// false,
// &text_layout_details,
// ),
// (
// DisplayPoint::new(0, 7),
// SelectionGoal::HorizontalPosition(x)
// )
// );
// assert_eq!(
// movement::down(
// &snapshot,
// DisplayPoint::new(0, 7),
// SelectionGoal::HorizontalPosition(x),
// false,
// &text_layout_details
// ),
// (
// DisplayPoint::new(1, 10),
// SelectionGoal::HorizontalPosition(x)
// )
// );
// assert_eq!(
// movement::down(
// &snapshot,
// DisplayPoint::new(1, 10),
// SelectionGoal::HorizontalPosition(x),
// false,
// &text_layout_details
// ),
// (
// DisplayPoint::new(2, 4),
// SelectionGoal::HorizontalPosition(x)
// )
// );
// let ix = snapshot.buffer_snapshot.text().find("seven").unwrap();
// buffer.update(cx, |buffer, cx| {
// buffer.edit([(ix..ix, "and ")], None, cx);
// });
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// assert_eq!(
// snapshot.text_chunks(1).collect::<String>(),
// "three four \nfive\nsix and \nseven eight"
// );
// // Re-wrap on font size changes
// map.update(cx, |map, cx| map.set_font_with_size(font_id, font_size + 3., cx));
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// assert_eq!(
// snapshot.text_chunks(1).collect::<String>(),
// "three \nfour five\nsix and \nseven \neight"
// )
// });
// }
// #[gpui::test]
// fn test_text_chunks(cx: &mut gpui::AppContext) {
// init_test(cx, |_| {});
// let text = sample_text(6, 6, 'a');
// let buffer = MultiBuffer::build_simple(&text, cx);
// let family_id = cx
// .font_cache()
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = cx
// .font_cache()
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 14.0;
// let map =
// cx.add_model(|cx| DisplayMap::new(buffer.clone(), font_id, font_size, None, 1, 1, cx));
// buffer.update(cx, |buffer, cx| {
// buffer.edit(
// vec![
// (Point::new(1, 0)..Point::new(1, 0), "\t"),
// (Point::new(1, 1)..Point::new(1, 1), "\t"),
// (Point::new(2, 1)..Point::new(2, 1), "\t"),
// ],
// None,
// cx,
// )
// });
// assert_eq!(
// map.update(cx, |map, cx| map.snapshot(cx))
// .text_chunks(1)
// .collect::<String>()
// .lines()
// .next(),
// Some(" b bbbbb")
// );
// assert_eq!(
// map.update(cx, |map, cx| map.snapshot(cx))
// .text_chunks(2)
// .collect::<String>()
// .lines()
// .next(),
// Some("c ccccc")
// );
// }
// #[gpui::test]
// async fn test_chunks(cx: &mut gpui::TestAppContext) {
// use unindent::Unindent as _;
// let text = r#"
// fn outer() {}
// mod module {
// fn inner() {}
// }"#
// .unindent();
// let theme = SyntaxTheme::new(vec![
// ("mod.body".to_string(), Hsla::red().into()),
// ("fn.name".to_string(), Hsla::blue().into()),
// ]);
// let language = Arc::new(
// Language::new(
// LanguageConfig {
// name: "Test".into(),
// path_suffixes: vec![".test".to_string()],
// ..Default::default()
// },
// Some(tree_sitter_rust::language()),
// )
// .with_highlights_query(
// r#"
// (mod_item name: (identifier) body: _ @mod.body)
// (function_item name: (identifier) @fn.name)
// "#,
// )
// .unwrap(),
// );
// language.set_theme(&theme);
// cx.update(|cx| init_test(cx, |s| s.defaults.tab_size = Some(2.try_into().unwrap())));
// let buffer = cx
// .add_model(|cx| Buffer::new(0, cx.model_id() as u64, text).with_language(language, cx));
// buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
// let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
// let font_cache = cx.font_cache();
// let family_id = font_cache
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 14.0;
// let map = cx.add_model(|cx| DisplayMap::new(buffer, font_id, font_size, None, 1, 1, cx));
// assert_eq!(
// cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)),
// vec![
// ("fn ".to_string(), None),
// ("outer".to_string(), Some(Hsla::blue())),
// ("() {}\n\nmod module ".to_string(), None),
// ("{\n fn ".to_string(), Some(Hsla::red())),
// ("inner".to_string(), Some(Hsla::blue())),
// ("() {}\n}".to_string(), Some(Hsla::red())),
// ]
// );
// assert_eq!(
// cx.update(|cx| syntax_chunks(3..5, &map, &theme, cx)),
// vec![
// (" fn ".to_string(), Some(Hsla::red())),
// ("inner".to_string(), Some(Hsla::blue())),
// ("() {}\n}".to_string(), Some(Hsla::red())),
// ]
// );
// map.update(cx, |map, cx| {
// map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
// });
// assert_eq!(
// cx.update(|cx| syntax_chunks(0..2, &map, &theme, cx)),
// vec![
// ("fn ".to_string(), None),
// ("out".to_string(), Some(Hsla::blue())),
// ("⋯".to_string(), None),
// (" fn ".to_string(), Some(Hsla::red())),
// ("inner".to_string(), Some(Hsla::blue())),
// ("() {}\n}".to_string(), Some(Hsla::red())),
// ]
// );
// }
// #[gpui::test]
// async fn test_chunks_with_soft_wrapping(cx: &mut gpui::TestAppContext) {
// use unindent::Unindent as _;
// cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX);
// let text = r#"
// fn outer() {}
// mod module {
// fn inner() {}
// }"#
// .unindent();
// let theme = SyntaxTheme::new(vec![
// ("mod.body".to_string(), Hsla::red().into()),
// ("fn.name".to_string(), Hsla::blue().into()),
// ]);
// let language = Arc::new(
// Language::new(
// LanguageConfig {
// name: "Test".into(),
// path_suffixes: vec![".test".to_string()],
// ..Default::default()
// },
// Some(tree_sitter_rust::language()),
// )
// .with_highlights_query(
// r#"
// (mod_item name: (identifier) body: _ @mod.body)
// (function_item name: (identifier) @fn.name)
// "#,
// )
// .unwrap(),
// );
// language.set_theme(&theme);
// cx.update(|cx| init_test(cx, |_| {}));
// let buffer = cx
// .add_model(|cx| Buffer::new(0, cx.model_id() as u64, text).with_language(language, cx));
// buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
// let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
// let font_cache = cx.font_cache();
// let family_id = font_cache
// .load_family(&["Courier"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 16.0;
// let map =
// cx.add_model(|cx| DisplayMap::new(buffer, font_id, font_size, Some(40.0), 1, 1, cx));
// assert_eq!(
// cx.update(|cx| syntax_chunks(0..5, &map, &theme, cx)),
// [
// ("fn \n".to_string(), None),
// ("oute\nr".to_string(), Some(Hsla::blue())),
// ("() \n{}\n\n".to_string(), None),
// ]
// );
// assert_eq!(
// cx.update(|cx| syntax_chunks(3..5, &map, &theme, cx)),
// [("{}\n\n".to_string(), None)]
// );
// map.update(cx, |map, cx| {
// map.fold(vec![Point::new(0, 6)..Point::new(3, 2)], cx)
// });
// assert_eq!(
// cx.update(|cx| syntax_chunks(1..4, &map, &theme, cx)),
// [
// ("out".to_string(), Some(Hsla::blue())),
// ("⋯\n".to_string(), None),
// (" \nfn ".to_string(), Some(Hsla::red())),
// ("i\n".to_string(), Some(Hsla::blue()))
// ]
// );
// }
// #[gpui::test]
// async fn test_chunks_with_text_highlights(cx: &mut gpui::TestAppContext) {
// cx.update(|cx| init_test(cx, |_| {}));
// let theme = SyntaxTheme::new(vec![
// ("operator".to_string(), Hsla::red().into()),
// ("string".to_string(), Hsla::green().into()),
// ]);
// let language = Arc::new(
// Language::new(
// LanguageConfig {
// name: "Test".into(),
// path_suffixes: vec![".test".to_string()],
// ..Default::default()
// },
// Some(tree_sitter_rust::language()),
// )
// .with_highlights_query(
// r#"
// ":" @operator
// (string_literal) @string
// "#,
// )
// .unwrap(),
// );
// language.set_theme(&theme);
// let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ «a»: B = "c «d»""#, false);
// let buffer = cx
// .add_model(|cx| Buffer::new(0, cx.model_id() as u64, text).with_language(language, cx));
// buffer.condition(cx, |buf, _| !buf.is_parsing()).await;
// let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
// let buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
// let font_cache = cx.font_cache();
// let family_id = font_cache
// .load_family(&["Courier"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 16.0;
// let map = cx.add_model(|cx| DisplayMap::new(buffer, font_id, font_size, None, 1, 1, cx));
// enum MyType {}
// let style = HighlightStyle {
// color: Some(Hsla::blue()),
// ..Default::default()
// };
// map.update(cx, |map, _cx| {
// map.highlight_text(
// TypeId::of::<MyType>(),
// highlighted_ranges
// .into_iter()
// .map(|range| {
// buffer_snapshot.anchor_before(range.start)
// ..buffer_snapshot.anchor_before(range.end)
// })
// .collect(),
// style,
// );
// });
// assert_eq!(
// cx.update(|cx| chunks(0..10, &map, &theme, cx)),
// [
// ("const ".to_string(), None, None),
// ("a".to_string(), None, Some(Hsla::blue())),
// (":".to_string(), Some(Hsla::red()), None),
// (" B = ".to_string(), None, None),
// ("\"c ".to_string(), Some(Hsla::green()), None),
// ("d".to_string(), Some(Hsla::green()), Some(Hsla::blue())),
// ("\"".to_string(), Some(Hsla::green()), None),
// ]
// );
// }
// #[gpui::test]
// fn test_clip_point(cx: &mut gpui::AppContext) {
// init_test(cx, |_| {});
// fn assert(text: &str, shift_right: bool, bias: Bias, cx: &mut gpui::AppContext) {
// let (unmarked_snapshot, mut markers) = marked_display_snapshot(text, cx);
// match bias {
// Bias::Left => {
// if shift_right {
// *markers[1].column_mut() += 1;
// }
// assert_eq!(unmarked_snapshot.clip_point(markers[1], bias), markers[0])
// }
// Bias::Right => {
// if shift_right {
// *markers[0].column_mut() += 1;
// }
// assert_eq!(unmarked_snapshot.clip_point(markers[0], bias), markers[1])
// }
// };
// }
// use Bias::{Left, Right};
// assert("ˇˇα", false, Left, cx);
// assert("ˇˇα", true, Left, cx);
// assert("ˇˇα", false, Right, cx);
// assert("ˇαˇ", true, Right, cx);
// assert("ˇˇ✋", false, Left, cx);
// assert("ˇˇ✋", true, Left, cx);
// assert("ˇˇ✋", false, Right, cx);
// assert("ˇ✋ˇ", true, Right, cx);
// assert("ˇˇ🍐", false, Left, cx);
// assert("ˇˇ🍐", true, Left, cx);
// assert("ˇˇ🍐", false, Right, cx);
// assert("ˇ🍐ˇ", true, Right, cx);
// assert("ˇˇ\t", false, Left, cx);
// assert("ˇˇ\t", true, Left, cx);
// assert("ˇˇ\t", false, Right, cx);
// assert("ˇ\tˇ", true, Right, cx);
// assert(" ˇˇ\t", false, Left, cx);
// assert(" ˇˇ\t", true, Left, cx);
// assert(" ˇˇ\t", false, Right, cx);
// assert(" ˇ\tˇ", true, Right, cx);
// assert(" ˇˇ\t", false, Left, cx);
// assert(" ˇˇ\t", false, Right, cx);
// }
// #[gpui::test]
// fn test_clip_at_line_ends(cx: &mut gpui::AppContext) {
// init_test(cx, |_| {});
// fn assert(text: &str, cx: &mut gpui::AppContext) {
// let (mut unmarked_snapshot, markers) = marked_display_snapshot(text, cx);
// unmarked_snapshot.clip_at_line_ends = true;
// assert_eq!(
// unmarked_snapshot.clip_point(markers[1], Bias::Left),
// markers[0]
// );
// }
// assert("ˇˇ", cx);
// assert("ˇaˇ", cx);
// assert("aˇbˇ", cx);
// assert("aˇαˇ", cx);
// }
// #[gpui::test]
// fn test_tabs_with_multibyte_chars(cx: &mut gpui::AppContext) {
// init_test(cx, |_| {});
// let text = "✅\t\tα\nβ\t\n🏀β\t\tγ";
// let buffer = MultiBuffer::build_simple(text, cx);
// let font_cache = cx.font_cache();
// let family_id = font_cache
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 14.0;
// let map =
// cx.add_model(|cx| DisplayMap::new(buffer.clone(), font_id, font_size, None, 1, 1, cx));
// let map = map.update(cx, |map, cx| map.snapshot(cx));
// assert_eq!(map.text(), "✅ α\nβ \n🏀β γ");
// assert_eq!(
// map.text_chunks(0).collect::<String>(),
// "✅ α\nβ \n🏀β γ"
// );
// assert_eq!(map.text_chunks(1).collect::<String>(), "β \n🏀β γ");
// assert_eq!(map.text_chunks(2).collect::<String>(), "🏀β γ");
// let point = Point::new(0, "✅\t\t".len() as u32);
// let display_point = DisplayPoint::new(0, "✅ ".len() as u32);
// assert_eq!(point.to_display_point(&map), display_point);
// assert_eq!(display_point.to_point(&map), point);
// let point = Point::new(1, "β\t".len() as u32);
// let display_point = DisplayPoint::new(1, "β ".len() as u32);
// assert_eq!(point.to_display_point(&map), display_point);
// assert_eq!(display_point.to_point(&map), point,);
// let point = Point::new(2, "🏀β\t\t".len() as u32);
// let display_point = DisplayPoint::new(2, "🏀β ".len() as u32);
// assert_eq!(point.to_display_point(&map), display_point);
// assert_eq!(display_point.to_point(&map), point,);
// // Display points inside of expanded tabs
// assert_eq!(
// DisplayPoint::new(0, "✅ ".len() as u32).to_point(&map),
// Point::new(0, "✅\t".len() as u32),
// );
// assert_eq!(
// DisplayPoint::new(0, "✅ ".len() as u32).to_point(&map),
// Point::new(0, "✅".len() as u32),
// );
// // Clipping display points inside of multi-byte characters
// assert_eq!(
// map.clip_point(DisplayPoint::new(0, "✅".len() as u32 - 1), Left),
// DisplayPoint::new(0, 0)
// );
// assert_eq!(
// map.clip_point(DisplayPoint::new(0, "✅".len() as u32 - 1), Bias::Right),
// DisplayPoint::new(0, "✅".len() as u32)
// );
// }
// #[gpui::test]
// fn test_max_point(cx: &mut gpui::AppContext) {
// init_test(cx, |_| {});
// let buffer = MultiBuffer::build_simple("aaa\n\t\tbbb", cx);
// let font_cache = cx.font_cache();
// let family_id = font_cache
// .load_family(&["Helvetica"], &Default::default())
// .unwrap();
// let font_id = font_cache
// .select_font(family_id, &Default::default())
// .unwrap();
// let font_size = 14.0;
// let map =
// cx.add_model(|cx| DisplayMap::new(buffer.clone(), font_id, font_size, None, 1, 1, cx));
// assert_eq!(
// map.update(cx, |map, cx| map.snapshot(cx)).max_point(),
// DisplayPoint::new(1, 11)
// )
// }
// fn syntax_chunks<'a>(
// rows: Range<u32>,
// map: &Model<DisplayMap>,
// theme: &'a SyntaxTheme,
// cx: &mut AppContext,
// ) -> Vec<(String, Option<Hsla>)> {
// chunks(rows, map, theme, cx)
// .into_iter()
// .map(|(text, color, _)| (text, color))
// .collect()
// }
// fn chunks<'a>(
// rows: Range<u32>,
// map: &Model<DisplayMap>,
// theme: &'a SyntaxTheme,
// cx: &mut AppContext,
// ) -> Vec<(String, Option<Hsla>, Option<Hsla>)> {
// let snapshot = map.update(cx, |map, cx| map.snapshot(cx));
// let mut chunks: Vec<(String, Option<Hsla>, Option<Hsla>)> = Vec::new();
// for chunk in snapshot.chunks(rows, true, None, None) {
// let syntax_color = chunk
// .syntax_highlight_id
// .and_then(|id| id.style(theme)?.color);
// let highlight_color = chunk.highlight_style.and_then(|style| style.color);
// if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut() {
// if syntax_color == *last_syntax_color && highlight_color == *last_highlight_color {
// last_chunk.push_str(chunk.text);
// continue;
// }
// }
// chunks.push((chunk.text.to_string(), syntax_color, highlight_color));
// }
// chunks
// }
// fn init_test(cx: &mut AppContext, f: impl Fn(&mut AllLanguageSettingsContent)) {
// cx.foreground().forbid_parking();
// cx.set_global(SettingsStore::test(cx));
// language::init(cx);
// crate::init(cx);
// Project::init_settings(cx);
// theme::init((), cx);
// cx.update_global::<SettingsStore, _, _>(|store, cx| {
// store.update_user_settings::<AllLanguageSettings>(cx, f);
// });
// }
// }