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

Revert "chore: move binding_is_suppressed() onto Binding (#104)" #140

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion crates/core/src/pattern/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::ops::Range as StdRange;
use super::compiler::MATCH_VAR;
use super::FileOwner;
use crate::intervals::{earliest_deadline_sort, get_top_level_intervals_in_range, Interval};
use crate::suppress::is_binding_suppressed;
use anyhow::{anyhow, Result};
use anyhow::{bail, Ok};
use im::{vector, Vector};
Expand Down Expand Up @@ -245,7 +246,7 @@ impl<'a> State<'a> {
if let ResolvedPattern::Binding(bindings) = value {
for binding in bindings.iter() {
bindings_count += 1;
if binding.is_suppressed(lang, current_name) {
if is_binding_suppressed(binding, lang, current_name) {
suppressed_count += 1;
continue;
}
Expand Down
52 changes: 27 additions & 25 deletions crates/core/src/suppress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,37 @@ use tree_sitter::{Node, Range};

use crate::binding::Binding;

impl<'a> Binding<'a> {
pub(crate) fn is_suppressed(&self, lang: &impl Language, current_name: Option<&str>) -> bool {
let (src, node) = match self {
Self::Node(src, node) | Self::List(src, node, _) | Self::Empty(src, node, _) => {
(src, node)
pub(crate) fn is_binding_suppressed(
binding: &Binding,
lang: &impl Language,
current_name: Option<&str>,
) -> bool {
let (src, node) = match binding {
Binding::Node(src, node) | Binding::List(src, node, _) | Binding::Empty(src, node, _) => {
(src, node)
}
Binding::String(_, _) | Binding::FileName(_) | Binding::ConstantRef(_) => return false,
};
let target_range = node.range();
for n in
node.children(&mut node.walk())
.chain(ParentTraverse::new(TreeSitterParentCursor::new(
node.clone(),
)))
{
let mut cursor = n.walk();
let children = n.children(&mut cursor);
for c in children {
if !(lang.is_comment(c.kind_id()) || lang.is_comment_wrapper(&c)) {
continue;
}
Self::String(_, _) | Self::FileName(_) | Self::ConstantRef(_) => return false,
};
let target_range = node.range();
for n in
node.children(&mut node.walk())
.chain(ParentTraverse::new(TreeSitterParentCursor::new(
node.clone(),
)))
{
let mut cursor = n.walk();
let children = n.children(&mut cursor);
for c in children {
if !(lang.is_comment(c.kind_id()) || lang.is_comment_wrapper(&c)) {
continue;
}
if is_suppress_comment(&c, src, &target_range, current_name, lang) {
return true;
}
if is_suppress_comment(&c, src, &target_range, current_name, lang) {
return true;
}
}

false
}

false
}

fn is_suppress_comment(
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/text_unparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binding::{linearize_binding, Binding};
use crate::pattern::resolved_pattern::CodeRange;
use crate::pattern::state::FileRegistry;
use crate::pattern::Effect;
use crate::suppress::is_binding_suppressed;
use anyhow::Result;
use im::Vector;
use marzano_language::target_language::TargetLanguage;
Expand Down Expand Up @@ -29,7 +30,7 @@ pub(crate) fn apply_effects<'a>(
) -> Result<(String, Option<Vec<Range<usize>>>)> {
let effects: Vec<_> = effects
.into_iter()
.filter(|effect| !effect.binding.is_suppressed(language, current_name))
.filter(|effect| !is_binding_suppressed(&effect.binding, language, current_name))
.collect();
if effects.is_empty() {
return Ok((code.to_string(), None));
Expand Down
Loading