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

function generated by Wire_gen.go "Cannot find declaration to go to" by Golang JetBrains but still run success #374

Open
Nghiait123456 opened this issue Sep 14, 2022 · 5 comments

Comments

@Nghiait123456
Copy link

Nghiait123456 commented Sep 14, 2022

I have main

package main

func main() {


	c, _ := ProviderCCCCCC()
	c.View()
	c.B().Show()
	c.A().Show()
	c.View()

}

i have wire.go :

//go:build wireinject
// +build wireinject

package main

import (
	"database/sql"
	"github.com/google/wire"
	"google.golang.org/grpc"
	"net"
	"wire_best_practice/b"
	"wire_best_practice/c"
	"wire_best_practice/repo"
	"wire_best_practice/rpci"
	"wire_best_practice/service"
)

func NewListener() (net.Listener, error) {
	return net.Listen("tcp4", "0.0.0.0:5000")
}

func NewGRPCServer() *grpc.Server {
	return grpc.NewServer()
}

func DBConn() (*sql.DB, error) {
	return sql.Open("mysql", "127.0.0.1:3306")
}

func initApp() (*App, error) {
	wire.Build(
		rpci.New,
		NewListener,
		NewGRPCServer,
		repo.Provider,
		DBConn,
		service.Provider,
		wire.Struct(new(App), "*"),
	)

	return &App{}, nil
}

func ProviderB() (b.BInterface, error) {
	wire.Build(
		b.ProviderB,
	)

	return &b.B{}, nil
}

func ProviderCCCCCC() (c.CInterface, error) {
	wire.Build(
		c.ProviderC,
	)

	return &c.C{}, nil
}

and wire_gen.go

// Code generated by Wire. DO NOT EDIT.

//go:generate go run github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject

package main

import (
	"database/sql"
	"google.golang.org/grpc"
	"net"
	"wire_best_practice/a"
	"wire_best_practice/b"
	"wire_best_practice/c"
	"wire_best_practice/repo"
	"wire_best_practice/rpci"
	"wire_best_practice/service"
)

// Injectors from wire.go:

func initApp() (*App, error) {
	listener, err := NewListener()
	if err != nil {
		return nil, err
	}
	server := NewGRPCServer()
	db, err := DBConn()
	if err != nil {
		return nil, err
	}
	repoDB := repo.New(db)
	serviceService := service.New(repoDB)
	rpciServer := rpci.New(serviceService, server)
	app := &App{
		listener: listener,
		gsrv:     server,
		rpcImpl:  rpciServer,
	}
	return app, nil
}

func ProviderB() (b.BInterface, error) {
	a2 := a.NewA2()
	bB := b.NewB(a2)
	return bB, nil
}

func ProviderCCCCCC() (c.CInterface, error) {
	a2 := a.NewA2()
	bB := b.NewB(a2)
	cC := c.NewC(bB, a2)
	return cC, nil
}

// wire.go:

func NewListener() (net.Listener, error) {
	return net.Listen("tcp4", "0.0.0.0:5000")
}

func NewGRPCServer() *grpc.Server {
	return grpc.NewServer()
}

func DBConn() (*sql.DB, error) {
	return sql.Open("mysql", "127.0.0.1:3306")
}

every run success but, JetBrain Ide show error "Cannot find declaration to go to" in file wire_gen.go.
Is there any way for this problem . Thanks all.

@Nghiait123456
Copy link
Author

Uploading Screenshot from 2022-09-14 10-58-07.png…

@Nghiait123456
Copy link
Author

Screenshot from 2022-09-14 10-58-07

@Nghiait123456
Copy link
Author

@766800551

please share me name of this plugin. i use golang ide of jetbrain and i don't find packet recommended

@Nghiait123456
Copy link
Author

@766800551
please share me name of this plugin. i use golang ide of jetbrain and i don't find packet recommended

The name of the plugin is go-wire-util

https://plugins.jetbrains.com/plugin/19395-go-wire-util

oh, something went wrong, i used it but not auto recommended, if i call form other file in same packet, ide dont find defind, still error: "Cannot find declaration to go to"

@Nghiait123456
Copy link
Author

Nghiait123456 commented Sep 23, 2022

@766800551 i used it, but packet only suggest link from in wire_gen to other, don't have link from other to wire_gen.go

error: ""Cannot find declaration to go to""

//go:generate go run github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject

this line was blocked for ide go to define code in wire_gen.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant