feat(event-watchers): rework file state detection and migrate tree-sitter integration
Switch file state checks to trigger on FocusedViewEvent instead of TextChangedEvent Resolve file via files controller and operate directly on file object Add user prompt for externally modified files with optional reload Auto-reload unmodified buffers when external changes are detected Simplify file_is_deleted / file_is_externally_modified APIs tree-sitter Remove bundled tree_sitter_language_pack and related setup/notes scripts Introduce local lightweight tree_sitter wrapper (Parser, get_parser) Store parser per file and generate AST directly from buffer text Remove runtime language download/config logic Update manifest (drop autoload) core Simplify CLI file handling in BaseControllerMixin Send directory args directly via IPC instead of encoding in file list cleanup Remove unused libs, scripts, and legacy code paths
This commit is contained in:
57
plugins/code/event-watchers/tree_sitter/tree_sitter.py
Normal file
57
plugins/code/event-watchers/tree_sitter/tree_sitter.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# Python imports
|
||||
import os
|
||||
import ctypes
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from .libs.tree_sitter import Language, Parser
|
||||
|
||||
|
||||
|
||||
_LIB_PATH = os.path.join(
|
||||
os.path.dirname(__file__), "languages", "languages.so"
|
||||
)
|
||||
_LANGUAGE_LIB = ctypes.CDLL(_LIB_PATH)
|
||||
|
||||
|
||||
|
||||
def load_language(name: str) -> Language | None:
|
||||
symbol = f"tree_sitter_{name}"
|
||||
|
||||
try:
|
||||
func = getattr(_LANGUAGE_LIB, symbol)
|
||||
except AttributeError:
|
||||
logger.warning(f"Tree-sitter: {name} not found in 'languages.so' shared library...")
|
||||
return None
|
||||
|
||||
func.restype = ctypes.c_void_p
|
||||
return Language(func())
|
||||
|
||||
|
||||
LANGUAGES = {
|
||||
"python": load_language("python"),
|
||||
"python3": load_language("python"),
|
||||
"javascript": load_language("javascript"),
|
||||
"html": load_language("html"),
|
||||
"css": load_language("css"),
|
||||
"json": load_language("json"),
|
||||
"java": load_language("java"),
|
||||
"c": load_language("c"),
|
||||
"cpp": load_language("cpp"),
|
||||
"go": load_language("go")
|
||||
}
|
||||
|
||||
|
||||
def get_parser(lang_name: str) -> Parser | None:
|
||||
if not lang_name in LANGUAGES: return
|
||||
|
||||
language = LANGUAGES[lang_name]
|
||||
|
||||
if not language in LANGUAGES: return
|
||||
|
||||
parser = Parser()
|
||||
parser.language = language
|
||||
|
||||
return parser
|
||||
|
||||
Reference in New Issue
Block a user