Skip to content

Commit

Permalink
feat: upgrade tree-sitter to 0.24.4
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 11, 2024
1 parent c643334 commit e5d55ae
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ sha2 = "0.10.7"
num_cpus = "1.15.0"
tracing = "0.1.40"
uuid = { version = "1.6.1", features = ["v4"] }
tree-sitter = "0.22.6"
tree-sitter = "0.24.4"
1 change: 1 addition & 0 deletions crates/static-analysis-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ globset = "0.4.14"
graphviz-rust = "0.9.0"
sequence_trie = "0.3.6"
serde_yaml = "0.9.21"
streaming-iterator = "0.1.9"
thiserror = "1.0.59"

[build-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::analysis::tree_sitter::get_tree_sitter_language;
use crate::model::common::Language;
use deno_core::v8;
use deno_core::v8::HandleScope;
use streaming_iterator::StreamingIterator;

/// Structure for the file context that is specific to Go.
#[derive(Debug)]
Expand Down Expand Up @@ -44,8 +45,9 @@ impl FileContextGo {
// the second capture is the name of the package.

let mut query_cursor = tree_sitter::QueryCursor::new();
let query_result = query_cursor.matches(&self.ts_query, tree.root_node(), code.as_bytes());
for query_match in query_result {
let mut query_result =
query_cursor.matches(&self.ts_query, tree.root_node(), code.as_bytes());
while let Some(query_match) = query_result.next() {
let mut package_name: Option<&str> = None;
let mut package_alias: Option<&str> = None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use deno_core::v8;
use deno_core::v8::HandleScope;
use streaming_iterator::StreamingIterator;

use crate::analysis::ddsa_lib::common::{Class, DDSAJsRuntimeError};
use crate::analysis::ddsa_lib::js::JSPackageImport;
Expand Down Expand Up @@ -165,8 +166,7 @@ impl FileContextJavaScript {

let query_result = query_cursor.matches(&self.query, tree.root_node(), code.as_bytes());
let imports = query_result
.into_iter()
.filter_map(|query_match| {
.filter_map_deref(|query_match| {
let mut name = None;
let mut imported_from = None;
let mut has_default = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright 2024 Datadog, Inc.

use deno_core::v8::{self, HandleScope};
use streaming_iterator::StreamingIterator;

use crate::analysis::ddsa_lib::common::{Class, DDSAJsRuntimeError};
use crate::analysis::ddsa_lib::js;
Expand Down Expand Up @@ -55,8 +56,7 @@ impl FileContextTerraform {
let query_result = query_cursor.matches(&self.query, tree.root_node(), code.as_bytes());

let resources = query_result
.into_iter()
.map(|query_match| {
.map_deref(|query_match| {
let mut resource_type = None;
let mut resource_name = None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ impl RootContext {
/////

let mut depth = 0;
while let Some(child) = current_node.child_containing_descendant(node) {
while let Some(child) = current_node.child_with_descendant(node) {
if child == node {
break;
}
// Cache the relationship discovered as a side effect of traversing down from the root.
// Note that because the `child_containing_descendant` API filter its output, we
// only end up caching the path directly from the root to this node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ mod tests {
use crate::model::common::Language;
use deno_core::v8;
use std::marker::PhantomData;
use streaming_iterator::StreamingIterator;

#[test]
fn js_properties_canary() {
Expand Down
3 changes: 2 additions & 1 deletion crates/static-analysis-kernel/src/analysis/tree_sitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use common::model::position::Position;
use indexmap::IndexMap;
use std::collections::HashMap;
use std::sync::Arc;
use streaming_iterator::StreamingIterator;
use tree_sitter::CaptureQuantifier;

pub fn get_tree_sitter_language(language: &Language) -> tree_sitter::Language {
Expand Down Expand Up @@ -176,7 +177,7 @@ impl<'a, 'tree> TSQueryCursor<'a, 'tree> {
MaybeOwnedMut::Owned(cursor) => cursor,
};
let matches = cursor.matches(self.query, node, text.as_bytes());
matches.map(|q_match| {
matches.map_deref(|q_match| {
for capture in q_match.captures {
self.captures_scratch
.entry(capture.index)
Expand Down

0 comments on commit e5d55ae

Please sign in to comment.