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.scm queries #15

Merged
merged 1 commit into from
Feb 26, 2022
Merged
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
54 changes: 54 additions & 0 deletions queries/tags.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
; Modules
(module) @name @reference.module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a bit weird for GitHub, etc, since the (module) nodes' contents will look like "gleam/json" (etc), which is different from it's other references in this file (just "json"). That said, what you have here is technically correct 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah maybe we should be splitting the module tokens in an import? The basic code navigation is a bit fuzzy so I think some awkwardness with imports is ok. Elixir has some troubles too when it comes to aliases.

(import alias: (identifier) @name) @reference.module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's a bit hand-wavy too since the alias is just what the module will be called in this file, but this seems close enough that we should keep it. 👍

(remote_type_identifier
module: (identifier) @name) @reference.module
((field_access
record: (identifier) @name)
(#is-not? local)) @reference.module

; Functions
(function
name: (identifier) @name) @definition.function
(public_function
name: (identifier) @name) @definition.function
(external_function
name: (identifier) @name) @definition.function
(public_external_function
name: (identifier) @name) @definition.function
(unqualified_import (identifier) @name) @reference.function
((function_call
function: (identifier) @name) @reference.function
(#is-not? local))
((field_access
record: (identifier) @ignore
field: (label) @name)
(#is-not? local)) @reference.function
((binary_expression
operator: "|>"
right: (identifier) @name)
(#is-not? local)) @reference.function

; Types
(public_type_definition
(type_name
name: (type_identifier) @name)) @definition.type
(type_definition
(type_name
name: (type_identifier) @name)) @definition.type
(public_type_definition
(type_constructors
(type_constructor
name: (type_identifier) @name))) @definition.type
(type_definition
(type_constructors
(type_constructor
name: (type_identifier) @name))) @definition.type
Comment on lines +39 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically a data constructor (here mislabeled as "type_constructor"; the actual type constructors are above as "type_name") isn't a type definition. That said, I'm open to keeping this if it has nice properties when integrating into GitHub or other systems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah I wasn't sure about this. I think this ends up working out well because you can jump between usages of data constructors and their definitions. The suffix in definition.<kind> or reference.<kind> doesn't have to be module|function|type, we could distinguish these as data_constructor. OTOH it works out nicely to just label all remaining type_identifiers as reference.type. I'm not sure what the best move is 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now we'll keep it as-is 👍

(external_type
(type_name
name: (type_identifier) @name)) @definition.type
(public_external_type
(type_name
name: (type_identifier) @name)) @definition.type

(type_identifier) @name @reference.type