Skip to content

Commit cdbba62

Browse files
committed
fix: update method declaration parsing to include body and parameters for better accuracy
1 parent c0dbbaf commit cdbba62

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.java.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("parseSourceCodeDefinitionsForFile with Java", () => {
9090

9191
it("should parse method declarations", () => {
9292
expect(parseResult).toMatch(/\d+--\d+ \|\s*void testInterfaceMethod\(/)
93-
expect(parseResult).toMatch(/\d+--\d+ \|\s*public void testInterfaceMethod\(String message, T data\) {/)
93+
expect(parseResult).toMatch(/88--88 \|\s*public void testInterfaceMethod\(String message, T data\) {/)
9494
expect(parseResult).toMatch(/\d+--\d+ \|\s*void testMultipleAnnotationMethod\(String message, T data\) {/)
9595
expect(parseResult).toMatch(/\d+--\d+ \|\s*default String testInterfaceDefaultMethod\(/)
9696
expect(parseResult).toMatch(/\d+--\d+ \|\s*public <R extends Comparable<R>> R testGenericMethodDefinition\(/)

src/services/tree-sitter/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function setMinComponentLines(value: number): void {
2727
currentMinComponentLines = value
2828
}
2929

30-
function shouldSkipLineCountCheck(lineCount: number, capture: QueryCapture, language: string) {
30+
function passesMinLines(lineCount: number, capture: QueryCapture, language: string) {
3131
if (["definition.method", "definition.method.start"].includes(capture.name)) {
3232
// In object-oriented programming languages, method signatures are only one line and should not be ignored.
3333
return false
@@ -318,7 +318,7 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st
318318
const lineCount = endLine - startLine + 1
319319

320320
// Skip components that don't span enough lines
321-
if (shouldSkipLineCountCheck(lineCount, capture, language)) {
321+
if (passesMinLines(lineCount, capture, language)) {
322322
return
323323
}
324324

src/services/tree-sitter/queries/java.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ export default `
3838
name: (identifier) @name.definition.constructor) @definition.constructor
3939
4040
; Method declarations
41-
(method_declaration
42-
name: (identifier) @name.definition.method) @definition.method
43-
44-
; Method declarations with type - capture from type start
4541
(method_declaration
4642
type: (_) @definition.method.start
47-
name: (identifier) @name.definition.method)
43+
name: (identifier) @name.definition.method)@definition.method
44+
4845
4946
; Inner class declarations
5047
(class_declaration

0 commit comments

Comments
 (0)