Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Add additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Jun 29, 2022
1 parent 704925e commit 5f66f71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions crates/rome_analyze/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ where
{
type Language = NodeLanguage<N>;

/// Match on [QueryMatch::Syntax] if the kind of the syntax node matches
/// the kind set of `N`
const KEY: QueryKey<Self::Language> = QueryKey::Syntax(N::KIND_SET);

fn unwrap_match(query: &QueryMatch<Self::Language>) -> Self {
Expand Down
14 changes: 7 additions & 7 deletions crates/rome_analyze/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use crate::{
pub struct RuleRegistry<'a, L: Language, B> {
/// Holds a collection of rules for each [SyntaxKind] node type that has
/// lint rules associated with it
syntax: Vec<SyntaxKindRules<L, B>>,
ast_rules: Vec<SyntaxKindRules<L, B>>,
emit_signal: Box<dyn FnMut(&dyn AnalyzerSignal<L>) -> ControlFlow<B> + 'a>,
}

impl<'a, L: Language, B> RuleRegistry<'a, L, B> {
pub fn new(emit_signal: impl FnMut(&dyn AnalyzerSignal<L>) -> ControlFlow<B> + 'a) -> Self {
Self {
syntax: Vec::new(),
ast_rules: Vec::new(),
emit_signal: Box::new(emit_signal),
}
}
Expand All @@ -43,13 +43,13 @@ impl<'a, L: Language, B> RuleRegistry<'a, L, B> {

// Ensure the vector has enough capacity by inserting empty
// `SyntaxKindRules` as required
if self.syntax.len() <= index {
self.syntax.resize_with(index + 1, SyntaxKindRules::new);
if self.ast_rules.len() <= index {
self.ast_rules.resize_with(index + 1, SyntaxKindRules::new);
}

// Insert a handle to the rule `R` into the `SyntaxKindRules` entry
// corresponding to the SyntaxKind index
let node = &mut self.syntax[index];
let node = &mut self.ast_rules[index];
node.rules.push(RegistryRule::of::<R>());
}
}
Expand All @@ -60,7 +60,7 @@ impl<'a, L: Language, B> RuleRegistry<'a, L, B> {
/// in this instance of the registry
pub fn metadata(self) -> impl Iterator<Item = (&'static str, &'static str)> {
let mut unique = HashSet::new();
self.syntax
self.ast_rules
.into_iter()
.flat_map(|node| node.rules)
.map(|rule| (rule.name, rule.docs))
Expand Down Expand Up @@ -105,7 +105,7 @@ where
let kind = usize::from(kind);

// Lookup the syntax entry corresponding to the SyntaxKind index
match self.syntax.get(kind) {
match self.ast_rules.get(kind) {
Some(entry) => &entry.rules,
None => return ControlFlow::Continue(()),
}
Expand Down
3 changes: 3 additions & 0 deletions crates/rome_analyze/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ where
}
}

// TODO: Checking for suppression comments is currently incomplete,
// it can only completely suppress linting and has a high performance
// cost due to eagerly looking up the first token of each node
if (self.has_suppressions)(node) {
self.skip_subtree = Some(node.clone());
return ControlFlow::Continue(());
Expand Down

0 comments on commit 5f66f71

Please sign in to comment.