"""Configuration for supported languages and file extensions."""
from typing import Dict, List
# Language ID to tree-sitter grammar mapping
LANGUAGE_GRAMMARS: Dict[str, str] = {
"python": "tree_sitter_python",
"javascript": "tree_sitter_javascript",
"typescript": "tree_sitter_typescript",
"java": "tree_sitter_java",
"csharp": "tree_sitter_c_sharp",
"go": "tree_sitter_go",
}
# File extension to language ID mapping
FILE_EXTENSION_MAP: Dict[str, str] = {
".py": "python",
".js": "javascript",
".mjs": "javascript",
".cjs": "javascript",
".ts": "typescript",
".tsx": "typescript",
".java": "java",
".cs": "csharp",
".go": "go",
}
# Node types that represent classes for each language
CLASS_NODE_TYPES: Dict[str, List[str]] = {
"python": ["class_definition"],
"javascript": ["class_declaration", "class_expression"],
"typescript": ["class_declaration", "class_expression"],
"java": ["class_declaration", "interface_declaration", "enum_declaration"],
"csharp": ["class_declaration", "interface_declaration", "struct_declaration"],
"go": ["type_declaration"], # Go uses type declarations for structs
}
# Node types that represent functions for each language
FUNCTION_NODE_TYPES: Dict[str, List[str]] = {
"python": [
"function_definition",
"async_function_definition",
"decorated_definition",
],
"javascript": [
"function_declaration",
"function_expression",
"arrow_function",
"method_definition",
],
"typescript": [
"function_declaration",
"function_expression",
"arrow_function",
"method_definition",
],
"java": [
"method_declaration",
"constructor_declaration",
],
"csharp": [
"method_declaration",
"constructor_declaration",
],
"go": [
"function_declaration",
"method_declaration",
],
}
def get_language_from_extension(file_path: str) -> str | None:
"""Get language ID from file extension."""
import os
_, ext = os.path.splitext(file_path)
return FILE_EXTENSION_MAP.get(ext.lower())
def get_supported_languages() -> List[str]:
"""Get list of supported language IDs."""
return list(LANGUAGE_GRAMMARS.keys())
def is_supported_language(language: str) -> bool:
"""Check if a language is supported."""
return language in LANGUAGE_GRAMMARS