Skip to content

Commit 6a982c7

Browse files
author
Eric Wheeler
committed
docs: document tree-sitter parseable but unsupported structures
Added TODO sections in test files documenting structures that can be parsed by tree-sitter but currently lack query pattern support: - Python: f-strings, complex type annotations, pattern matching - C++: virtual methods, field initializers, base class clauses - Java: import declarations, field declarations with modifiers - TSX: React hooks, context providers, event handlers Added examples and clarifying comments to existing TODO sections. Enhanced Java query patterns for better structure capture including lambda expressions, field declarations, and type parameters. Signed-off-by: Eric Wheeler <[email protected]>
1 parent 1aa8809 commit 6a982c7

File tree

6 files changed

+106
-20
lines changed

6 files changed

+106
-20
lines changed

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.cpp.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ TODO: The following C++ structures can be parsed by tree-sitter but lack query s
33
44
1. Virtual Methods:
55
(field_declaration (virtual) type: (primitive_type) declarator: (function_declarator))
6+
Example: virtual void method() = 0;
67
78
2. Default Methods:
89
(default_method_clause)
10+
Example: virtual ~base_class_definition() = default;
911
1012
3. Field Initializer Lists:
1113
(field_initializer_list (field_initializer))
14+
Example: constructor() : field1(value1), field2(value2) {}
1215
1316
4. Base Class Clauses:
1417
(base_class_clause (access_specifier) (type_identifier))
18+
Example: class derived : public base {}
1519
1620
5. Type Aliases:
1721
(alias_declaration name: (type_identifier) type: (type_descriptor))
22+
Example: using size_type = std::size_t;
1823
*/
1924

2025
import { describe, it, expect, beforeAll } from "@jest/globals"
21-
import { debugLog, testParseSourceCodeDefinitions } from "./helpers"
26+
import { testParseSourceCodeDefinitions } from "./helpers"
2227
import { cppQuery } from "../queries"
2328
import sampleCppContent from "./fixtures/sample-cpp"
2429

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.go.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
TODO: The following structures can be parsed by tree-sitter but lack query support:
3+
4+
1. Anonymous Functions (func_literal):
5+
(func_literal parameters: (parameter_list) body: (block ...))
6+
- Currently visible in goroutine and defer statements
7+
- Would enable capturing lambda/closure definitions
8+
9+
2. Map Types (map_type):
10+
(map_type key: (type_identifier) value: (interface_type))
11+
- Currently visible in struct field declarations
12+
- Would enable capturing map type definitions
13+
14+
3. Pointer Types (pointer_type):
15+
(pointer_type (type_identifier))
16+
- Currently visible in method receiver declarations
17+
- Would enable capturing pointer type definitions
18+
*/
19+
120
import { describe, it, expect, beforeAll } from "@jest/globals"
221
import sampleGoContent from "./fixtures/sample-go"
322
import { testParseSourceCodeDefinitions } from "./helpers"

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import { describe, expect, it, jest, beforeAll, beforeEach } from "@jest/globals"
2-
import { parseSourceCodeDefinitionsForFile } from ".."
3-
import * as fs from "fs/promises"
4-
import * as path from "path"
5-
import { fileExistsAtPath } from "../../../utils/fs"
6-
import { loadRequiredLanguageParsers } from "../languageParser"
72
import { javaQuery } from "../queries"
83
import { testParseSourceCodeDefinitions } from "./helpers"
94
import sampleJavaContent from "./fixtures/sample-java"
@@ -13,9 +8,15 @@ TODO: The following structures can be parsed by tree-sitter but lack query suppo
138
149
1. Import Declarations:
1510
(import_declaration (scoped_identifier))
11+
- Tree-sitter successfully parses import statements but no query pattern exists
12+
- Example from inspect output: 'import java.util.List;'
13+
- Would enable capturing package dependencies and API usage
1614
1715
2. Field Declarations:
1816
(field_declaration (modifiers) type: (type_identifier) declarator: (variable_declarator))
17+
- Current query pattern needs enhancement to fully capture modifier information
18+
- Example from inspect output: 'private static final int count = 0;'
19+
- Would improve field visibility and mutability analysis
1920
*/
2021

2122
// Java test options
@@ -26,20 +27,6 @@ const testOptions = {
2627
extKey: "java",
2728
}
2829

