From 9a74f5cbf5cb5dc59c0729f16550b33c1eec5cc0 Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Thu, 8 Jun 2023 19:37:04 +0100 Subject: [PATCH] Add ts_node_language() that returns the language of the node Since an input might have a nested sublanguage (like Javascript inside Vue) and symbols are per-language, we need to know which language a node is. --- lib/include/tree_sitter/api.h | 5 +++++ lib/src/node.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/include/tree_sitter/api.h b/lib/include/tree_sitter/api.h index e455e81d..306891df 100644 --- a/lib/include/tree_sitter/api.h +++ b/lib/include/tree_sitter/api.h @@ -436,6 +436,11 @@ const char *ts_node_type(TSNode); */ TSSymbol ts_node_symbol(TSNode); +/** + * Get the node's language. + */ +const TSLanguage *ts_node_language(TSNode); + /** * Get the node's start byte. */ diff --git a/lib/src/node.c b/lib/src/node.c index d6a190c0..aa947148 100644 --- a/lib/src/node.c +++ b/lib/src/node.c @@ -423,6 +423,10 @@ const char *ts_node_type(TSNode self) { return ts_language_symbol_name(self.tree->language, symbol); } +const TSLanguage *ts_node_language(TSNode self) { + return self.tree->language; +} + char *ts_node_string(TSNode self) { return ts_subtree_string(ts_node__subtree(self), self.tree->language, false); }