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

Capture group for module names #38

Closed
andrhua opened this issue Jul 31, 2022 · 3 comments
Closed

Capture group for module names #38

andrhua opened this issue Jul 31, 2022 · 3 comments

Comments

@andrhua
Copy link

andrhua commented Jul 31, 2022

Not sure where to ask this, but let's start small.

Here #16 modules were given @module capture group. IIUC that was done basically to cater Github TS highlighter, which somehow has color for @module but not for @type. Again, correct me if I'm wrong, nothing really stops, for example, proprietary IDE's TS plugin to recognize only @class as capture group for classes, namespaces, modules etc. At the same time, nvim-treesitter could recognize only @namespace as capture group for the same entites.

tree-sitter docs to me reads like you're entitled to have arbitrary capture groups, which is kinda reasonable, given that each language has its own set of entities. So there's no fixed set of capture group names for related entities, and I don't know whether there might be any consensus at all?

@the-mikedavis
Copy link
Member

Yes: which captures to use are arbitrary for any tree-sitter consumer (editors, difftastic, tree-sitter-cli, GitHub, etc). Typically a consumer will map the name of a capture to some color. For example, tree-sitter-cli maps capture names to a terminal 256-color https://github.com/tree-sitter/tree-sitter/blob/3739b7794e381582c8f4a37b2ccec756c3504984/cli/src/highlight.rs#L145-L177.

Different consumers may have different conventions. I know nvim and helix use @namespace for modules but github and tree-sitter-cli use @module

@jonatanklosko
Copy link
Member

Also note that we do provide highlight captures as part of this repo and it is used by GitHub, so we try to keep it in line with GitHub and tree-sitter-cli. The consumer can define their own captures to define whatever groups and names they see fit (e.g. nvim-treesitter) :)

@andrhua
Copy link
Author

andrhua commented Aug 1, 2022

ok thx guys, I'll use :TSEditQueryUserAfter then

@andrhua andrhua closed this as completed Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants