Bump Tree-sitter for bug fixes affecting YAML parser loaded via WASM (#25054)

Closes https://github.com/zed-industries/zed/issues/24742
Closes #24632

This PR bumps Tree-sitter to bring in bug fixes:
* https://github.com/tree-sitter/tree-sitter/pull/4218
* https://github.com/tree-sitter/tree-sitter/pull/4213
* https://github.com/tree-sitter/tree-sitter/pull/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 <anthony@zed.dev>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
This commit is contained in:
Max Brunsfeld 2025-02-17 21:29:27 -08:00 committed by GitHub
parent 8942e657aa
commit 813d870a03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 225 additions and 211 deletions

View file

@ -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#"
@ -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#"

View file

@ -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#"

View file

@ -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")?

View file

@ -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;
@ -59,7 +58,6 @@ impl From<Command> for latest::Command {
}
}
#[async_trait]
impl HostWorktree for WasmState {
async fn read_text_file(
&mut self,
@ -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

View file

@ -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};
@ -67,7 +66,6 @@ impl From<Command> for latest::Command {
}
}
#[async_trait]
impl HostWorktree for WasmState {
async fn read_text_file(
&mut self,
@ -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

View file

@ -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};
@ -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
@ -153,7 +151,6 @@ impl HostWorktree for WasmState {
}
}
#[async_trait]
impl ExtensionImports for WasmState {
async fn get_settings(
&mut self,

View file

@ -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};
@ -228,7 +227,6 @@ impl From<latest::lsp::SymbolKind> for lsp::SymbolKind {
}
}
#[async_trait]
impl HostKeyValueStore for WasmState {
async fn insert(
&mut self,
@ -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
@ -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,
@ -328,7 +323,6 @@ impl http_client::Host for WasmState {
}
}
#[async_trait]
impl http_client::HostHttpResponseStream for WasmState {
async fn next_chunk(
&mut self,
@ -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,

View file

@ -247,7 +247,6 @@ impl From<SlashCommandArgumentCompletion> for extension::SlashCommandArgumentCom
}
}
#[async_trait]
impl HostKeyValueStore for WasmState {
async fn insert(
&mut self,
@ -265,7 +264,6 @@ impl HostKeyValueStore for WasmState {
}
}
#[async_trait]
impl HostProject for WasmState {
async fn worktree_ids(
&mut self,
@ -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)?;
@ -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,
@ -371,7 +366,6 @@ impl http_client::Host for WasmState {
}
}
#[async_trait]
impl http_client::HostHttpResponseStream for WasmState {
async fn next_chunk(
&mut self,
@ -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
@ -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,
@ -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((
@ -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,

View file

@ -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;

View file

@ -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(
"

View file

@ -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>,
@ -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(),
})
@ -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()
})

View file

@ -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"))
})

View file

@ -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#"