Skip to content

Commit

Permalink
Bump Tree-sitter for bug fixes affecting YAML parser loaded via WASM (#…
Browse files Browse the repository at this point in the history
…25054)

Closes #24742
Closes #24632

This PR bumps Tree-sitter to bring in bug fixes:
* tree-sitter/tree-sitter#4218
* tree-sitter/tree-sitter#4213
* tree-sitter/tree-sitter#4210

I've also bumped Wasmtime and wit-bindgen, since the new Tree-sitter
uses a newer wasmtime.

Release Notes:

- Fixed a parsing bug that caused memory leaks and crashes when using
the Ansible extension

---------

Co-authored-by: Anthony <[email protected]>
Co-authored-by: Anthony Eid <[email protected]>
  • Loading branch information
3 people authored Feb 18, 2025
1 parent 8942e65 commit 813d870
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 208 deletions.
365 changes: 202 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ tiny_http = "0.8"
toml = "0.8"
tokio = { version = "1" }
tower-http = "0.4.4"
tree-sitter = { version = "0.24", features = ["wasm"] }
tree-sitter = { version = "0.25.2", features = ["wasm"] }
tree-sitter-bash = "0.23"
tree-sitter-c = "0.23"
tree-sitter-cpp = "0.23"
Expand All @@ -539,7 +539,7 @@ tree-sitter-go-mod = { git = "https://github.com/camdencheek/tree-sitter-go-mod"
tree-sitter-gowork = { git = "https://github.com/zed-industries/tree-sitter-go-work", rev = "acb0617bf7f4fda02c6217676cc64acb89536dc7" }
tree-sitter-heex = { git = "https://github.com/zed-industries/tree-sitter-heex", rev = "1dd45142fbb05562e35b2040c6129c9bca346592" }
tree-sitter-diff = "0.1.0"
tree-sitter-html = "0.20"
tree-sitter-html = "0.23"
tree-sitter-jsdoc = "0.23"
tree-sitter-json = "0.24"
tree-sitter-md = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "9a23c1a96c0513d8fc6520972beedd419a973539" }
Expand All @@ -555,18 +555,18 @@ unicode-segmentation = "1.10"
unicode-script = "0.5.7"
url = "2.2"
uuid = { version = "1.1.2", features = ["v4", "v5", "v7", "serde"] }
wasmparser = "0.217"
wasm-encoder = "0.217"
wasmtime = { version = "25", default-features = false, features = [
wasmparser = "0.221"
wasm-encoder = "0.221"
wasmtime = { version = "29", default-features = false, features = [
"async",
"demangle",
"runtime",
"cranelift",
"component-model",
] }
wasmtime-wasi = "25"
wasmtime-wasi = "29"
which = "6.0.0"
wit-component = "0.201"
wit-component = "0.221"
zed_llm_client = "0.4"
zstd = "0.11"
metal = "0.31"
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6283,7 +6283,7 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
autoclose_before: "})]>".into(),
..Default::default()
},
Some(tree_sitter_html::language()),
Some(tree_sitter_html::LANGUAGE.into()),
)
.with_injection_query(
r#"
Expand Down Expand Up @@ -9685,7 +9685,7 @@ async fn test_toggle_block_comment(cx: &mut gpui::TestAppContext) {
block_comment: Some(("<!-- ".into(), " -->".into())),
..Default::default()
},
Some(tree_sitter_html::language()),
Some(tree_sitter_html::LANGUAGE.into()),
)
.with_injection_query(
r#"
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/test/editor_lsp_test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl EditorLspTestContext {
word_characters: ['-'].into_iter().collect(),
..Default::default()
},
Some(tree_sitter_html::language()),
Some(tree_sitter_html::LANGUAGE.into()),
)
.with_queries(LanguageQueries {
brackets: Some(Cow::from(indoc! {r#"
Expand Down
2 changes: 1 addition & 1 deletion crates/extension/src/extension_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl ExtensionBuilder {
let wasm_bytes = fs::read(&wasm_path)
.with_context(|| format!("failed to read output module `{}`", wasm_path.display()))?;

let encoder = ComponentEncoder::default()
let mut encoder = ComponentEncoder::default()
.module(&wasm_bytes)?
.adapter("wasi_snapshot_preview1", &adapter_bytes)
.context("failed to load adapter module")?
Expand Down
3 changes: 0 additions & 3 deletions crates/extension_host/src/wasm_host/wit/since_v0_0_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::latest;
use crate::wasm_host::wit::since_v0_0_4;
use crate::wasm_host::WasmState;
use anyhow::Result;
use async_trait::async_trait;
use extension::{ExtensionLanguageServerProxy, WorktreeDelegate};
use language::LanguageServerBinaryStatus;
use semantic_version::SemanticVersion;
Expand Down Expand Up @@ -59,7 +58,6 @@ impl From<Command> for latest::Command {
}
}

#[async_trait]
impl HostWorktree for WasmState {
async fn read_text_file(
&mut self,
Expand Down Expand Up @@ -89,7 +87,6 @@ impl HostWorktree for WasmState {
}
}

#[async_trait]
impl ExtensionImports for WasmState {
async fn node_binary_path(&mut self) -> wasmtime::Result<Result<String, String>> {
latest::nodejs::Host::node_binary_path(self).await
Expand Down
3 changes: 0 additions & 3 deletions crates/extension_host/src/wasm_host/wit/since_v0_0_4.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::latest;
use crate::wasm_host::WasmState;
use anyhow::Result;
use async_trait::async_trait;
use extension::WorktreeDelegate;
use semantic_version::SemanticVersion;
use std::sync::{Arc, OnceLock};
Expand Down Expand Up @@ -67,7 +66,6 @@ impl From<Command> for latest::Command {
}
}

#[async_trait]
impl HostWorktree for WasmState {
async fn read_text_file(
&mut self,
Expand Down Expand Up @@ -98,7 +96,6 @@ impl HostWorktree for WasmState {
}
}

#[async_trait]
impl ExtensionImports for WasmState {
async fn node_binary_path(&mut self) -> wasmtime::Result<Result<String, String>> {
latest::nodejs::Host::node_binary_path(self).await
Expand Down
3 changes: 0 additions & 3 deletions crates/extension_host/src/wasm_host/wit/since_v0_0_6.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::{latest, since_v0_1_0};
use crate::wasm_host::WasmState;
use anyhow::Result;
use async_trait::async_trait;
use extension::WorktreeDelegate;
use semantic_version::SemanticVersion;
use std::sync::{Arc, OnceLock};
Expand Down Expand Up @@ -111,7 +110,6 @@ impl From<CodeLabel> for latest::CodeLabel {
}
}

#[async_trait]
impl HostWorktree for WasmState {
async fn id(&mut self, delegate: Resource<Arc<dyn WorktreeDelegate>>) -> wasmtime::Result<u64> {
latest::HostWorktree::id(self, delegate).await
Expand Down Expand Up @@ -153,7 +151,6 @@ impl HostWorktree for WasmState {
}
}

#[async_trait]
impl ExtensionImports for WasmState {
async fn get_settings(
&mut self,
Expand Down
8 changes: 0 additions & 8 deletions crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ::settings::{Settings, WorktreeId};
use anyhow::{anyhow, bail, Context, Result};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use async_trait::async_trait;
use extension::{ExtensionLanguageServerProxy, KeyValueStoreDelegate, WorktreeDelegate};
use futures::{io::BufReader, FutureExt as _};
use futures::{lock::Mutex, AsyncReadExt};
Expand Down Expand Up @@ -228,7 +227,6 @@ impl From<latest::lsp::SymbolKind> for lsp::SymbolKind {
}
}

#[async_trait]
impl HostKeyValueStore for WasmState {
async fn insert(
&mut self,
Expand All @@ -246,7 +244,6 @@ impl HostKeyValueStore for WasmState {
}
}

#[async_trait]
impl HostWorktree for WasmState {
async fn id(&mut self, delegate: Resource<Arc<dyn WorktreeDelegate>>) -> wasmtime::Result<u64> {
latest::HostWorktree::id(self, delegate).await
Expand Down Expand Up @@ -288,10 +285,8 @@ impl HostWorktree for WasmState {
}
}

#[async_trait]
impl common::Host for WasmState {}

#[async_trait]
impl http_client::Host for WasmState {
async fn fetch(
&mut self,
Expand Down Expand Up @@ -328,7 +323,6 @@ impl http_client::Host for WasmState {
}
}

#[async_trait]
impl http_client::HostHttpResponseStream for WasmState {
async fn next_chunk(
&mut self,
Expand Down Expand Up @@ -415,10 +409,8 @@ async fn convert_response(
Ok(extension_response)
}

#[async_trait]
impl lsp::Host for WasmState {}

#[async_trait]
impl ExtensionImports for WasmState {
async fn get_settings(
&mut self,
Expand Down
10 changes: 0 additions & 10 deletions crates/extension_host/src/wasm_host/wit/since_v0_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ impl From<SlashCommandArgumentCompletion> for extension::SlashCommandArgumentCom
}
}

#[async_trait]
impl HostKeyValueStore for WasmState {
async fn insert(
&mut self,
Expand All @@ -265,7 +264,6 @@ impl HostKeyValueStore for WasmState {
}
}

#[async_trait]
impl HostProject for WasmState {
async fn worktree_ids(
&mut self,
Expand All @@ -281,7 +279,6 @@ impl HostProject for WasmState {
}
}

#[async_trait]
impl HostWorktree for WasmState {
async fn id(&mut self, delegate: Resource<Arc<dyn WorktreeDelegate>>) -> wasmtime::Result<u64> {
let delegate = self.table.get(&delegate)?;
Expand Down Expand Up @@ -331,10 +328,8 @@ impl HostWorktree for WasmState {
}
}

#[async_trait]
impl common::Host for WasmState {}

#[async_trait]
impl http_client::Host for WasmState {
async fn fetch(
&mut self,
Expand Down Expand Up @@ -371,7 +366,6 @@ impl http_client::Host for WasmState {
}
}

#[async_trait]
impl http_client::HostHttpResponseStream for WasmState {
async fn next_chunk(
&mut self,
Expand Down Expand Up @@ -458,7 +452,6 @@ async fn convert_response(
Ok(extension_response)
}

#[async_trait]
impl nodejs::Host for WasmState {
async fn node_binary_path(&mut self) -> wasmtime::Result<Result<String, String>> {
self.host
Expand Down Expand Up @@ -525,7 +518,6 @@ impl From<::http_client::github::GithubReleaseAsset> for github::GithubReleaseAs
}
}

#[async_trait]
impl github::Host for WasmState {
async fn latest_github_release(
&mut self,
Expand Down Expand Up @@ -565,7 +557,6 @@ impl github::Host for WasmState {
}
}

#[async_trait]
impl platform::Host for WasmState {
async fn current_platform(&mut self) -> Result<(platform::Os, platform::Architecture)> {
Ok((
Expand All @@ -588,7 +579,6 @@ impl platform::Host for WasmState {
#[async_trait]
impl slash_command::Host for WasmState {}

#[async_trait]
impl ExtensionImports for WasmState {
async fn get_settings(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion crates/language/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,7 @@ impl BufferSnapshot {

let mut error_ranges = Vec::<Range<Point>>::new();
let mut matches = self.syntax.matches(range.clone(), &self.text, |grammar| {
Some(&grammar.error_query)
grammar.error_query.as_ref()
});
while let Some(mat) = matches.peek() {
let node = mat.captures[0].node;
Expand Down
2 changes: 1 addition & 1 deletion crates/language/src/buffer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3149,7 +3149,7 @@ fn html_lang() -> Language {
block_comment: Some(("<!--".into(), "-->".into())),
..Default::default()
},
Some(tree_sitter_html::language()),
Some(tree_sitter_html::LANGUAGE.into()),
)
.with_indents_query(
"
Expand Down
7 changes: 4 additions & 3 deletions crates/language/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ impl GrammarId {
pub struct Grammar {
id: GrammarId,
pub ts_language: tree_sitter::Language,
pub(crate) error_query: Query,
pub(crate) error_query: Option<Query>,
pub(crate) highlights_query: Option<Query>,
pub(crate) brackets_config: Option<BracketConfig>,
pub(crate) redactions_config: Option<RedactionConfig>,
Expand Down Expand Up @@ -1070,7 +1070,7 @@ impl Language {
override_config: None,
redactions_config: None,
runnable_config: None,
error_query: Query::new(&ts_language, "(ERROR) @error").unwrap(),
error_query: Query::new(&ts_language, "(ERROR) @error").ok(),
ts_language,
highlight_map: Default::default(),
})
Expand Down Expand Up @@ -1723,12 +1723,13 @@ impl Grammar {
.expect("incompatible grammar");
let mut chunks = text.chunks_in_range(0..text.len());
parser
.parse_with(
.parse_with_options(
&mut move |offset, _| {
chunks.seek(offset);
chunks.next().unwrap_or("").as_bytes()
},
old_tree.as_ref(),
None,
)
.unwrap()
})
Expand Down
3 changes: 2 additions & 1 deletion crates/language/src/syntax_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,13 @@ fn parse_text(
parser.set_included_ranges(&ranges)?;
parser.set_language(&grammar.ts_language)?;
parser
.parse_with(
.parse_with_options(
&mut move |offset, _| {
chunks.seek(start_byte + offset);
chunks.next().unwrap_or("").as_bytes()
},
old_tree.as_ref(),
None,
)
.ok_or_else(|| anyhow::anyhow!("failed to parse"))
})
Expand Down
2 changes: 1 addition & 1 deletion crates/language/src/syntax_map/syntax_map_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ fn html_lang() -> Language {
},
..Default::default()
},
Some(tree_sitter_html::language()),
Some(tree_sitter_html::LANGUAGE.into()),
)
.with_highlights_query(
r#"
Expand Down

0 comments on commit 813d870

Please sign in to comment.