Skip to content
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

Trigger CI on PR, as well as push #797

Merged
merged 11 commits into from
Dec 2, 2024
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
on: push
on:
- push
- pull_request

Xophmeister marked this conversation as resolved.
Show resolved Hide resolved
jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion topiary-core/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use topiary_core::{formatter, Language, Operation, TopiaryQuery};
async fn format() {
let input = fs::read_to_string("../topiary-cli/tests/samples/input/ocaml.ml").unwrap();
let query_content = fs::read_to_string("../topiary-queries/queries/ocaml.scm").unwrap();
let ocaml = tree_sitter_ocaml::language_ocaml();
let ocaml = tree_sitter_ocaml::LANGUAGE_OCAML;

let mut input = input.as_bytes();
let mut output = io::BufWriter::new(Vec::new());
Expand Down
15 changes: 11 additions & 4 deletions topiary-core/src/tree_sitter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{collections::HashSet, fmt::Display};

use serde::Serialize;
use streaming_iterator::StreamingIterator;
use topiary_tree_sitter_facade::{
Node, Parser, Point, Query, QueryCapture, QueryCursor, QueryMatch, QueryPredicate, Tree,
Node, Parser, Point, Query, QueryCapture, QueryCursor, QueryPredicate, Tree,
};

use crate::{
Expand All @@ -12,6 +11,12 @@ use crate::{
FormatterResult,
};

#[cfg(not(target_arch = "wasm32"))]
use streaming_iterator::StreamingIterator;

#[cfg(not(target_arch = "wasm32"))]
use topiary_tree_sitter_facade::QueryMatch;

Xophmeister marked this conversation as resolved.
Show resolved Hide resolved
/// Supported visualisation formats
#[derive(Clone, Copy, Debug)]
pub enum Visualisation {
Expand Down Expand Up @@ -159,6 +164,7 @@ impl<'a> NodeExt for Node<'a> {
}
}

#[cfg(not(target_arch = "wasm32"))]
impl<'a> NodeExt for tree_sitter::Node<'a> {
fn display_one_based(&self) -> String {
format!(
Expand Down Expand Up @@ -236,6 +242,7 @@ pub fn apply_query(
let capture_names = query.query.capture_names();

let mut query_matches = query.query.matches(&root, source, &mut cursor);
#[allow(clippy::while_let_on_iterator)] // This is not a normal iterator
while let Some(query_match) = query_matches.next() {
let local_captures: Vec<QueryCapture> = query_match.captures().collect();

Expand Down Expand Up @@ -284,8 +291,8 @@ pub fn apply_query(
if log::log_enabled!(log::Level::Info) {
#[cfg(target_arch = "wasm32")]
// Resize the pattern_positions vector if we need to store more positions
if m.pattern_index as usize >= pattern_positions.len() {
pattern_positions.resize(m.pattern_index as usize + 1, None);
if m.pattern_index >= pattern_positions.len() {
pattern_positions.resize(m.pattern_index + 1, None);
}

// Fetch from pattern_positions, otherwise insert
Expand Down
2 changes: 1 addition & 1 deletion topiary-tree-sitter-facade/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod wasm {
}

#[inline]
pub fn general_predicates(&self, index: u32) -> Vec<QueryPredicate> {
pub fn general_predicates(&self, index: usize) -> Vec<QueryPredicate> {
let predicates: Vec<_> = self
.inner
.predicates_for_pattern(index)
Expand Down
6 changes: 4 additions & 2 deletions topiary-tree-sitter-facade/src/query_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use native::*;
#[cfg(target_arch = "wasm32")]
mod wasm {
use crate::query_capture::QueryCapture;
use std::convert::TryInto;
use wasm_bindgen::JsCast;

#[derive(Clone)]
Expand All @@ -38,8 +39,9 @@ mod wasm {

impl<'tree> QueryMatch<'tree> {
#[inline]
pub fn pattern_index(&self) -> u32 {
self.inner.pattern()
pub fn pattern_index(&self) -> usize {
// On WASM32, usize is the same as u32, so the unwrap is safe
self.inner.pattern().try_into().unwrap()
Xophmeister marked this conversation as resolved.
Show resolved Hide resolved
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion topiary-web-tree-sitter-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ extern "C" {

// -> PredicateResult[]
#[wasm_bindgen(method, js_name = predicatesForPattern)]
pub fn predicates_for_pattern(this: &Query, pattern_index: u32) -> Box<[JsValue]>;
pub fn predicates_for_pattern(this: &Query, pattern_index: usize) -> Box<[JsValue]>;
}

#[wasm_bindgen]
Expand Down
Loading