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

feature: Node of key type in dictionary-like tables #11

Open
1 task done
HiPhish opened this issue Aug 14, 2024 · 0 comments
Open
1 task done

feature: Node of key type in dictionary-like tables #11

HiPhish opened this issue Aug 14, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@HiPhish
Copy link

HiPhish commented Aug 14, 2024

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

Maintainer of HiPhish/rainbow-delimiters.nvim here; I have a problem matching the key of a dictionary-like table type annotation. According to the documentation we can document the type of a dictionary-like table as follows:

@type { [string]: VALUE_TYPE }

However, currently [, string and ] are three top-level field nodes:

(table_literal_type
  "{"
  field: "["
  field: (builtin_type
    "string")
  field: "]"
  ":"
  (identifier)
  "}")

There is no one container-like node which would contain the three other nodes. This makes it impossible to build a tree of nested delimiters.

Describe the solution you'd like

I propose grouping the three above nodes under one common node:

(table_literal_type
  "{"
  field: (dict_key_type
    "["
    (builtin_type
      "string")
    "]")
  ":"
  (identifier)
  "}")

The name dict_key_type is just something off the top of my head, I don't have any particular opinion on what the new node should be named.

Describe alternatives you've considered

Matching the delimiters is not a problem in itself, I already have a pattern for that in place:

(_
  "[" @delimiter
  .
  field: (_)
  .
  "]" @delimiter @sentinel) @container

The problem with this pattern is that now the container node of this match is on the same level as the parent container. This messes up the algorithm for determining which colour to use for which delimiter.

Additional context

No response

@HiPhish HiPhish added the enhancement New feature or request label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant