mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
feat: add an example locals query
This will be the guide for the implementation of locals extraction, which is treesitters name of definition/scope.
This commit is contained in:
parent
e51b25dce2
commit
00f871ab51
1 changed files with 45 additions and 0 deletions
45
queries/lua/locals.scm
Normal file
45
queries/lua/locals.scm
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
;;; DECLARATIONS AND SCOPES
|
||||
|
||||
;; Variable and field declarations
|
||||
((variable_declarator
|
||||
(identifier) @definition)
|
||||
(set! kind "v"))
|
||||
|
||||
((variable_declarator
|
||||
(field_expression object:(*) @definition.associated (property_identifier) @definition))
|
||||
(set! kind "v"))
|
||||
|
||||
;; Parameters
|
||||
((local_function
|
||||
(parameters (identifier) @definition))
|
||||
(set! kind "v"))
|
||||
((function
|
||||
(parameters (identifier) @definition))
|
||||
(set! kind "v"))
|
||||
|
||||
;; Function definitions
|
||||
;; Functions definitions creates both a definition and a new scope
|
||||
((function
|
||||
(function_name_field
|
||||
object: (identifier) @definition.associated
|
||||
(property_identifier) @definition)) @scope
|
||||
(set! kind "m"))
|
||||
|
||||
((function
|
||||
(function_name (identifier) @definition)) @scope
|
||||
(set! kind "f"))
|
||||
|
||||
((local_function
|
||||
(identifier) @definition) @scope
|
||||
(set! kind "f"))
|
||||
|
||||
((if_statement) @scope)
|
||||
((for_in_statement) @scope)
|
||||
((repeat_statement) @scope)
|
||||
;; Loops
|
||||
((loop_expression
|
||||
(identifier) @definition)
|
||||
(set! kind "v"))
|
||||
|
||||
;;; REFERENCES
|
||||
((identifier) @reference)
|
||||
Loading…
Add table
Add a link
Reference in a new issue