diff --git a/Cargo.lock b/Cargo.lock index 49a417890..d8e9d1954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,19 +4,13 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "adler2" version = "2.0.0" @@ -80,23 +74,23 @@ checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", - "miniz_oxide 0.7.4", + "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -124,9 +118,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cassowary" @@ -136,9 +130,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.1.23" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -272,7 +266,7 @@ checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if", "crossbeam-utils", - "hashbrown", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -326,9 +320,9 @@ dependencies = [ [[package]] name = "error-code" -version = "3.2.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0474425d51df81997e2f90a21591180b38eccf27292d755f3e30750225c175b" +checksum = "a5d9305ccc6942a704f4335694ecd3de2ea531b114ac2d51f5f843750787a92f" [[package]] name = "etcetera" @@ -387,12 +381,12 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", - "miniz_oxide 0.8.0", + "miniz_oxide", ] [[package]] @@ -412,15 +406,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -429,15 +423,15 @@ dependencies = [ [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", "futures-task", @@ -459,9 +453,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gix" @@ -768,7 +762,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ddf80e16f3c19ac06ce415a38b8591993d3f73aede049cb561becb5b3a8e242" dependencies = [ "gix-hash", - "hashbrown", + "hashbrown 0.14.5", "parking_lot", ] @@ -804,7 +798,7 @@ dependencies = [ "gix-traverse", "gix-utils", "gix-validate", - "hashbrown", + "hashbrown 0.14.5", "itoa", "libc", "memmap2", @@ -1197,6 +1191,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "helix-core" version = "24.7.0" @@ -1209,7 +1209,7 @@ dependencies = [ "encoding_rs", "etcetera", "globset", - "hashbrown", + "hashbrown 0.14.5", "helix-loader", "helix-stdx", "imara-diff", @@ -1226,12 +1226,13 @@ dependencies = [ "slotmap", "smallvec", "smartstring", + "streaming-iterator", "textwrap", "toml", "tree-sitter", "unicode-general-category", "unicode-segmentation", - "unicode-width", + "unicode-width 0.2.0", "url", ] @@ -1257,7 +1258,7 @@ dependencies = [ "ahash", "anyhow", "futures-executor", - "hashbrown", + "hashbrown 0.14.5", "log", "once_cell", "parking_lot", @@ -1466,9 +1467,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1520,17 +1521,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc9da1a252bd44cd341657203722352efc9bc0c847d06ea6d2dc1cd1135e0a01" dependencies = [ "ahash", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.0", ] [[package]] @@ -1664,22 +1665,13 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memmap2" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" dependencies = [ "libc", ] -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.8.0" @@ -1744,21 +1736,18 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "open" @@ -1820,15 +1809,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -1908,9 +1897,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] @@ -2052,9 +2041,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -2182,11 +2171,17 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" +[[package]] +name = "streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" + [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -2223,7 +2218,7 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", "unicode-linebreak", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -2333,9 +2328,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", @@ -2346,14 +2341,23 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.22.6" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca" +checksum = "23b84f60031bf8245b563a80c92c1034e557a914f7958f474bc0afa2eed78b98" dependencies = [ "cc", "regex", + "regex-syntax", + "streaming-iterator", + "tree-sitter-language", ] +[[package]] +name = "tree-sitter-language" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ddffe35a0e5eeeadf13ff7350af564c6e73993a24db62caee1822b185c2600" + [[package]] name = "unicase" version = "2.7.0" @@ -2365,9 +2369,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-bom" @@ -2383,9 +2387,9 @@ checksum = "2281c8c1d221438e373249e065ca4989c4c36952c211ff21a0ee91c44a3869e7" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-linebreak" @@ -2395,9 +2399,9 @@ checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] @@ -2410,9 +2414,15 @@ checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.1.12" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "unicode-width" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" [[package]] name = "url" @@ -2705,9 +2715,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 763992480..18c0fa480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ package.helix-tui.opt-level = 2 package.helix-term.opt-level = 2 [workspace.dependencies] -tree-sitter = { version = "0.22" } +tree-sitter = { version = "0.24" } nucleo = "0.5.0" slotmap = "1.0.7" thiserror = "1.0" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 4cd516268..f213d2f6e 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -28,7 +28,7 @@ unicode-segmentation = "1.12" # width definitions in terminals, we need to replace it. # For now lets lock the version to avoid rendering glitches # when installing without `--locked` -unicode-width = "=0.1.12" +unicode-width = "=0.2.0" unicode-general-category = "0.6" slotmap.workspace = true tree-sitter.workspace = true @@ -58,6 +58,7 @@ textwrap = "0.16.1" nucleo.workspace = true parking_lot = "0.12" globset = "0.4.15" +streaming-iterator = "0.1.9" [dev-dependencies] quickcheck = { version = "1", default-features = false } diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index ae26c13e0..87b75f70f 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -1,6 +1,7 @@ use std::{borrow::Cow, collections::HashMap}; use helix_stdx::rope::RopeSliceExt; +use streaming_iterator::StreamingIterator; use tree_sitter::{Query, QueryCursor, QueryPredicateArg}; use crate::{ @@ -452,8 +453,9 @@ fn query_indents<'a>( let mut extend_captures: HashMap> = HashMap::new(); cursor.set_byte_range(range); + let mut captures = cursor.matches(query, syntax.tree().root_node(), RopeProvider(text)); // Iterate over all captures from the query - for m in cursor.matches(query, syntax.tree().root_node(), RopeProvider(text)) { + while let Some(m) = captures.next() { // Skip matches where not all custom predicates are fulfilled if !query.general_predicates(m.pattern_index).iter().all(|pred| { match pred.operator.as_ref() { diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index e446d8cc4..4d1c119dd 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -1,6 +1,7 @@ use std::{cmp::Reverse, iter}; use ropey::iter::Chars; +use streaming_iterator::StreamingIterator; use tree_sitter::{Node, QueryCursor}; use crate::{ @@ -588,15 +589,17 @@ pub fn goto_treesitter_object( let node = match dir { Direction::Forward => nodes .filter(|n| n.start_byte() > byte_pos) - .min_by_key(|n| (n.start_byte(), Reverse(n.end_byte())))?, + .map_deref(|c| c.byte_range()) + .min_by_key(|n| (n.start, Reverse(n.end)))?, Direction::Backward => nodes .filter(|n| n.end_byte() < byte_pos) - .max_by_key(|n| (n.end_byte(), Reverse(n.start_byte())))?, + .map_deref(|c| c.byte_range()) + .max_by_key(|n| (n.end, Reverse(n.start)))?, }; let len = slice.len_bytes(); - let start_byte = node.start_byte(); - let end_byte = node.end_byte(); + let start_byte = node.start; + let end_byte = node.end; if start_byte >= len || end_byte >= len { return None; } diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 7de6ddf44..5f8040068 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -16,6 +16,7 @@ use globset::GlobSet; use hashbrown::raw::RawTable; use helix_stdx::rope::{self, RopeSliceExt}; use slotmap::{DefaultKey as LayerId, HopSlotMap}; +use streaming_iterator::StreamingIterator; use std::{ borrow::Cow, @@ -679,7 +680,7 @@ impl TextObjectQuery { node: Node<'a>, slice: RopeSlice<'a>, cursor: &'a mut QueryCursor, - ) -> Option>> { + ) -> Option>> { self.capture_nodes_any(&[capture_name], node, slice, cursor) } @@ -691,7 +692,7 @@ impl TextObjectQuery { node: Node<'a>, slice: RopeSlice<'a>, cursor: &'a mut QueryCursor, - ) -> Option>> { + ) -> Option>> { let capture_idx = capture_names .iter() .find_map(|cap| self.query.capture_index_for_name(cap))?; @@ -1288,7 +1289,7 @@ impl Syntax { let layer = &self.layers[layer_id]; // Process injections. - let matches = cursor.matches( + let mut matches = cursor.matches( &layer.config.injections_query, layer.tree().root_node(), RopeProvider(source_slice), @@ -1299,10 +1300,10 @@ impl Syntax { ]; let mut injections = Vec::new(); let mut last_injection_end = 0; - for mat in matches { + while let Some(mat) = matches.next() { let (injection_capture, content_node, included_children) = layer .config - .injection_for_match(&layer.config.injections_query, &mat, source_slice); + .injection_for_match(&layer.config.injections_query, mat, source_slice); // in case this is a combined injection save it for more processing later if let Some(combined_injection_idx) = layer @@ -1441,16 +1442,15 @@ impl Syntax { cursor_ref.set_byte_range(range.clone().unwrap_or(0..usize::MAX)); cursor_ref.set_match_limit(TREE_SITTER_MATCH_LIMIT); - let mut captures = cursor_ref - .captures( - &layer.config.query, - layer.tree().root_node(), - RopeProvider(source), - ) - .peekable(); + let mut captures = cursor_ref.captures( + &layer.config.query, + layer.tree().root_node(), + RopeProvider(source), + ); // If there's no captures, skip the layer - captures.peek()?; + captures.advance(); + captures.get()?; Some(HighlightIterLayer { highlight_end_stack: Vec::new(), @@ -1740,7 +1740,7 @@ pub(crate) fn generate_edits( } use std::sync::atomic::{AtomicUsize, Ordering}; -use std::{iter, mem, ops, str}; +use std::{mem, ops, str}; use tree_sitter::{ Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError, QueryMatch, Range, TextProvider, Tree, @@ -1842,7 +1842,7 @@ impl<'a> TextProvider<&'a [u8]> for RopeProvider<'a> { struct HighlightIterLayer<'a> { _tree: Option, cursor: QueryCursor, - captures: RefCell, &'a [u8]>>>, + captures: RefCell, &'a [u8]>>, config: &'a HighlightConfiguration, highlight_end_stack: Vec, scope_stack: Vec>, @@ -2115,7 +2115,7 @@ impl<'a> HighlightIterLayer<'a> { let next_start = self .captures .borrow_mut() - .peek() + .get() .map(|(m, i)| m.captures[*i].node.start_byte()); let next_end = self.highlight_end_stack.last().cloned(); match (next_start, next_end) { @@ -2340,7 +2340,7 @@ impl<'a> Iterator for HighlightIter<'a> { let range; let layer = &mut self.layers[0]; let captures = layer.captures.get_mut(); - if let Some((next_match, capture_index)) = captures.peek() { + if let Some((next_match, capture_index)) = captures.get() { let next_capture = next_match.captures[*capture_index]; range = next_capture.node.byte_range(); @@ -2363,7 +2363,7 @@ impl<'a> Iterator for HighlightIter<'a> { return self.emit_event(self.source.len_bytes(), None); }; - let (mut match_, capture_index) = captures.next().unwrap(); + let (mut match_, capture_index) = captures.get().map(|m| (&m.0, m.1)).unwrap(); let mut capture = match_.captures[capture_index]; // Remove from the local scope stack any local scopes that have already ended. @@ -2439,11 +2439,11 @@ impl<'a> Iterator for HighlightIter<'a> { } // Continue processing any additional matches for the same node. - if let Some((next_match, next_capture_index)) = captures.peek() { + if let Some((next_match, next_capture_index)) = captures.get() { let next_capture = next_match.captures[*next_capture_index]; if next_capture.node == capture.node { capture = next_capture; - match_ = captures.next().unwrap().0; + match_ = &captures.next().unwrap().0; continue; } } @@ -2467,11 +2467,11 @@ impl<'a> Iterator for HighlightIter<'a> { if definition_highlight.is_some() || reference_highlight.is_some() { while layer.config.non_local_variable_patterns[match_.pattern_index] { match_.remove(); - if let Some((next_match, next_capture_index)) = captures.peek() { + if let Some((next_match, next_capture_index)) = captures.get() { let next_capture = next_match.captures[*next_capture_index]; if next_capture.node == capture.node { capture = next_capture; - match_ = captures.next().unwrap().0; + match_ = &captures.next().unwrap().0; continue; } } @@ -2486,10 +2486,10 @@ impl<'a> Iterator for HighlightIter<'a> { // for a given node are ordered by pattern index, so these subsequent // captures are guaranteed to be for highlighting, not injections or // local variables. - while let Some((next_match, next_capture_index)) = captures.peek() { + while let Some((next_match, next_capture_index)) = captures.get() { let next_capture = next_match.captures[*next_capture_index]; if next_capture.node == capture.node { - captures.next(); + captures.advance(); } else { break; } @@ -2763,18 +2763,12 @@ mod test { let root = syntax.tree().root_node(); let mut test = |capture, range| { - let matches: Vec<_> = textobject + let captures = textobject .capture_nodes(capture, root, source.slice(..), &mut cursor) - .unwrap() - .collect(); - - assert_eq!( - matches[0].byte_range(), - range, - "@{} expected {:?}", - capture, - range - ) + .unwrap(); + let matches: Vec<_> = captures.map_deref(|c| c.byte_range()).collect(); + + assert_eq!(matches[0], range, "@{} expected {:?}", capture, range) }; test("quantified_nodes", 1..37); diff --git a/helix-core/src/textobject.rs b/helix-core/src/textobject.rs index 7576b3a78..fee0a14b4 100644 --- a/helix-core/src/textobject.rs +++ b/helix-core/src/textobject.rs @@ -1,6 +1,7 @@ use std::fmt::Display; use ropey::RopeSlice; +use streaming_iterator::StreamingIterator; use tree_sitter::{Node, QueryCursor}; use crate::chars::{categorize_char, char_is_whitespace, CharCategory}; @@ -273,11 +274,12 @@ pub fn textobject_treesitter( .textobject_query()? .capture_nodes(&capture_name, slice_tree, slice, &mut cursor)? .filter(|node| node.byte_range().contains(&byte_pos)) - .min_by_key(|node| node.byte_range().len())?; + .map_deref(|n| n.byte_range()) + .min_by_key(|node_range| node_range.len())?; let len = slice.len_bytes(); - let start_byte = node.start_byte(); - let end_byte = node.end_byte(); + let start_byte = node.start; + let end_byte = node.end; if start_byte >= len || end_byte >= len { return None; } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7c7cb7f41..673fd95d7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.74.0" +channel = "1.74.1" components = ["rustfmt", "rust-src", "clippy"]