forked from run-llama/llama_index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for all languages in py-treesitter (run-llama#13587)
- Loading branch information
Showing
19 changed files
with
673 additions
and
9 deletions.
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
9 changes: 9 additions & 0 deletions
9
...e-hierarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-c-tags.scm
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,9 @@ | ||
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class | ||
|
||
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class | ||
|
||
(function_declarator declarator: (identifier) @name.definition.function) @definition.function | ||
|
||
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type | ||
|
||
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type |
46 changes: 46 additions & 0 deletions
46
...archy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-c_sharp-tags.scm
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,46 @@ | ||
(class_declaration | ||
name: (identifier) @name.definition.class | ||
) @definition.class | ||
|
||
(class_declaration | ||
bases: (base_list (_) @name.reference.class) | ||
) @reference.class | ||
|
||
(interface_declaration | ||
name: (identifier) @name.definition.interface | ||
) @definition.interface | ||
|
||
(interface_declaration | ||
bases: (base_list (_) @name.reference.interface) | ||
) @reference.interface | ||
|
||
(method_declaration | ||
name: (identifier) @name.definition.method | ||
) @definition.method | ||
|
||
(object_creation_expression | ||
type: (identifier) @name.reference.class | ||
) @reference.class | ||
|
||
(type_parameter_constraints_clause | ||
target: (identifier) @name.reference.class | ||
) @reference.class | ||
|
||
(type_constraint | ||
type: (identifier) @name.reference.class | ||
) @reference.class | ||
|
||
(variable_declaration | ||
type: (identifier) @name.reference.class | ||
) @reference.class | ||
|
||
(invocation_expression | ||
function: | ||
(member_access_expression | ||
name: (identifier) @name.reference.send | ||
) | ||
) @reference.send | ||
|
||
(namespace_declaration | ||
name: (identifier) @name.definition.module | ||
) @definition.module |
15 changes: 15 additions & 0 deletions
15
...hierarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-cpp-tags.scm
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,15 @@ | ||
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class | ||
|
||
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class | ||
|
||
(function_declarator declarator: (identifier) @name.definition.function) @definition.function | ||
|
||
(function_declarator declarator: (field_identifier) @name.definition.function) @definition.function | ||
|
||
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @scope name: (identifier) @name.definition.method)) @definition.method | ||
|
||
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type | ||
|
||
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type | ||
|
||
(class_specifier name: (type_identifier) @name.definition.class) @definition.class |
8 changes: 8 additions & 0 deletions
8
...erarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-elisp-tags.scm
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,8 @@ | ||
;; defun/defsubst | ||
(function_definition name: (symbol) @name.definition.function) @definition.function | ||
|
||
;; Treat macros as function definitions for the sake of TAGS. | ||
(macro_definition name: (symbol) @name.definition.function) @definition.function | ||
|
||
;; Match function calls | ||
(list (symbol) @name.reference.function) @reference.function |
54 changes: 54 additions & 0 deletions
54
...rarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-elixir-tags.scm
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,54 @@ | ||
; Definitions | ||
|
||
; * modules and protocols | ||
(call | ||
target: (identifier) @ignore | ||
(arguments (alias) @name.definition.module) | ||
(#match? @ignore "^(defmodule|defprotocol)$")) @definition.module | ||
|
||
; * functions/macros | ||
(call | ||
target: (identifier) @ignore | ||
(arguments | ||
[ | ||
; zero-arity functions with no parentheses | ||
(identifier) @name.definition.function | ||
; regular function clause | ||
(call target: (identifier) @name.definition.function) | ||
; function clause with a guard clause | ||
(binary_operator | ||
left: (call target: (identifier) @name.definition.function) | ||
operator: "when") | ||
]) | ||
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function | ||
|
||
; References | ||
|
||
; ignore calls to kernel/special-forms keywords | ||
(call | ||
target: (identifier) @ignore | ||
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defmodule|defprotocol|defimpl|defstruct|defexception|defoverridable|alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) | ||
|
||
; ignore module attributes | ||
(unary_operator | ||
operator: "@" | ||
operand: (call | ||
target: (identifier) @ignore)) | ||
|
||
; * function call | ||
(call | ||
target: [ | ||
; local | ||
(identifier) @name.reference.call | ||
; remote | ||
(dot | ||
right: (identifier) @name.reference.call) | ||
]) @reference.call | ||
|
||
; * pipe into function call | ||
(binary_operator | ||
operator: "|>" | ||
right: (identifier) @name.reference.call) @reference.call | ||
|
||
; * modules | ||
(alias) @name.reference.module @reference.module |
19 changes: 19 additions & 0 deletions
19
...hierarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-elm-tags.scm
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,19 @@ | ||
(value_declaration (function_declaration_left (lower_case_identifier) @name.definition.function)) @definition.function | ||
|
||
(function_call_expr (value_expr (value_qid) @name.reference.function)) @reference.function | ||
(exposed_value (lower_case_identifier) @name.reference.function)) @reference.function | ||
(type_annotation ((lower_case_identifier) @name.reference.function) (colon)) @reference.function | ||
|
||
(type_declaration ((upper_case_identifier) @name.definition.type) ) @definition.type | ||
|
||
(type_ref (upper_case_qid (upper_case_identifier) @name.reference.type)) @reference.type | ||
(exposed_type (upper_case_identifier) @name.reference.type)) @reference.type | ||
|
||
(type_declaration (union_variant (upper_case_identifier) @name.definition.union)) @definition.union | ||
|
||
(value_expr (upper_case_qid (upper_case_identifier) @name.reference.union)) @reference.union | ||
|
||
|
||
(module_declaration | ||
(upper_case_qid (upper_case_identifier)) @name.definition.module | ||
) @definition.module |
30 changes: 30 additions & 0 deletions
30
...-hierarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-go-tags.scm
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,30 @@ | ||
( | ||
(comment)* @doc | ||
. | ||
(function_declaration | ||
name: (identifier) @name.definition.function) @definition.function | ||
(#strip! @doc "^//\\s*") | ||
(#set-adjacent! @doc @definition.function) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
(method_declaration | ||
name: (field_identifier) @name.definition.method) @definition.method | ||
(#strip! @doc "^//\\s*") | ||
(#set-adjacent! @doc @definition.method) | ||
) | ||
|
||
(call_expression | ||
function: [ | ||
(identifier) @name.reference.call | ||
(parenthesized_expression (identifier) @name.reference.call) | ||
(selector_expression field: (field_identifier) @name.reference.call) | ||
(parenthesized_expression (selector_expression field: (field_identifier) @name.reference.call)) | ||
]) @reference.call | ||
|
||
(type_spec | ||
name: (type_identifier) @name.definition.type) @definition.type | ||
|
||
(type_identifier) @name.reference.type @reference.type |
20 changes: 20 additions & 0 deletions
20
...ierarchy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-java-tags.scm
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,20 @@ | ||
(class_declaration | ||
name: (identifier) @name.definition.class) @definition.class | ||
|
||
(method_declaration | ||
name: (identifier) @name.definition.method) @definition.method | ||
|
||
(method_invocation | ||
name: (identifier) @name.reference.call | ||
arguments: (argument_list) @reference.call) | ||
|
||
(interface_declaration | ||
name: (identifier) @name.definition.interface) @definition.interface | ||
|
||
(type_list | ||
(type_identifier) @name.reference.implementation) @reference.implementation | ||
|
||
(object_creation_expression | ||
type: (type_identifier) @name.reference.class) @reference.class | ||
|
||
(superclass (type_identifier) @name.reference.class) @reference.class |
88 changes: 88 additions & 0 deletions
88
...hy/llama_index/packs/code_hierarchy/pytree-sitter-queries/tree-sitter-javascript-tags.scm
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,88 @@ | ||
( | ||
(comment)* @doc | ||
. | ||
(method_definition | ||
name: (property_identifier) @name.definition.method) @definition.method | ||
(#not-eq? @name.definition.method "constructor") | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.method) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
[ | ||
(class | ||
name: (_) @name.definition.class) | ||
(class_declaration | ||
name: (_) @name.definition.class) | ||
] @definition.class | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.class) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
[ | ||
(function | ||
name: (identifier) @name.definition.function) | ||
(function_declaration | ||
name: (identifier) @name.definition.function) | ||
(generator_function | ||
name: (identifier) @name.definition.function) | ||
(generator_function_declaration | ||
name: (identifier) @name.definition.function) | ||
] @definition.function | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
(lexical_declaration | ||
(variable_declarator | ||
name: (identifier) @name.definition.function | ||
value: [(arrow_function) (function)]) @definition.function) | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
(variable_declaration | ||
(variable_declarator | ||
name: (identifier) @name.definition.function | ||
value: [(arrow_function) (function)]) @definition.function) | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
(assignment_expression | ||
left: [ | ||
(identifier) @name.definition.function | ||
(member_expression | ||
property: (property_identifier) @name.definition.function) | ||
] | ||
right: [(arrow_function) (function)] | ||
) @definition.function | ||
|
||
(pair | ||
key: (property_identifier) @name.definition.function | ||
value: [(arrow_function) (function)]) @definition.function | ||
|
||
( | ||
(call_expression | ||
function: (identifier) @name.reference.call) @reference.call | ||
(#not-match? @name.reference.call "^(require)$") | ||
) | ||
|
||
(call_expression | ||
function: (member_expression | ||
property: (property_identifier) @name.reference.call) | ||
arguments: (_) @reference.call) | ||
|
||
(new_expression | ||
constructor: (_) @name.reference.class) @reference.class |
Oops, something went wrong.