(typeNode: SyntaxNode | null, source: string)
| 51 | * exactly as before. |
| 52 | */ |
| 53 | export function rustImplTypeName(typeNode: SyntaxNode | null, source: string): string | undefined { |
| 54 | if (!typeNode) return undefined; |
| 55 | switch (typeNode.type) { |
| 56 | case 'type_identifier': |
| 57 | case 'identifier': |
| 58 | return getNodeText(typeNode, source); |
| 59 | // `Foo<T>` — the `type` field is the bare (or scoped) name, never the args. |
| 60 | case 'generic_type': |
| 61 | return rustImplTypeName(getChildByField(typeNode, 'type'), source); |
| 62 | // `m::Foo` — the last segment is the type's name. |
| 63 | case 'scoped_type_identifier': |
| 64 | case 'scoped_identifier': |
| 65 | return rustImplTypeName(getChildByField(typeNode, 'name'), source); |
| 66 | // `&Foo` / `&'a mut Foo` — the referenced type. |
| 67 | case 'reference_type': |
| 68 | return rustImplTypeName(getChildByField(typeNode, 'type'), source); |
| 69 | default: |
| 70 | return undefined; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * The type an item written directly in an `impl` block belongs to: `ValueHint` |
no test coverage detected