Skip to content

Commit 8e85a12

Browse files
KJ7LNWEric Wheeler
andauthored
feat: standardize tree-sitter test implementations (#2960)
* refactor: standardize C# Tree-Sitter parser tests This commit standardizes the C# Tree-Sitter parser tests to ensure: - Variable/function names in sample code match the tests - Each test only verifies specific identifiers relevant to that test - Test names clearly indicate what they're testing - No skipped tests remain - Only one test exists per structure or combination of structures - All debug output uses debugLog from helpers.ts The standardization improves maintainability and clarity while preserving all existing functionality. Signed-off-by: Eric Wheeler <[email protected]> * refactor: standardize C Tree-Sitter parser tests This commit standardizes the C Tree-Sitter parser tests to ensure: - Variable/function names in sample code match the tests (using snake_case) - Each test only verifies specific identifiers relevant to that test - Test names clearly indicate what they're testing - No skipped tests remain - tests for unsupported features are removed - Only one test exists per structure or combination of structures - All debug output uses debugLog from helpers.ts The standardization improves maintainability and clarity while preserving all existing functionality. Documentation has been added for C language constructs that are not currently supported by the parser. Signed-off-by: Eric Wheeler <[email protected]> * feat: standardize Kotlin Tree-Sitter parser Standardized Kotlin Tree-Sitter parser to ensure consistent naming and structure: - Renamed identifiers to clearly indicate what they're testing - Ensured all code sections are at least 4 lines long - Organized query patterns logically with clear comments - Removed skipped tests and unused query patterns - Ensured only one test per structure or combination of structures Signed-off-by: Eric Wheeler <[email protected]> * feat: standardize PHP Tree-Sitter parser Standardized PHP Tree-Sitter parser to ensure consistent naming and structure: - Renamed identifiers to clearly indicate what they're testing - Ensured all code sections are at least 4 lines long - Organized query patterns logically with clear comments - Consolidated related tests to ensure only one test per structure - Ensured all debug output uses debugLog from helpers.ts Signed-off-by: Eric Wheeler <[email protected]> * feat: standardize Ruby Tree-Sitter parser Standardized Ruby Tree-Sitter parser to ensure consistent naming and structure: - Expanded query to support many more Ruby language constructs - Added comprehensive test file with clear section headers - Ensured all code sections are at least 4 lines long - Added tests for each language construct - Used consistent naming conventions for test identifiers Signed-off-by: Eric Wheeler <[email protected]> * feat: standardize Swift Tree-Sitter parser Standardized Swift Tree-Sitter parser to ensure consistent naming and structure: - Renamed identifiers to clearly indicate what they're testing - Ensured all code sections are at least 4 lines long - Organized query patterns logically with clear comments - Removed skipped tests and unused query patterns - Ensured only one test per structure or combination of structures Signed-off-by: Eric Wheeler <[email protected]> * feat: dynamically include all tree-sitter WASM files in build process - Modified esbuild.js to dynamically read and copy all WASM files from tree-sitter-wasms package - Added error handling and logging for better debugging - Ensures all language parsers are automatically included without requiring manual updates * refactor: move test mocks and fixtures to shared locations Move test mocks to helpers.ts to be shared between test files Create fixtures directory for shared test data Move sample TSX content to fixtures/sample-tsx.ts Update test files to use shared mocks and fixtures Signed-off-by: Eric Wheeler <[email protected]> * refactor: simplify tree-sitter debug output - Remove detailed node inspection to reduce noise - Keep only essential tree structure output - Remove duplicate content logging Signed-off-by: Eric Wheeler <[email protected]> * refactor: standardize C# tree-sitter test structure Move C# sample code to dedicated fixture file and create inspectCSharp test following the same pattern as other language tests. This improves test organization and maintainability by: - Extracting sample C# code to fixtures/sample-c-sharp.ts - Adding inspectCSharp.test.ts for tree structure inspection - Updating parseSourceCodeDefinitions.c-sharp.test.ts to use fixture Signed-off-by: Eric Wheeler <[email protected]> * feat: add language-specific capture processing - Add language parameter to processCaptures for language-specific handling - Implement selective HTML filtering for jsx/tsx files - Update all call sites to pass correct language parameter - Fix type safety by properly passing language strings Signed-off-by: Eric Wheeler <[email protected]> * refactor: move tree-sitter test samples to fixtures Move sample code from parseSourceCodeDefinitions test files into dedicated fixtures directory for better organization and reuse: - Created fixtures directory for language samples - Moved sample code for C#, C, JSON, Kotlin, PHP, Ruby, Rust, and Swift - Created inspect test files for each language - Updated original test files to import from fixtures - Standardized test options across languages - No behavior changes, all tests passing Signed-off-by: Eric Wheeler <[email protected]> * refactor: standardize tree-sitter test code across languages Standardize test code structure and naming across all language parsers: - Rename identifiers to clearly indicate test purpose - Ensure each code section has descriptive comments - Group related code sections together - Maintain language-specific naming conventions - Keep test structure consistent across languages - Remove tests for unsupported features Changes made to: - C, JSON, Kotlin, PHP, Ruby, Rust, and Swift test files - Sample code fixtures - Parser definition tests - Inspect structure tests No functional changes - all tests passing with improved maintainability. Signed-off-by: Eric Wheeler <[email protected]> * refactor: standardize tree-sitter parser tests across all languages - Ensure all test structures span at least 4 lines for better parsing - Create exactly one consolidated test per data structure type - Use descriptive names that clearly indicate test purpose - Improve query pattern organization and documentation - Simplify inspect test files to focus on structure validation - Implement result caching in test files for better performance - Remove duplicate and skipped tests - Follow consistent naming conventions across all languages Signed-off-by: Eric Wheeler <[email protected]> * first pass all but elm-bash * test: inspectTreeStructure helper now returns a string Signed-off-by: Eric Wheeler <[email protected]> * refactor: establish single source of truth for MIN_COMPONENT_LINES - Move minComponentLines parameter to a file-level constant - Remove parameter passing to processCaptures function - Update all references to use the global constant - Remove redundant local constant declaration in parseFile Signed-off-by: Eric Wheeler <[email protected]> * refactor: improve MIN_COMPONENT_LINES implementation - Changed MIN_COMPONENT_LINES constant to use getter/setter functions - Updated references to use getMinComponentLines() function - Modified test helper to set value to 0 during tests - This establishes a single source of truth while making testing easier Signed-off-by: Eric Wheeler <[email protected]> * feat: standardize tree-sitter test implementations Standardized tree-sitter test implementations across all supported languages: - Removed debugLog calls from test files - Implemented consistent line number pattern matching - Ensured proper test structure and execution order - Added comprehensive test coverage for supported structures - Maintained 1:1 mapping between queries, tests and samples - Documented unsupported features in TODO sections Signed-off-by: Eric Wheeler <[email protected]> * 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]> * fix: use correct distDir variable for WASM file copying The copyWasmFiles plugin was using an undefined targetDir variable when copying tree-sitter WASM files. Changed to use the correctly defined distDir variable, fixing the build process. Signed-off-by: Eric Wheeler <[email protected]> * lint: remove unused imports and variables from tree-sitter tests Removed unused imports and variables from tree-sitter test files to fix linting errors: - Removed unused goQuery import from helpers.ts - Removed unused imports and mockedFs variables from language-specific test files - Cleaned up test files to only import what they use Signed-off-by: Eric Wheeler <[email protected]> --------- Signed-off-by: Eric Wheeler <[email protected]> Co-authored-by: Eric Wheeler <[email protected]>
1 parent ecc7473 commit 8e85a12

File tree

119 files changed

+9743
-4248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+9743
-4248
lines changed

esbuild.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,21 @@ const copyWasmFiles = {
3838
path.join(distDir, "tiktoken_bg.wasm"),
3939
)
4040

41-
// tree-sitter WASM
42-
fs.copyFileSync(
43-
path.join(nodeModulesDir, "web-tree-sitter", "tree-sitter.wasm"),
44-
path.join(distDir, "tree-sitter.wasm"),
45-
)
41+
// Copy language-specific WASM files
42+
const languageWasmDir = path.join(__dirname, "node_modules", "tree-sitter-wasms", "out")
4643

47-
// language-specific tree-sitter WASMs
48-
const languageWasmDir = path.join(nodeModulesDir, "tree-sitter-wasms", "out")
49-
const languages = [
50-
"typescript",
51-
"tsx",
52-
"python",
53-
"rust",
54-
"javascript",
55-
"go",
56-
"cpp",
57-
"c",
58-
"c_sharp",
59-
"ruby",
60-
"java",
61-
"php",
62-
"swift",
63-
"kotlin",
64-
]
65-
66-
languages.forEach((lang) => {
67-
const filename = `tree-sitter-${lang}.wasm`
68-
fs.copyFileSync(path.join(languageWasmDir, filename), path.join(distDir, filename))
69-
})
44+
// Dynamically read all WASM files from the directory instead of using a hardcoded list
45+
if (fs.existsSync(languageWasmDir)) {
46+
const wasmFiles = fs.readdirSync(languageWasmDir).filter((file) => file.endsWith(".wasm"))
47+
48+
console.log(`Copying ${wasmFiles.length} tree-sitter WASM files to dist directory`)
49+
50+
wasmFiles.forEach((filename) => {
51+
fs.copyFileSync(path.join(languageWasmDir, filename), path.join(distDir, filename))
52+
})
53+
} else {
54+
console.warn(`Tree-sitter WASM directory not found: ${languageWasmDir}`)
55+
}
7056
})
7157
},
7258
}

0 commit comments

Comments
 (0)