Просмотр исходного кода

Merge pull request #2663 from NaccOll/fix-listCodeDefinitionNamesTool-for-java

fix listCodeDefinitionNamesTool not working in java. #2562
Christiaan Arnoldus 4 месяцев назад
Родитель
Сommit
115dd8eb5c

+ 5 - 0
.changeset/strong-drinks-shave.md

@@ -0,0 +1,5 @@
+---
+"kilo-code": patch
+---
+
+Fix listCodeDefinitionNamesTool for annotated Java methods

+ 10 - 12
src/services/tree-sitter/__tests__/fixtures/sample-java.ts

@@ -29,16 +29,10 @@ public @interface TestAnnotationDefinition {
 // Interface declaration test - at least 4 lines long
 public interface TestInterfaceDefinition<T extends Comparable<T>> {
     // Interface method declarations
-    void testInterfaceMethod(
-        String message,
-        T data
-    );
+    void testInterfaceMethod(String message, T data); // kilocode_change: whitespace
     
     // Default method in interface - 4+ lines
-    default String testInterfaceDefaultMethod(
-        String input,
-        T data
-    ) {
+    default String testInterfaceDefaultMethod(String input, T data) { // kilocode_change: whitespace
         return String.format("%s: %s", input, data.toString());
     }
 }
@@ -91,12 +85,16 @@ public class TestClassDefinition<T extends Comparable<T>>
 
     // Method implementation - at least 4 lines long
     @Override
-    public void testInterfaceMethod(
-        String message,
-        T data
-    ) {
+    public void testInterfaceMethod(String message, T data) { // kilocode_change: whitespace
+        System.out.println(testInterfaceDefaultMethod(message, data));
+    }
+
+    // kilocode_change start: method added
+    @TestAnnotationDefinition(value="test")    
+    void testMultipleAnnotationMethod(String message, T data) {
         System.out.println(testInterfaceDefaultMethod(message, data));
     }
+    // kilocode_change end
 
     // Generic method test - at least 4 lines long
     public <R extends Comparable<R>> R testGenericMethodDefinition(

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

@@ -90,7 +90,9 @@ describe("parseSourceCodeDefinitionsForFile with Java", () => {
 
 	it("should parse method declarations", () => {
 		expect(parseResult).toMatch(/\d+--\d+ \|\s*void testInterfaceMethod\(/)
+		expect(parseResult).toMatch(/\d+--\d+ \|\s*public void testInterfaceMethod\(String message, T data\) {/) // kilocode_change
 		expect(parseResult).toMatch(/\d+--\d+ \|\s*default String testInterfaceDefaultMethod\(/)
+		expect(parseResult).toMatch(/\d+--\d+ \|\s*void testMultipleAnnotationMethod\(String message, T data\) {/) // kilocode_change
 		expect(parseResult).toMatch(/\d+--\d+ \|\s*public <R extends Comparable<R>> R testGenericMethodDefinition\(/)
 		expect(parseResult).toMatch(/\d+--\d+ \|\s*public String formatMessage\(/)
 		expect(parseResult).toMatch(/\d+--\d+ \|\s*public abstract String testAbstractMethod\(/)

+ 13 - 1
src/services/tree-sitter/index.ts

@@ -7,6 +7,8 @@ import { parseMarkdown } from "./markdownParser"
 import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
 import { QueryCapture } from "web-tree-sitter"
 
+const METHOD_CAPTURE = ["definition.method", "definition.method.start"] // kilocode_change
+
 // Private constant
 const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4
 
@@ -27,6 +29,16 @@ export function setMinComponentLines(value: number): void {
 	currentMinComponentLines = value
 }
 
+// kilocode_change start
+function shouldSkipMinLines(lineCount: number, capture: QueryCapture, language: string) {
+	if (METHOD_CAPTURE.includes(capture.name)) {
+		// In object-oriented programming languages, method signatures are only one line and should not be ignored.
+		return false
+	}
+	return lineCount < getMinComponentLines()
+}
+// kilocode_change end
+
 const extensions = [
 	"tla",
 	"js",
@@ -310,7 +322,7 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st
 		const lineCount = endLine - startLine + 1
 
 		// Skip components that don't span enough lines
-		if (lineCount < getMinComponentLines()) {
+		if (shouldSkipMinLines(lineCount, capture, language) /*kilocode_change: orginal logic moved into function*/) {
 			return
 		}
 

+ 1 - 0
src/services/tree-sitter/queries/java.ts

@@ -39,6 +39,7 @@ export default `
 
 ; Method declarations
 (method_declaration
+  type: (_) @definition.method.start ; kilocode_change
   name: (identifier) @name.definition.method) @definition.method
 
 ; Inner class declarations