Skip to content

Commit

Permalink
Fix tree-sitter update with proper Language object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartManoj committed Feb 19, 2025
1 parent ed2d2b3 commit b0ec7fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openhands/linter/languages/treesitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from grep_ast import TreeContext, filename_to_lang
from grep_ast.parsers import PARSERS
from tree_sitter_languages import get_parser

from openhands.linter.base import BaseLinter, LintResult
from openhands.linter.languages.treesitter_compat import get_parser

# tree_sitter is throwing a FutureWarning
warnings.simplefilter('ignore', category=FutureWarning)
Expand Down
23 changes: 23 additions & 0 deletions openhands/linter/languages/treesitter_compat.py
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])

0 comments on commit b0ec7fb

Please sign in to comment.