Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't find struct in a same package

suddenly, vscode cannot get access struct in the same package,but different files.

the error showed undefined struct

Previously vscode was able to instantiate struct across files(vscode+go1.12.4)

the sample code like this:

file1 a.go

package main

import "fmt"

type su struct {
    Sfd string
    Sf  int
}

func (sed *su) do() {
    fmt.Println(sed.Sfd + string(sed.Sf))
}


file2 main.go

package main

import "fmt"

func main() {
    d := su{}
    fmt.Println(d)
}

these two files are in the same package

have some one met the same problem?

like image 510
Cosmo Avatar asked Oct 26 '25 12:10

Cosmo


2 Answers

Actually, the language server sometimes crashes. Open the Command Palette and type „language server“. A command should be shown that says „restart language server“. Restarting VSCode might be sufficient.

like image 183
Markus W Mahlberg Avatar answered Oct 28 '25 01:10

Markus W Mahlberg


In GoLand, you can change the Run kind from file to Package.

enter image description here

like image 27
tzJacky Avatar answered Oct 28 '25 02:10

tzJacky