Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags for types and operators #109

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 108 additions & 54 deletions queries/tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,99 @@

(
(comment)? @doc .
(module_definition (module_binding (module_name) @name) @definition.module)
(module_definition
(module_binding name: (module_name) @name) @definition.module
)
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

(module_path (module_name) @name) @reference.module
(extended_module_path (module_name) @name) @reference.module

; Module types
;--------------

(
(comment)? @doc .
(module_type_definition (module_type_name) @name) @definition.interface
(module_type_definition name: (module_type_name) @name) @definition.interface
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

(module_type_path (module_type_name) @name) @reference.implementation


; Classes
;--------

(
(comment)? @doc .
[
(class_definition
(class_binding name: (class_name) @name) @definition.class
)
(class_type_definition
(class_type_binding name: (class_type_name) @name) @definition.class
)
]
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

[
(class_path (class_name) @name)
(class_type_path (class_type_name) @name)
] @reference.class

(
(comment)? @doc .
(method_definition name: (method_name) @name) @definition.method
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

(method_invocation (method_name) @name) @reference.call


; Types
;------

(
(comment)? @doc .
(type_definition
(type_binding
name: [
(type_constructor) @name
(type_constructor_path (type_constructor) @name)
]
) @definition.type
)
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

(type_constructor_path (type_constructor) @name) @reference.type

[
(constructor_declaration (constructor_name) @name)
(tag_specification (tag) @name)
] @definition.enum_variant

[
(constructor_path (constructor_name) @name)
(tag) @name
] @reference.enum_variant

(field_declaration (field_name) @name) @definition.field

(field_path (field_name) @name) @reference.field


; Functions
;----------

(
(comment)? @doc .
(value_definition
[
(let_binding pattern: (value_name) @name (parameter))
(let_binding
pattern: (value_name) @name
(parameter))
(let_binding
pattern: (value_name) @name
body: [(fun_expression) (function_expression)])
body: [(fun_expression) (function_expression)]
)
] @definition.function
)
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
Expand All @@ -46,71 +108,63 @@
)

(application_expression
function: (value_path (value_name) @name)) @reference.call
function: (value_path (value_name) @name)
) @reference.call

(infix_expression
left: (value_path (value_name) @name)
operator: (concat_operator) @reference.call
(#eq? @reference.call "@@"))
(#eq? @reference.call "@@")
)

(infix_expression
operator: (rel_operator) @reference.call
right: (value_path (value_name) @name)
(#eq? @reference.call "|>"))
(#eq? @reference.call "|>")
)

; Operator
;---------

; Operators
;----------

(
(comment)? @doc .
(value_definition
(let_binding
pattern: (parenthesized_operator (_) @name)) @definition.function)
[
(let_binding pattern: (parenthesized_operator (_) @name) (parameter))
(let_binding
pattern: (parenthesized_operator (_) @name)
body: [(fun_expression) (function_expression)]
)
] @definition.operator
)
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)

[
(prefix_operator)
(sign_operator)
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
(hash_operator)
(indexing_operator)
(let_operator)
(let_and_operator)
(match_operator)
] @name @reference.call
(application_expression
function: (value_path (parenthesized_operator (_) @name))
) @reference.call

; Classes
;--------
(infix_expression
left: (value_path (parenthesized_operator (_) @name))
operator: (concat_operator) @reference.call
(#eq? @reference.call "@@")
)

(
(comment)? @doc .
[
(class_definition (class_binding (class_name) @name) @definition.class)
(class_type_definition (class_type_binding (class_type_name) @name) @definition.class)
]
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
(infix_expression
operator: (rel_operator) @reference.call
right: (value_path (parenthesized_operator (_) @name))
(#eq? @reference.call "|>")
)

[
(class_path (class_name) @name)
(class_type_path (class_type_name) @name)
] @reference.class
(prefix_expression operator: (prefix_operator) @name) @reference.call

; Methods
;--------
(hash_expression operator: (hash_operator) @name) @reference.call

(
(comment)? @doc .
(method_definition (method_name) @name) @definition.method
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
)
(infix_expression operator: (_) @name) @reference.call

(method_invocation (method_name) @name) @reference.call
(indexing_operator_path (indexing_operator) @name) @reference.call

(value_definition [(let_operator) (let_and_operator)] @name) @reference.call

(match_expression (match_operator) @name) @reference.call
2 changes: 1 addition & 1 deletion test/tags/functions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ external f : 'a -> 'a = "id"
(* ^ definition.function *)

let ( + ) a b = a + b
(* ^ definition.function *)
(* ^ definition.operator *)
(* ^ reference.call *)
27 changes: 27 additions & 0 deletions test/tags/types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type t = int
(* ^ definition.type *)
(* ^ reference.type *)

type t = A of int | B
(* ^ definition.type *)
(* ^ definition.enum_variant *)
(* ^ definition.enum_variant *)

let a = A 0
(* ^ reference.enum_variant *)

type t = [`A of int | `B]
(* ^ definition.type *)
(* ^ definition.enum_variant *)
(* ^ definition.enum_variant *)

let a = `A 0
(* ^ reference.enum_variant *)

type t = {field : int}
(* ^ definition.type *)
(* ^ definition.field *)

let x = {field = 0}.field
(* ^ reference.field *)
(* ^ reference.field *)
Loading