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

add tags.scm queries #15

merged 1 commit into from
Feb 26, 2022

Conversation

the-mikedavis
Copy link
Member

connects #14

I'm not sure I got them all, plus I'd like to add some tests (see tree-sitter/tree-sitter#1547). This PR makes me think that maybe the pub visibility qualifier might want to be its own node under type_definition or function definitions? I think that might simplify the queries but I don't know if that's a good enough reason to refactor nodes. (Also, I use tree-sitter nodes for motion in my editor (see helix-editor/helix#1495) and I think jumping to the pub token could occassionally be valuable, wydt?)

Copy link
Member

@J3RN J3RN left a comment

Choose a reason for hiding this comment

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

Hey @the-mikedavis 👋 Thanks for taking care of this! 🎉

There's one more case that we might consider for function definitions, which would be something like

let foo = fn(x) { x + 1 }

i.e.

(let
  pattern: (identifier)
  value: (anonymous_function))

There's a whole road we could go down w.r.t. patterns and assignment with anonymous functions (what if the lambda is assigned a name in a destructuring of a tuple?) but returns rapidly diminish.


This PR makes me think that maybe the pub visibility qualifier might want to be its own node under type_definition or function definitions?

Yeah, I've debated doing that before. Notably, tree=sitter=rust uses a (visibility_modifier) node for it's common pub keyword and we could do something similar, though we also have to create a modifier node for "opaque".

Opened an issue for this here: #17.

@@ -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.

@@ -0,0 +1,54 @@
; Modules
(module) @name @reference.module
(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. 👍

Comment on lines +39 to +46
(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
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 👍

@the-mikedavis
Copy link
Member Author

Ah interesting. I saw a fn when I was testing and decided to look the other way 😄

I think it's ok for these tags to only work on blatantly obvious function/module/type constructs. That is probably something I would want to cover when writing stack-graphs queries for precise navigation

Copy link
Member

@J3RN J3RN left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 Thanks for this contribution! 🎉

@J3RN J3RN merged commit 5cb3870 into gleam-lang:main Feb 26, 2022
@the-mikedavis the-mikedavis deleted the md-tags-queries branch September 29, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants