Skip to content

Commit

Permalink
Add Support for tree-sitter queries as a ;anguage
Browse files Browse the repository at this point in the history
  • Loading branch information
ketkarameya committed Jun 30, 2023
1 parent f33bef7 commit 3c172f1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/models/default_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub const TYPESCRIPT: &str = "ts";
pub const TSX: &str = "tsx";
pub const THRIFT: &str = "thrift";
pub const STRINGS: &str = "strings";
pub const TS_SCHEME: &str = "scm"; // We support scheme files that contain tree-sitter query

#[cfg(test)]
//FIXME: Remove this hack by not passing PiranhaArguments to SourceCodeUnit
Expand Down
12 changes: 11 additions & 1 deletion src/models/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::utilities::parse_toml;

use super::{
default_configs::{
default_language, GO, JAVA, KOTLIN, PYTHON, STRINGS, SWIFT, THRIFT, TSX, TYPESCRIPT,
default_language, GO, JAVA, KOTLIN, PYTHON, STRINGS, SWIFT, THRIFT, TSX, TS_SCHEME, TYPESCRIPT,
},
outgoing_edges::Edges,
rule::Rules,
Expand Down Expand Up @@ -65,6 +65,7 @@ pub enum SupportedLanguage {
Python,
Thrift,
Strings,
TsScheme,
}

impl PiranhaLanguage {
Expand Down Expand Up @@ -228,6 +229,15 @@ impl std::str::FromStr for PiranhaLanguage {
scopes: vec![],
comment_nodes: vec![],
}),
TS_SCHEME => Ok(PiranhaLanguage {
extension: language.to_string(),
supported_language: SupportedLanguage::TsScheme,
language: tree_sitter_query::language(),
rules: None,
edges: None,
scopes: vec![],
comment_nodes: vec![],
}),
_ => Err("Language not supported"),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod test_piranha_tsx;

mod test_piranha_thrift;

mod test_piranha_scm;
mod test_piranha_strings;

use std::sync::Once;
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_piranha_scm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright (c) 2023 Uber Technologies, Inc.
<p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
<p>http://www.apache.org/licenses/LICENSE-2.0
<p>Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
limitations under the License.
*/

use crate::models::default_configs::TS_SCHEME;

use super::create_rewrite_tests;

create_rewrite_tests! {
TS_SCHEME,
test_simple_rename: "simple_rename", 1;

}
24 changes: 24 additions & 0 deletions test-resources/scm/simple_rename/configurations/rules.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2023 Uber Technologies, Inc.
#
# <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
# <p>http://www.apache.org/licenses/LICENSE-2.0
#
# <p>Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing permissions and
# limitations under the License.

# Matchs an enum entry named `GLOBAL_TAG.enum_entry_name`
[[rules]]
name = "delete_enum_entry"
query = """
(
(named_node name: (_)@named_node (field_definition (named_node (capture name: (_)@i) ))) @n
(#eq? @named_node "method_declaration")
(#eq? @i "name")
)
"""
replace_node = "i"
replace = "method_name"
is_seed_rule = true
1 change: 1 addition & 0 deletions test-resources/scm/simple_rename/expected/sample.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(method_declaration name: (_) @method_name) @md
1 change: 1 addition & 0 deletions test-resources/scm/simple_rename/input/sample.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(method_declaration name: (_) @name) @md

0 comments on commit 3c172f1

Please sign in to comment.