forked from All-Hands-AI/OpenHands
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tree-sitter update with proper Language object creation
- Loading branch information
1 parent
ed2d2b3
commit b0ec7fb
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Compatibility layer for tree-sitter 0.24.0.""" | ||
|
||
import importlib | ||
from tree_sitter import Language, Parser | ||
|
||
# Cache of loaded languages | ||
_language_cache = {} | ||
|
||
|
||
def get_parser(language): | ||
"""Get a Parser object for the given language name.""" | ||
if language not in _language_cache: | ||
# Try to import the language module | ||
module_name = f"tree_sitter_{language}" | ||
try: | ||
module = importlib.import_module(module_name) | ||
_language_cache[language] = Language(module.language()) | ||
except ImportError: | ||
raise ValueError( | ||
f"Language {language} is not supported. Please install {module_name} package." | ||
) | ||
|
||
return Parser(_language_cache[language]) |