tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
341 stars 104 forks source link

extends interfaces seem to render incorrectly #202

Closed miki725 closed 2 years ago

miki725 commented 2 years ago

The following piece of code is valid but it is rendered incorrectly:

type Things = { foo: string };

export class Foo<
    Name extends keyof Things,
    Subtype extends Things[Name],
> {
    public foo(_a: Name, _b: Subtype) {}
}

Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:

https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgFgSwHYHMDOUC8UDeUBmA9oQFxRrABOyKUAvgNwBQTEAHmIZcFAMYA2AQzQYAYsQA8TKDKgA5QQFto7YBCQATDAGsIIQvliJUaADTTZAZQCuAI1CQoq9VqM00AbQXKAuuYB8uBYyYHb8CLwExAAUAPqCZN4QplCxtmQ29uAQAJS4dEx0QA

The output of tree-sitter parse is the following:

$ tree-sitter parse test.ts
(program [0, 0] - [8, 0]
  (type_alias_declaration [0, 0] - [0, 30]
    name: (type_identifier [0, 5] - [0, 11])
    value: (object_type [0, 14] - [0, 29]
      (property_signature [0, 16] - [0, 27]
        name: (property_identifier [0, 16] - [0, 19])
        type: (type_annotation [0, 19] - [0, 27]
          (predefined_type [0, 21] - [0, 27])))))
  (export_statement [2, 0] - [7, 1]
    declaration: (class_declaration [2, 7] - [7, 1]
      name: (type_identifier [2, 13] - [2, 16])
      type_parameters: (type_parameters [2, 16] - [5, 1]
        (type_parameter [3, 4] - [3, 29]
          name: (type_identifier [3, 4] - [3, 8])
          constraint: (constraint [3, 9] - [3, 29]
            (index_type_query [3, 17] - [3, 29]
              (type_identifier [3, 23] - [3, 29]))))
        (type_parameter [4, 4] - [4, 32]
          name: (type_identifier [4, 4] - [4, 11])
          constraint: (constraint [4, 12] - [4, 32]
            (lookup_type [4, 20] - [4, 32]
              (type_identifier [4, 20] - [4, 26])
              (type_identifier [4, 27] - [4, 31])))))
      body: (class_body [5, 2] - [7, 1]
        (method_definition [6, 4] - [6, 40]
          (accessibility_modifier [6, 4] - [6, 10])
          name: (property_identifier [6, 11] - [6, 14])
          parameters: (formal_parameters [6, 14] - [6, 37]
            (required_parameter [6, 15] - [6, 23]
              pattern: (identifier [6, 15] - [6, 17])
              type: (type_annotation [6, 17] - [6, 23]
                (type_identifier [6, 19] - [6, 23])))
            (required_parameter [6, 25] - [6, 36]
              pattern: (identifier [6, 25] - [6, 27])
              type: (type_annotation [6, 27] - [6, 36]
                (type_identifier [6, 29] - [6, 36]))))
          body: (statement_block [6, 38] - [6, 40]))))))

in typescript playground it renders as:

image

in neovim without treesitter same typescript file is rendered as:

image

simply enabling treesitter with typescript support it starts rendering as:

image

given that default theme works as expected not sure if this some issue with my vim setup or treesitter (Im just giving it a shot so cant point to any configs). any pointers?

maxbrunsfeld commented 2 years ago

This repo is just the parser, so unless the parse tree is wrong, you should open the issue on the Neovim repo.

miki725 commented 2 years ago

looks like this an issue with the theme with not enough color definitions treesitter sets when parsing syntax more accurately