dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

Go layer - cannot run `main` in the way VSCode does #387

Closed stradicat closed 3 years ago

stradicat commented 3 years ago

I'm doing a simple exercise in Go, which is comprised of 2 files:

So far, nothing unseen in other programming languages.

main.go:

func main(){
    variable := deck{"element1", "element2"} // if correctly imported, `deck` is a mnemonic type alias for `[]string`

    cards.print()
}

deck.go:

import "fmt"

type deck []string // now 'deck' is a type alias for `[]string`
    func (x deck) string {
        for i, card := range d { // for index and element ’card’ in all indexes in slice ‘cards’, print index and element
    fmt.Println(i, card)
     }

|

However, when hitting M-return x x to invoke go-run-main, I get an error message:

# command line arguments
./main.go:8:11: undefined: deck

This may happen because go-run-main is running go run main.go, without additional files. Thing is, for a correct output, what should be run is go run main.go deck.go, as apparently VSCode does, since the latter shows the expected output: a printout of elements via the mentioned print() function above.

My question is: how can the go-run-main be customized, so that additional files can be added (or detected) as parameters?

dominikh commented 3 years ago

go-run-main does not seem to be a function defined in go-mode.

stradicat commented 3 years ago

Thanks for the prompt reply, I'll ask the Spacemacs maintainers, where the behavior was identified. Cheers!