Skip to content
Merged
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
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ description = "Tool to compute and export code metrics"
license = "MPL-2.0"

[dependencies]
aho-corasick = "^1.0"
aho-corasick = "^1.1"
crossbeam = { version = "^0.8", features = ["crossbeam-channel"] }
globset = "^0.4"
num = "^0.4"
num-derive = "^0.4"
num-derive = "^0.5"
num-format = "^0.4"
num-traits = "^0.2"
petgraph = "^0.8"
regex = "^1.7"
regex = "^1.13"
serde = { version = "^1.0", features = ["derive"] }
termcolor = "^1.2"
walkdir = "^2.3"
termcolor = "^1.4"
walkdir = "^2.5"

tree-sitter = "=0.26.5"
tree-sitter = "=0.27.2"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-sg = "0.4.1"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.25.0"
tree-sitter-python = "=0.25.0"
tree-sitter-rust = "=0.24.0"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.4" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.4" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.5" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.4" }
tree-sitter-rust = "=0.24.2"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.5" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.5" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.6" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.5" }

[dev-dependencies]
insta = { version = "1.46.1", features = ["yaml", "json", "redactions"] }
pretty_assertions = "^1.3"
insta = { version = "1.49.0", features = ["yaml", "json", "redactions"] }
pretty_assertions = "^1.4"

[profile.dev.package.insta]
opt-level = 3
Expand Down
16 changes: 8 additions & 8 deletions enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ authors = ["Calixte Denizet <cdenizet@mozilla.com>"]
edition = "2024"

[dependencies]
clap = { version = "^4.0", features = ["derive"] }
askama = "^0.15"
clap = { version = "^4.6", features = ["derive"] }
askama = "^0.16"

tree-sitter = "=0.26.5"
tree-sitter = "=0.27.2"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-sg = "0.4.1"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.25.0"
tree-sitter-python = "=0.25.0"
tree-sitter-rust = "=0.24.0"
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.4" }
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.4" }
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.5" }
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.4" }
tree-sitter-rust = "=0.24.2"
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.5" }
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.5" }
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.6" }
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.5" }

[profile.release]
strip = "debuginfo"
6 changes: 3 additions & 3 deletions rust-code-analysis-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ license = "MPL-2.0"
name = "rust-code-analysis-cli"

[dependencies]
clap = { version = "^4.0", features = ["derive"] }
clap = { version = "^4.6", features = ["derive"] }
globset = "^0.4"
indicatif = "^0.18"
regex = "^1.7"
regex = "^1.13"
rust-code-analysis = { path = "..", version = "=0.0.25" }
serde = "^1.0"
serde_cbor = "^0.11"
serde_json = "^1.0"
serde_yaml = "^0.9"
toml = "^0.9"
toml = "^1.2"
8 changes: 4 additions & 4 deletions rust-code-analysis-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ description = "Run a web service to compute and export code metrics"
license = "MPL-2.0"

[dependencies]
actix-rt = "^2.6"
actix-web = "^4.2"
clap = { version = "^4.0", features = ["derive"] }
actix-rt = "^2.16"
actix-web = "^4.20"
clap = { version = "^4.6", features = ["derive"] }
futures = "^0.3"
rust-code-analysis = { path = "..", version = "=0.0.25" }
serde = "^1.0"
serde_json = "^1.0"

[dev-dependencies]
pretty_assertions = "^1.3"
pretty_assertions = "^1.4"
58 changes: 50 additions & 8 deletions src/alterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ use crate::*;
/// thought to be sent on the network.
pub trait Alterator
where
Self: Checker,
Self: Checker + LanguageInfo,
{
/// Gets the kind of a node as a `'static` string.
///
/// Since tree-sitter 0.27, `Node::kind` returns a string bound to the
/// lifetime of the tree, so the kind is resolved through the generated
/// language enum instead.
fn get_kind(node: &Node) -> &'static str {
Self::BaseLang::from(node.kind_id()).into()
}

/// Creates a new `AST` node containing the code associated to the node,
/// its span, and its children.
///
Expand Down Expand Up @@ -38,7 +47,7 @@ where
/// its span, and its children.
fn get_default(node: &Node, code: &[u8], span: bool, children: Vec<AstNode>) -> AstNode {
let (text, span) = Self::get_text_span(node, code, span, node.child_count() == 0);
AstNode::new(node.kind(), text, span, children)
AstNode::new(Self::get_kind(node), text, span, children)
}

