Skip to content

chore: Upgrade tree-sitter to 0.25.4 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resolver = "2"
lto = true

[workspace.package]
version = "0.25.3"
version = "0.25.4"
authors = ["Herrington Darkholme <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -20,6 +20,6 @@ readme = "README.md"


[workspace.dependencies]
web-tree-sitter-sg = { path = "crates/web-tree-sitter-sg", version = "0.25.3" }
tree-sitter = { version = "0.25.3" }
web-tree-sitter-sg = { path = "crates/web-tree-sitter-sg", version = "0.25.4" }
tree-sitter = { version = "0.25.4" }
tree-sitter-language = { version = "0.1" }
3 changes: 1 addition & 2 deletions crates/tree-sitter-facade/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ mod wasm {

#[inline]
pub fn set_language(&mut self, language: &Language) -> Result<(), LanguageError> {
let language = Some(&language.inner);
self.inner.set_language(language).map_err(Into::into)
self.inner.set_language(&language.inner).map_err(Into::into)
}

#[inline]
Expand Down
38 changes: 16 additions & 22 deletions crates/web-tree-sitter-sg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use core::cell::RefCell;
use js_sys::{Array, Error, Function, JsString, Object, Promise, Reflect, Uint8Array};
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen::{JsCast, prelude::*};
use wasm_bindgen_futures::JsFuture;

trait JsValueExt {
Expand Down Expand Up @@ -41,27 +41,27 @@ thread_local! {
pub struct TreeSitter;

impl TreeSitter {
pub async fn init() -> Result<(), JsError> {
pub async fn init(locate_file: Option<Function>) -> Result<(), JsError> {
#![allow(non_snake_case)]

// Exit early if `web-tree-sitter` is already initialized
if TREE_SITTER_INITIALIZED.with(|cell| *cell.borrow()) {
return Ok(());
}

JsFuture::from(Parser::init()).await.lift_error()?;
if let Some(locate_file) = locate_file {
let options = Object::new();
Reflect::set(&options, &"locateFile".into(), &locate_file.into()).unwrap();
JsFuture::from(Parser::init(Some(&options))).await.lift_error()?;
} else {
JsFuture::from(Parser::init(None)).await.lift_error()?;
}

// Set `web-tree-sitter` to initialized
TREE_SITTER_INITIALIZED.with(|cell| cell.replace(true));

Ok(())
}

fn init_guard() {
if !TREE_SITTER_INITIALIZED.with(|cell| *cell.borrow()) {
wasm_bindgen::throw_str("TreeSitter::init must be called to initialize the library");
}
}
}

#[wasm_bindgen]
Expand Down Expand Up @@ -154,7 +154,7 @@ extern {
fn delete(this: &LoggerParams, val: &JsString);
}

#[wasm_bindgen(module="web-tree-sitter")]
#[wasm_bindgen(module = "web-tree-sitter")]
extern {
#[derive(Clone, Debug, PartialEq)]
pub type Language;
Expand Down Expand Up @@ -204,15 +204,13 @@ extern {

impl Language {
pub async fn load_bytes(bytes: &Uint8Array) -> Result<Language, LanguageError> {
TreeSitter::init_guard();
JsFuture::from(Language::__load_bytes(bytes))
.await
.map(JsCast::unchecked_into)
.map_err(JsCast::unchecked_into)
}

pub async fn load_path(path: &str) -> Result<Language, LanguageError> {
TreeSitter::init_guard();
JsFuture::from(Language::__load_path(path))
.await
.map(JsCast::unchecked_into)
Expand Down Expand Up @@ -292,8 +290,7 @@ impl Default for Point {
}
}

impl Eq for Point {
}
impl Eq for Point {}

impl std::hash::Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -538,8 +535,7 @@ impl Default for Range {
}
}

impl Eq for Range {
}
impl Eq for Range {}

impl std::hash::Hash for Range {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -743,8 +739,7 @@ impl PartialEq<SyntaxNode> for SyntaxNode {
}
}

impl Eq for SyntaxNode {
}
impl Eq for SyntaxNode {}

impl std::hash::Hash for SyntaxNode {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -850,14 +845,14 @@ extern {
pub fn reset(this: &TreeCursor, node: &SyntaxNode);
}

#[wasm_bindgen(module="web-tree-sitter")]
#[wasm_bindgen(module = "web-tree-sitter")]
extern {
#[derive(Clone, Debug)]
pub type Parser;

// Static Methods
#[wasm_bindgen(static_method_of = Parser)]
pub fn init() -> Promise;
pub fn init(options: Option<&Object>) -> Promise;

// Constructor

Expand Down Expand Up @@ -897,15 +892,14 @@ extern {
pub fn reset(this: &Parser);

#[wasm_bindgen(catch, method, js_name = setLanguage)]
pub fn set_language(this: &Parser, language: Option<&Language>) -> Result<(), LanguageError>;
pub fn set_language(this: &Parser, language: &Language) -> Result<(), LanguageError>;

#[wasm_bindgen(method, js_name = setLogger)]
pub fn set_logger(this: &Parser, logger: Option<&Logger>);
}

impl Parser {
pub fn new() -> Result<Parser, ParserError> {
TreeSitter::init_guard();
let result = Parser::__new()?;
Ok(result)
}
Expand Down