Skip to content

Commit

Permalink
fix(repo-map): only return top level definitions (yetone#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Sep 27, 2024
1 parent d74c9d0 commit ac959cc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 14 deletions.
38 changes: 25 additions & 13 deletions crates/avante-repo-map/queries/tree-sitter-go-defs.scm
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
;; Capture top-level functions and struct definitions
(var_declaration
(var_spec) @variable
(source_file
(var_declaration
(var_spec) @variable
)
)
(const_declaration
(const_spec) @variable
(source_file
(const_declaration
(const_spec) @variable
)
)
(function_declaration) @function
(type_declaration
(type_spec (struct_type)) @class
(source_file
(function_declaration) @function
)
(type_declaration
(type_spec
(struct_type
(field_declaration_list
(field_declaration) @class_variable)))
(source_file
(type_declaration
(type_spec (struct_type)) @class
)
)
(source_file
(type_declaration
(type_spec
(struct_type
(field_declaration_list
(field_declaration) @class_variable)))
)
)
(source_file
(method_declaration) @method
)
(method_declaration) @method
55 changes: 54 additions & 1 deletion crates/avante-repo-map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ mod tests {
InnerTestEnumField2,
}
pub fn test_fn(a: u32, b: u32) -> u32 {
a + b
let inner_var_in_func = 1;
struct InnerStructInFunc {
c: u32,
}
a + b + c
}
fn inner_test_fn(a: u32, b: u32) -> u32 {
a + b
Expand Down Expand Up @@ -729,6 +733,10 @@ mod tests {
innerTestField string
}
func (t *TestStruct) TestMethod(a int, b int) (int, error) {
var InnerVarInFunc int = 1
type InnerStructInFunc struct {
C int
}
return a + b, nil
}
func (t *TestStruct) innerTestMethod(a int, b int) (int, error) {
Expand Down Expand Up @@ -767,8 +775,18 @@ mod tests {
self.a = a
self.b = b
def test_method(self, a: int, b: int) -> int:
inner_var_in_method: int = 1
return a + b
def test_func(a: int, b: int) -> int:
inner_var_in_func: str = "test"
class InnerClassInFunc:
def __init__(self, a, b):
self.a = a
self.b = b
def test_method(self, a: int, b: int) -> int:
return a + b
def inne_func_in_func(a: int, b: int) -> int:
return a + b
return a + b
"#;
let definitions = extract_definitions("python", source).unwrap();
Expand All @@ -792,6 +810,10 @@ mod tests {
this.b = b;
}
testMethod(a: number, b: number): number {
const innerConstInMethod: number = 1;
function innerFuncInMethod(a: number, b: number): number {
return a + b;
}
return a + b;
}
}
Expand All @@ -800,6 +822,10 @@ mod tests {
b: number;
}
export function testFunc(a: number, b: number) {
const innerConstInFunc: number = 1;
function innerFuncInFunc(a: number, b: number): number {
return a + b;
}
return a + b;
}
export const testFunc2 = (a: number, b: number) => {
Expand Down Expand Up @@ -832,6 +858,10 @@ mod tests {
this.b = b;
}
testMethod(a, b) {
const innerConstInMethod = 1;
function innerFuncInMethod(a, b) {
return a + b;
}
return a + b;
}
}
Expand All @@ -842,6 +872,10 @@ mod tests {
}
}
export const testFunc = function(a, b) {
const innerConstInFunc = 1;
function innerFuncInFunc(a, b) {
return a + b;
}
return a + b;
}
export const testFunc2 = (a, b) => {
Expand All @@ -865,6 +899,17 @@ mod tests {
# This is a test comment
test_var = "test"
def test_func(a, b)
inner_var_in_func = "test"
class InnerClassInFunc
attr_accessor :a, :b
def initialize(a, b)
@a = a
@b = b
end
def test_method(a, b)
return a + b
end
end
return a + b
end
class TestClass
Expand All @@ -874,6 +919,10 @@ mod tests {
@b = b
end
def test_method(a, b)
inner_var_in_method = 1
def inner_func_in_method(a, b)
return a + b
end
return a + b
end
end
Expand All @@ -892,6 +941,10 @@ mod tests {
-- This is a test comment
local test_var = "test"
function test_func(a, b)
local inner_var_in_func = 1
function inner_func_in_func(a, b)
return a + b
end
return a + b
end
"#;
Expand Down

0 comments on commit ac959cc

Please sign in to comment.