Skip to content

Can we extract embedded struct in different packages? #187

@officialasishkumar

Description

@officialasishkumar

Here is the code snippet

package complex

import "fmt"

type stats struct {
	healthBar health
}

type king struct {
	firstName string
	lastName  string
	age       int
	stats     stats
}

func findKing() {
	kingbladwin := king{
		firstName: "Bladwin",
		lastName:  "King",
		age:       30,
		stats: stats{
			healthBar: health{
				current: 100,
				stamina: "100",
				injury: injurystats{
					injuryType: "broken leg",
					injuryLevel: 10,
					injuryDuration: 10,
				},
			},
		},
	}

	fmt.Println(kingbladwin)
}

I want to use tree sitter to extract all the struct if i give my code a function (lets say findKing)

currently im able to extract all the structs that are defined in the same file and used in function which is invoked for but im not able to get the structs which are not in this file (im passing the file as well in my code). The struct can lie in same package or different package.

Is there any way i can find all the struct the function is using?

expected output:

=== Structs used by function 'findKing' ===

struct tree-sitter/test_files/complex.stats {
    healthBar tree-sitter/test_files/complex.health
}

struct tree-sitter/test_files/complex.health {
    current int
    stamina string
    injury tree-sitter/test_files/complex.injurystats
    findme tree-sitter/test_files/complex/more.Find
}

struct tree-sitter/test_files/complex.injurystats {
    injuryType string
    injuryLevel int
    injuryDuration int
    injuryLocation string
    injurySeverity int
    injuryCause string
    injuryTreatment string
    injuryRecoveryTime int
    injuryRecoveryProgress int
    injuryLinked tree-sitter/test_files/linked.Strange
}

struct tree-sitter/test_files/linked.Strange {
    Miles int
}

struct tree-sitter/test_files/complex/more.Find {
    Name string
}

struct tree-sitter/test_files/complex.king {
    firstName string
    lastName string
    age int
    stats tree-sitter/test_files/complex.stats
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions