Skip to content

Commit fd754be

Browse files
committed
[function-grep] Added support for csharp ruby and go out of the box
added test for c
1 parent 866312c commit fd754be

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

function-grep/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,27 @@ rust-version = "1.75.0"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[features]
15-
default = ["rust", "python", "c", "ocaml", "java"]
15+
default = ["rust", "python", "c", "ocaml", "java", "ruby", "go", "c-sharp"]
1616
rust = ["dep:tree-sitter-rust"]
1717
ocaml = ["dep:tree-sitter-ocaml"]
1818
c = ["dep:tree-sitter-c"]
1919
java = ["dep:tree-sitter-java"]
2020
python = ["dep:tree-sitter-python"]
21+
ruby = ["dep:tree-sitter-ruby"]
22+
go = ["dep:tree-sitter-go"]
23+
c-sharp = ["dep:tree-sitter-c-sharp"]
2124

2225
[dependencies]
2326
tree-sitter = ">=0.21.0"
2427
tree-sitter-c = { version = "0.21.4", optional = true }
2528
tree-sitter-java = { version = "0.21.0", optional = true }
2629
tree-sitter-ocaml = { version = "0.21.2", optional = true }
2730
tree-sitter-python = { version = "0.21.0", optional = true }
31+
tree-sitter-ruby = { version = "0.21.0", optional = true }
32+
tree-sitter-go = { version = "0.21.2", optional = true }
33+
tree-sitter-c-sharp = { version = "0.21.3", optional = true }
2834
tree-sitter-rust = { version = "0.21.2", optional = true }
35+
tree-sitter-tags = "0.21"
2936

3037
[dev-dependencies]
3138
clap = { version = "4.5.7", features = ["derive"] }

function-grep/src/supported_languages.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::ops::Deref;
22
use tree_sitter::{Language as TsLanguage, Node, Query, QueryError, Range};
33
// TODO: better api less boxing and more results
4+
// TODO: better way to do variable assigned to function or just abondon it? (the problem is with
5+
// languages that allow mutliple assignments how do you match up only the identifiers that
6+
// corespond to functions)
7+
// TODO: we could probably use tree sitter tags?
48

59
#[allow(missing_debug_implementations)]
610
pub struct InstatiatedLanguage<'a> {
@@ -290,6 +294,41 @@ construct_language!(C(tree_sitter_c::language()).[c h]?=
290294
(#eq? @method-name {name}))"
291295
);
292296

297+
#[cfg(feature = "ruby")]
298+
// TODO: also query for anonymous functions assigned to variables
299+
construct_language!(Ruby(tree_sitter_ruby::language()).[rb] ?= "method-name" =>
300+
"((method name: (identifier) @method-name) @method-definition)");
301+
302+
#[cfg(feature = "c-sharp")]
303+
// TODO: also query for anonymous functions assigned to variables
304+
construct_language!(CSharp(tree_sitter_c_sharp::language()).[cs] ?= "method-name" =>
305+
"((local_function_statement name: (identifier) @method-name) @method)
306+
((method_declaration name: (identifier) @method-name) @method)"
307+
308+
);
309+
#[cfg(feature = "go")]
310+
// TODO: also query for anonymous functions assigned to variables
311+
// var f,y integer = func(x int) int {
312+
// return x * x
313+
// }, y
314+
// x, y := 5
315+
// fmt.Println(foo(10))
316+
// const f f = 5;
317+
// func main() {
318+
// empty_test(1, 2, "3")
319+
// fmt.Println("Hello World!")
320+
// }
321+
//
322+
// // doc comment
323+
//
324+
// func empty_test(c, a int, b string) {
325+
// fmt.Println("Hello World!")
326+
// }
327+
// ((var_declaration (var_spec name: (identifier) @method-name )))
328+
// ((const_declaration))
329+
// ((short_var_declaration))
330+
construct_language!(Go(tree_sitter_go::language()).[go] ?= "method-name" =>
331+
"((function_declaration name: (identifier) @method-name) @method-definition)");
293332
#[cfg(feature = "rust")]
294333
construct_language!(Rust(tree_sitter_rust::language()).[rs] ?= "method-name" =>
295334

@@ -379,5 +418,11 @@ pub fn predefined_languages() -> &'static [&'static dyn SupportedLanguage] {
379418
&Java,
380419
#[cfg(feature = "ocaml")]
381420
&OCaml,
421+
#[cfg(feature = "c-sharp")]
422+
&CSharp,
423+
#[cfg(feature = "go")]
424+
&Go,
425+
#[cfg(feature = "ruby")]
426+
&Ruby,
382427
]
383428
}

git-function-history-lib/src/test_functions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ void test_function(void)
2424
printf("Hello World!");
2525
}
2626

27+
int empty_test()
28+
{f}
29+

0 commit comments

Comments
 (0)