Skip to content

Commit

Permalink
Trigger CI on PR, as well as push (#797)
Browse files Browse the repository at this point in the history
* Trigger CI on PR, as well as push

* Update benchmark to use new tree-sitter-ocaml API

* WASM: Fix usize/u32 discrepancy

* WASM: Don't import unnecessary modules

* WASM: Don't impl NodeExt for tree_sitter::Node

* Appease Clippy :P

* Comment unwrap of u32 to usize

* Trigger CI on PRs against main and pushes to main

* Allow dead code, rather than conditional compile, for imports

* Attempt 2 of ...: Allow dead code for the module, in WASM builds

* Attempt 3 of ...: Allow unused imports for the module, in WASM builds
  • Loading branch information
Xophmeister authored Dec 2, 2024
1 parent 7bda48e commit 932cb22
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: push
on:
push:
branches: main
pull_request:
branches: main

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
14 changes: 11 additions & 3 deletions topiary-core/src/tree_sitter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// WASM build doesn't use topiary_tree_sitter_facade::QueryMatch or
// streaming_iterator::StreamingIterator
#![cfg_attr(target_arch = "wasm32", allow(unused_imports))]

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,
};

use streaming_iterator::StreamingIterator;

use crate::{
atom_collection::{AtomCollection, QueryPredicates},
error::FormatterError,
Expand Down Expand Up @@ -159,6 +165,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 +243,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 +292,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()
}

#[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

0 comments on commit 932cb22

Please sign in to comment.