2026-03-22 17:56:48 -05:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
from libs.event_factory import Event_Factory, Code_Event_Types
|
|
|
|
|
|
|
|
|
|
from plugins.plugin_types import PluginCode
|
|
|
|
|
|
2026-03-27 20:00:59 -05:00
|
|
|
from .tree_sitter import Parser, get_parser
|
2026-03-22 17:56:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Plugin(PluginCode):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(Plugin, self).__init__()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
|
|
|
|
if isinstance(event, Code_Event_Types.TextChangedEvent):
|
2026-03-27 20:00:59 -05:00
|
|
|
if not hasattr(event.file, "tree_sitter"):
|
|
|
|
|
parser = get_parser( event.file.ftype )
|
|
|
|
|
if not parser: return
|
|
|
|
|
|
|
|
|
|
event.file.tree_sitter = parser
|
|
|
|
|
|
|
|
|
|
buffer = event.file.buffer
|
2026-03-22 17:56:48 -05:00
|
|
|
start_itr, \
|
|
|
|
|
end_itr = buffer.get_bounds()
|
|
|
|
|
text = buffer.get_text(start_itr, end_itr, True)
|
|
|
|
|
|
2026-03-27 20:00:59 -05:00
|
|
|
tree = event.file.tree_sitter.parse( text.encode("UTF-8") )
|
|
|
|
|
event.file.ast = tree
|
|
|
|
|
|
|
|
|
|
# root = tree.root_node
|
|
|
|
|
# print("Root type:", root.type)
|
|
|
|
|
# for child in root.children:
|
|
|
|
|
# print(child.type, child.start_point, child.end_point)
|
2026-03-22 17:56:48 -05:00
|
|
|
|
|
|
|
|
def load(self):
|
2026-03-27 20:00:59 -05:00
|
|
|
...
|
2026-03-22 17:56:48 -05:00
|
|
|
|
|
|
|
|
def unload(self):
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
...
|