balpan-rs / balpan

Simple CLI Tool that supports your onboarding for a journey on source code.
37 stars 7 forks source link

(rust) Fix a bug where accessing name of impl node for struct(not for trait) raises error #59

Closed malkoG closed 1 year ago

malkoG commented 1 year ago

Here is intuitive example.

Code snippet:

impl Foo {

}

impl Foo for Bar {

}

Syntax Tree:

source_file [0, 0] - [7, 0]
  impl_item [0, 0] - [2, 1]
    type: type_identifier [0, 5] - [0, 8]
    body: declaration_list [0, 9] - [2, 1]
  impl_item [4, 0] - [6, 1]
    trait: type_identifier [4, 5] - [4, 8]
    type: type_identifier [4, 13] - [4, 16]
    body: declaration_list [4, 17] - [6, 1]

That is, If we want to access name of impl for struct, we have to access named child node type. If we want to access name of impl for trait, we have to access named child node trait.