Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | Cargo.lock | 25 | ||||
| -rw-r--r-- | helix-core/Cargo.toml | 2 | ||||
| -rw-r--r-- | helix-core/src/snippets.rs | 2 | ||||
| -rw-r--r-- | helix-core/src/syntax.rs | 43 | ||||
| -rw-r--r-- | helix-lsp-types/src/completion.rs | 2 | ||||
| -rw-r--r-- | helix-lsp-types/src/lib.rs | 10 | ||||
| -rw-r--r-- | helix-term/Cargo.toml | 1 | ||||
| -rw-r--r-- | rust-toolchain.toml | 3 |
8 files changed, 79 insertions, 9 deletions
@@ -269,6 +269,12 @@ dependencies = [ ] [[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1542,6 +1548,7 @@ dependencies = [ "tokio", "tokio-stream", "toml", + "tree-house", "url", ] @@ -2178,6 +2185,16 @@ dependencies = [ ] [[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + +[[package]] name = "proc-macro2" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2912,11 +2929,13 @@ dependencies = [ "hashbrown 0.15.5", "kstring", "once_cell", + "pretty_assertions", "regex", "regex-cursor", "ropey", "slab", "tree-house-bindings", + "unicode-width 0.1.12", ] [[package]] @@ -3382,6 +3401,12 @@ dependencies = [ ] [[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + +[[package]] name = "yoke" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index e7e79ea4..4309cc14 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -32,7 +32,7 @@ unicode-segmentation.workspace = true unicode-width = "=0.1.12" unicode-general-category = "1.1" slotmap.workspace = true -tree-house.workspace = true +tree-house = { workspace = true, features = ["fixtures"] } once_cell = "1.21" arc-swap = "1" regex = "1" diff --git a/helix-core/src/snippets.rs b/helix-core/src/snippets.rs index 3dd3b9c3..477c9e75 100644 --- a/helix-core/src/snippets.rs +++ b/helix-core/src/snippets.rs @@ -1,6 +1,6 @@ mod active; mod elaborate; -mod parser; +pub mod parser; mod render; #[derive(PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Clone, Copy)] diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 325c47ac..4bc177ef 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -90,7 +90,7 @@ impl LanguageData { Ok(Some(config)) } - fn syntax_config(&self, loader: &Loader) -> Option<&SyntaxConfig> { + pub fn syntax_config(&self, loader: &Loader) -> Option<&SyntaxConfig> { self.syntax .get_or_init(|| { Self::compile_syntax_config(&self.config, loader) @@ -238,7 +238,7 @@ impl LanguageData { } } -fn reconfigure_highlights(config: &SyntaxConfig, recognized_names: &[String]) { +pub fn reconfigure_highlights(config: &SyntaxConfig, recognized_names: &[String]) { config.configure(move |capture_name| { let capture_parts: Vec<_> = capture_name.split('.').collect(); @@ -512,7 +512,7 @@ impl FileTypeGlobMatcher { #[derive(Debug)] pub struct Syntax { - inner: tree_house::Syntax, + pub inner: tree_house::Syntax, } const PARSE_TIMEOUT: Duration = Duration::from_millis(500); // half a second is pretty generous @@ -1203,7 +1203,24 @@ mod test { ); let language = LOADER.language_for_name("rust").unwrap(); + dbg!(language); let grammar = LOADER.get_config(language).unwrap().grammar; + dbg!(grammar); + let syntax = Syntax::new(source.slice(..), language, &LOADER).unwrap(); + let mut h = syntax.highlighter( + "fn main() { 4 + 2; }".into(), + &LOADER, + 0.."fn main() { 4 + 2; }".len() as u32, + ); + + for n in 0..5 { + dbg!(h.active_highlights().collect::<Vec<_>>()); + dbg!(h.next_event_offset()); + let (e, h) = h.advance(); + dbg!(h.collect::<Vec<_>>(), e); + // panic!() + } + let query = Query::new(grammar, query_str, |_, _| Ok(())).unwrap(); let textobject = TextObjectQuery::new(query); let syntax = Syntax::new(source.slice(..), language, &LOADER).unwrap(); @@ -1368,4 +1385,24 @@ mod test { source.len(), ); } + #[test] + fn highlight() { + let source = Rope::from_str(r#"assert_eq!(0, Some(0));"#); + let loader = crate::config::default_lang_loader(); + loader.set_scopes(vec!["punctuation".to_string()]); + let language = loader.language_for_name("rust").unwrap(); + + let syntax = Syntax::new(source.slice(..), language, &loader).unwrap(); + println!( + "{}", + tree_house::fixtures::highlighter_fixture( + "", + &loader, + |_| "punct".to_string(), + &syntax.inner, + source.slice(..), + .., + ) + ); + } } diff --git a/helix-lsp-types/src/completion.rs b/helix-lsp-types/src/completion.rs index 7c006bdb..793252de 100644 --- a/helix-lsp-types/src/completion.rs +++ b/helix-lsp-types/src/completion.rs @@ -24,7 +24,7 @@ impl InsertTextFormat { /// The kind of a completion entry. #[derive(Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] #[serde(transparent)] -pub struct CompletionItemKind(i32); +pub struct CompletionItemKind(pub i32); lsp_enum! { impl CompletionItemKind { pub const TEXT: CompletionItemKind = CompletionItemKind(1); diff --git a/helix-lsp-types/src/lib.rs b/helix-lsp-types/src/lib.rs index fd668de5..fa912f56 100644 --- a/helix-lsp-types/src/lib.rs +++ b/helix-lsp-types/src/lib.rs @@ -210,6 +210,16 @@ pub enum NumberOrString { Number(i32), String(String), } +impl From<i32> for NumberOrString { + fn from(v: i32) -> Self { + Self::Number(v) + } +} +impl From<&i32> for NumberOrString { + fn from(&v: &i32) -> Self { + Self::Number(v) + } +} /* ----------------- Cancel support ----------------- */ diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index a62b2e16..ab9f166b 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -92,6 +92,7 @@ serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } dashmap = "6.0" +tree-house = { workspace = true, features = ["fixtures"] } [target.'cfg(windows)'.dependencies] crossterm = { version = "0.28", features = ["event-stream"] } diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 74c6fc7a..00000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "1.82.0" -components = ["rustfmt", "rust-src", "clippy"] |