/// Gets a new `AST` node if and only if the code is not a comment,
Expand Down Expand Up @@ -67,7 +76,7 @@ impl Alterator for CppCode {
match Cpp::from(node.kind_id()) {
Cpp::StringLiteral | Cpp::CharLiteral => {
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
Cpp::PreprocDef | Cpp::PreprocFunctionDef | Cpp::PreprocCall => {
if let Some(last) = children.last()
Expand All @@ -94,7 +103,7 @@ impl Alterator for MozjsCode {
// TODO: have a thought about template_strings:
// they may have children for replacement...
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
_ => Self::get_default(node, code, span, children),
}
Expand All @@ -106,7 +115,7 @@ impl Alterator for JavascriptCode {
match Javascript::from(node.kind_id()) {
Javascript::String => {
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
_ => Self::get_default(node, code, span, children),
}
Expand All @@ -118,7 +127,7 @@ impl Alterator for TypescriptCode {
match Typescript::from(node.kind_id()) {
Typescript::String => {
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
_ => Self::get_default(node, code, span, children),
}
Expand All @@ -130,7 +139,7 @@ impl Alterator for TsxCode {
match Tsx::from(node.kind_id()) {
Tsx::String => {
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
_ => Self::get_default(node, code, span, children),
}
Expand All @@ -142,9 +151,42 @@ impl Alterator for RustCode {
match Rust::from(node.kind_id()) {
Rust::StringLiteral | Rust::CharLiteral => {
let (text, span) = Self::get_text_span(node, code, span, true);
AstNode::new(node.kind(), text, span, Vec::new())
AstNode::new(Self::get_kind(node), text, span, Vec::new())
}
_ => Self::get_default(node, code, span, children),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

// `Alterator::get_kind` relies on the generated language enums mapping
// every kind id to the same name tree-sitter reports.
fn check_kind_names<T: LanguageInfo>() {
let lang = T::get_lang().get_ts_language();
for id in (0..lang.node_kind_count() as u16).chain([u16::MAX]) {
let Some(expected) = lang.node_kind_for_id(id) else {
continue;
};
let got: &'static str = T::BaseLang::from(id).into();
assert_eq!(got, expected, "{} id={id}", T::get_lang_name());
}
}

#[test]
fn kind_names_match_tree_sitter() {
check_kind_names::<MozjsCode>();
check_kind_names::<JavascriptCode>();
check_kind_names::<JavaCode>();
check_kind_names::<KotlinCode>();
check_kind_names::<RustCode>();
check_kind_names::<CppCode>();
check_kind_names::<PythonCode>();
check_kind_names::<TsxCode>();
check_kind_names::<TypescriptCode>();
check_kind_names::<PreprocCode>();
check_kind_names::<CcommentCode>();
}
}
4 changes: 2 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn build<T: ParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNod
cursor.reset(ts_node);
if cursor.goto_first_child() {
let node = cursor.node();
child_stack.push(Vec::with_capacity(node.child_count()));
child_stack.push(Vec::with_capacity(node.child_count() as usize));
node_stack.push(node);
} else {
loop {
Expand All @@ -114,7 +114,7 @@ fn build<T: ParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNod
}
}
if let Some(next_node) = ts_node.next_sibling() {
child_stack.push(Vec::with_capacity(next_node.child_count()));
child_stack.push(Vec::with_capacity(next_node.child_count() as usize));
node_stack.push(next_node);
break;
}
Expand Down
40 changes: 20 additions & 20 deletions src/languages/language_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,25 @@ pub enum Rust {
Try = 126,
IntegerLiteral = 127,
DQUOTE = 128,
DQUOTE2 = 129,
CharLiteral = 130,
EscapeSequence = 131,
True = 132,
False = 133,
SLASHSLASH = 134,
LineCommentToken1 = 135,
LineCommentToken2 = 136,
LineCommentToken3 = 137,
BANG2 = 138,
SLASH2 = 139,
SLASHSTAR = 140,
STARSLASH = 141,
Shebang = 142,
Zelf = 143,
Super = 144,
Crate = 145,
Metavariable = 146,
StringContent = 147,
CharLiteral = 129,
EscapeSequence = 130,
True = 131,
False = 132,
SLASHSLASH = 133,
LineCommentToken1 = 134,
LineCommentToken2 = 135,
LineCommentToken3 = 136,
BANG2 = 137,
SLASH2 = 138,
SLASHSTAR = 139,
STARSLASH = 140,
Shebang = 141,
Zelf = 142,
Super = 143,
Crate = 144,
Metavariable = 145,
StringContent = 146,
DQUOTE2 = 147,
RawStringLiteralStart = 148,
StringContent2 = 149,
RawStringLiteralEnd = 150,
Expand Down Expand Up @@ -495,7 +495,6 @@ impl From<Rust> for &'static str {
Rust::Try => "try",
Rust::IntegerLiteral => "integer_literal",
Rust::DQUOTE => "\"",
Rust::DQUOTE2 => "\"",
Rust::CharLiteral => "char_literal",
Rust::EscapeSequence => "escape_sequence",
Rust::True => "true",
Expand All @@ -514,6 +513,7 @@ impl From<Rust> for &'static str {
Rust::Crate => "crate",
Rust::Metavariable => "metavariable",
Rust::StringContent => "string_content",
Rust::DQUOTE2 => "\"",
Rust::RawStringLiteralStart => "_raw_string_literal_start",
Rust::StringContent2 => "string_content",
Rust::RawStringLiteralEnd => "_raw_string_literal_end",
Expand Down
8 changes: 4 additions & 4 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> Node<'a> {
self.0.id()
}

pub(crate) fn kind(&self) -> &'static str {
pub(crate) fn kind(&self) -> &'a str {
self.0.kind()
}

Expand Down Expand Up @@ -185,16 +185,16 @@ impl<'a> Node<'a> {
.any(|child| child.kind_id() == id)
}

pub(crate) fn child_count(&self) -> usize {
pub(crate) fn child_count(&self) -> u32 {
self.0.child_count()
}

pub(crate) fn child_by_field_name(&self, name: &str) -> Option<Node<'a>> {
self.0.child_by_field_name(name).map(|node| self.wrap(node))
}

pub(crate) fn child(&self, pos: usize) -> Option<Node<'a>> {
self.0.child(pos as u32).map(|node| self.wrap(node))
pub(crate) fn child(&self, pos: u32) -> Option<Node<'a>> {
self.0.child(pos).map(|node| self.wrap(node))
}

pub(crate) fn children(&self) -> impl ExactSizeIterator<Item = Node<'a>> + use<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait Callback {
}

pub trait LanguageInfo {
type BaseLang;
type BaseLang: From<u16> + Into<&'static str>;

fn get_lang() -> LANG;
fn get_lang_name() -> &'static str;
Expand Down
8 changes: 4 additions & 4 deletions tree-sitter-ccomment/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-ccomment"
description = "Ccomment grammar for the tree-sitter parsing library"
version = "0.20.4"
version = "0.20.5"
authors = ["Calixte Denizet <cdenizet@mozilla.com>"]
license = "MIT"
readme = "bindings/rust/README.md"
Expand All @@ -21,10 +21,10 @@ include = [
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter-language="0.1.0"
tree-sitter-language="0.1.9"

[build-dependencies]
cc = "^1.0"
cc = "^1.11"

[dev-dependencies]
tree-sitter = "=0.26.5"
tree-sitter = "=0.27.2"
4 changes: 2 additions & 2 deletions tree-sitter-ccomment/bindings/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ way.)

``` toml
[dependencies]
tree-sitter = "0.26.5"
tree-sitter-ccomment = "0.20.4"
tree-sitter = "0.27.2"
tree-sitter-ccomment = "0.20.5"
```

Typically, you will use the [LANGUAGE][] function to add this
Expand Down
2 changes: 1 addition & 1 deletion tree-sitter-ccomment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"nan": "^2.14.2"
},
"devDependencies": {
"tree-sitter-cli": "^0.26.5"
"tree-sitter-cli": "^0.27.2"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
Expand Down
Loading