29-
// Mock file system operations
30-
jest.mock("fs/promises")
31-
const mockedFs = jest.mocked(fs)
32-
33-
// Mock loadRequiredLanguageParsers
34-
jest.mock("../languageParser", () => ({
35-
loadRequiredLanguageParsers: jest.fn(),
36-
}))
37-
38-
// Mock fileExistsAtPath to return true for our test paths
39-
jest.mock("../../../utils/fs", () => ({
40-
fileExistsAtPath: jest.fn().mockImplementation(() => Promise.resolve(true)),
41-
}))
42-
4330
describe("parseSourceCodeDefinitionsForFile with Java", () => {
4431
let parseResult: string = ""
4532

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.python.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
TODO: The following structures can be parsed by tree-sitter but lack query support:
3+
4+
1. String Interpolation (f-strings):
5+
(string (string_start) (interpolation expression: (identifier)) (string_content) (string_end))
6+
Example: f"{result}: {param3}"
7+
8+
2. Complex Type Annotations with Generics:
9+
(type (generic_type (identifier) (type_parameter (type (generic_type)))))
10+
Example: dict[str, Union[List[int], Dict[str, bool], Optional[ComplexType]]]
11+
12+
3. Multiple Context Managers in With Statements:
13+
(with_clause (with_item) (with_item) (with_item))
14+
Example: with (open('file1.txt') as f1, open('file2.txt') as f2)
15+
16+
4. Pattern Matching with As-Patterns:
17+
(case_pattern (as_pattern (case_pattern (class_pattern)) (identifier)))
18+
Example: case {"name": str() as name, "age": int() as age}
19+
20+
5. Nested Function Definitions with Scope Modifiers:
21+
(function_definition (block (function_definition (block (nonlocal_statement) (global_statement)))))
22+
Example: Nested functions with nonlocal/global declarations
23+
*/
24+
125
import { describe, expect, it, beforeAll } from "@jest/globals"
226
import { testParseSourceCodeDefinitions, debugLog } from "./helpers"
327
import { samplePythonContent } from "./fixtures/sample-python"

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.tsx.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
/*
2+
TODO: The following structures can be parsed by tree-sitter but lack query support:
3+
4+
1. React Hooks:
5+
(call_expression
6+
function: (member_expression
7+
object: (identifier) @react
8+
property: [(property_identifier) @hook_name]))
9+
- Affects useState, useEffect, useRef, useCallback, useMemo
10+
- Currently visible in parse tests but no query patterns exist
11+
12+
2. Context Providers/Consumers:
13+
(jsx_element
14+
open_tag: (jsx_opening_element
15+
name: (member_expression
16+
object: (identifier) @context
17+
property: [(property_identifier) @provider
18+
(property_identifier) @consumer])))
19+
- Can be parsed as JSX elements but no specific capture patterns
20+
21+
3. React Event Handlers:
22+
(arrow_function
23+
parameters: (formal_parameters
24+
(required_parameter
25+
pattern: (identifier)
26+
type: (type_annotation
27+
(generic_type
28+
name: (nested_type_identifier
29+
module: (identifier) @react
30+
name: (type_identifier) @event_type)))))
31+
- Parsed but no specific patterns for React synthetic events
32+
*/
33+
134
import { describe, expect, it, jest, beforeAll } from "@jest/globals"
235
import { testParseSourceCodeDefinitions, mockedFs } from "./helpers"
336
import sampleTsxContent from "./fixtures/sample-tsx"

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,22 @@ export default `
5252
(class_body
5353
(class_declaration
5454
name: (identifier) @name.definition.static_nested_class))) @definition.static_nested_class
55+
56+
; Lambda expressions
57+
(lambda_expression) @definition.lambda
58+
59+
; Field declarations
60+
(field_declaration
61+
(modifiers)?
62+
type: (_)
63+
declarator: (variable_declarator
64+
name: (identifier) @name.definition.field)) @definition.field
65+
66+
; Import declarations
67+
(import_declaration
68+
(scoped_identifier) @name.definition.import) @definition.import
69+
70+
; Type parameters
71+
(type_parameters
72+
(type_parameter) @name.definition.type_parameter) @definition.type_parameter
5573
`

0 commit comments

Comments
 (0)