feat: first version of locals

Locals will be the main interface to treesitter, through some functions:
    get_definitions(bufnr) : returns all the definitions in bufnr
    get_scopes(bufnr): returns all definitions in bufnr
    get_references(bufnr): returns all references in bufnr
This commit is contained in:
Thomas Vigouroux 2020-04-19 09:53:44 +02:00
parent f784a0adda
commit b706c4e8ed
2 changed files with 90 additions and 8 deletions

View file

@ -3,19 +3,19 @@
;; Variable and field declarations
((variable_declarator
(identifier) @definition)
(set! kind "v"))
(set! definition.kind "v"))
((variable_declarator
(field_expression object:(*) @definition.associated (property_identifier) @definition))
(set! kind "v"))
(set! difinition.kind "v"))
;; Parameters
((local_function
(parameters (identifier) @definition))
(set! kind "v"))
(set! definition.kind "v"))
((function
(parameters (identifier) @definition))
(set! kind "v"))
(set! definition.kind "v"))
;; Function definitions
;; Functions definitions creates both a definition and a new scope
@ -23,15 +23,15 @@
(function_name_field
object: (identifier) @definition.associated
(property_identifier) @definition)) @scope
(set! kind "m"))
(set! definition.kind "m"))
((function
(function_name (identifier) @definition)) @scope
(set! kind "f"))
(set! definition.kind "f"))
((local_function
(identifier) @definition) @scope
(set! kind "f"))
(set! definition.kind "f"))
((if_statement) @scope)
((for_in_statement) @scope)
@ -39,7 +39,7 @@
;; Loops
((loop_expression
(identifier) @definition)
(set! kind "v"))
(set! definition.kind "v"))
;;; REFERENCES
((identifier) @reference)