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

can not run multi file project #555

Open
tombrus opened this issue Jan 20, 2014 · 14 comments
Open

can not run multi file project #555

tombrus opened this issue Jan 20, 2014 · 14 comments
Assignees
Milestone

Comments

@tombrus
Copy link

tombrus commented Jan 20, 2014

Can not run a func in another file.

When I have one go file I can run fine.
When I have two go files (main using a func in the other), I get an "undefined:" error.

repro:

  • make a new go project
  • create one file:
package main
import "fmt"
func main() {
    fmt.Printf("Hello world!")
    xxx()
}
  • create another file:
package main
import "fmt"
func xxx() {
    fmt.Printf("Hello world again!")
}
  • run the first file and get:
# command-line-arguments
src/gotry.go:7: undefined: xxx

Process finished with exit code 2

My 'internals':

Project dir -> /Users/tom/projects/gotry
GO_GOROOT_PATH -> /usr/local/go
GO_BIN_PATH -> /usr/local/go/bin/go
GO_GOPATH_PATH -> /Users/tom/gocode
TARGET_OS -> Darwin
TARGET_ARCH -> _amd64
VERSION_MAJOR -> go1.1.2 darwin/amd64
VERSION_MINOR -> 
Extended Go Env -> 
SHELL=/bin/bash
TMPDIR=/var/folders/96/rgpc19kj6tx1q67p8mqbr7gr0000gn/T/
__CF_USER_TEXT_ENCODING=0x1F5:0:2
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/tom/gocode/bin:/Users/tom/projects/gotry/bin
GOROOT=/usr/local/go
DISPLAY=/tmp/launch-KuXA1u/org.macosforge.xquartz:0
GOPATH=/Users/tom/gocode:/Users/tom/projects/gotry
USER=tom
COM_GOOGLE_CHROME_FRAMEWORK_SERVICE_PROCESS/USERS/TOM/LIBRARY/APPLICATION_SUPPORT/GOOGLE/CHROME_SOCKET=/tmp/launch-FBuB9z/ServiceProcessSocket
HOME=/Users/tom
LOGNAME=tom
Apple_PubSub_Socket_Render=/tmp/launch-SVekGf/Render
__CHECKFIX1436934=1
SSH_AUTH_SOCK=/tmp/launch-hUIPDS/Listeners
Project dir -> /Users/tom/projects/gotry
/usr/local/go/bin/go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tom/gocode:/Users/tom/projects/gotry"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CGO_ENABLED="1"
Project dir -> /Users/tom/projects/gotry
SHELL=/bin/bash
TMPDIR=/var/folders/96/rgpc19kj6tx1q67p8mqbr7gr0000gn/T/
__CF_USER_TEXT_ENCODING=0x1F5:0:2
PATH=/usr/bin:/bin:/usr/sbin:/sbin
GOROOT=/usr/local/go
DISPLAY=/tmp/launch-KuXA1u/org.macosforge.xquartz:0
GOPATH=/Users/tom/gocode
USER=tom
COM_GOOGLE_CHROME_FRAMEWORK_SERVICE_PROCESS/USERS/TOM/LIBRARY/APPLICATION_SUPPORT/GOOGLE/CHROME_SOCKET=/tmp/launch-FBuB9z/ServiceProcessSocket
HOME=/Users/tom
LOGNAME=tom
Apple_PubSub_Socket_Render=/tmp/launch-SVekGf/Render
SSH_AUTH_SOCK=/tmp/launch-hUIPDS/Listeners
__CHECKFIX1436934=1
@dlsniper
Copy link
Member

Hi,

That's a limitation of go itself, not the plugin, see below (I'm using zsh in case you wonder why my console output looks like that): main() is in untitled6.go, xxx() is in demo.go

florin@XYZ [10:29:29] [/var/www/personal/untitled6] 
-> % /usr/lib/go/bin/go run /var/www/personal/untitled6/src/untitled6.go
# command-line-arguments
src/untitled6.go:7: undefined: xxx
florin@XYZ [10:29:31] [/var/www/personal/untitled6] 
-> % /usr/lib/go/bin/go run src/untitled6.go         
# command-line-arguments
src/untitled6.go:7: undefined: xxx
florin@XYZ [10:29:45] [/var/www/personal/untitled6] 
-> % go run src/untitled6.go    
# command-line-arguments
src/untitled6.go:7: undefined: xxx
florin@XYZ [10:29:53] [/var/www/personal/untitled6] 
-> % go run                 
go run: no go files listed
florin@XYZ [10:29:56] [/var/www/personal/untitled6] 
-> % cd src                 
florin@XYZ [10:30:14] [/var/www/personal/untitled6/src] 
-> % go run
go run: no go files listed
florin@XYZ [10:30:16] [/var/www/personal/untitled6/src] 
-> % go run ./...
go run: no go files listed
florin@XYZ [10:30:21] [/var/www/personal/untitled6/src] 
-> % go run untitled6.go 
# command-line-arguments
./untitled6.go:7: undefined: xxx

If you are able to run this from the command line in and it's not working from the plugin then it should be a problem.

@tombrus
Copy link
Author

tombrus commented Jan 20, 2014

wow, quick reply... ;-)

That was what I first thought, then I stumbled on this thread: https://groups.google.com/forum/#!topic/golang-nuts/dP9SKOsG0AU where Julian Phillips states:

To call a function in another file that is part of the same package you 
just call it, the package defines the scope.

I tried it and when I run

go run *.go

it runs fine. But, indeed, you have to mention both files before it works.

Would it not be a little limiting if everything needs to be in the same go file? Or am I missing something else here?

(but then, I am still exploring go...)

@dlsniper
Copy link
Member

Yeah, well, I'm waiting for a server to configure itself ;)

The statement from Julian is true but in order for it to work you either
have to execute go run like you did or if you want to run it from
IDEA, supply all the files that you need to the ``` Go builder arguments


As I side note: I usually keep a single file in the main package with the
init / main functions and that's about it, the rest of the work goes into
other packages.

Hope it helps.


Btw: Feel free to make a PR to improve the (non-existing) docs with this
use case if you want. Thanks!

----
Florin Patan / @dlsniper <https://twitter.com/dlsniper>
https://github.com/dlsniper
http://www.linkedin.com/in/florinpatan


On Mon, Jan 20, 2014 at 10:57 AM, Tom Brus <notifications@github.com> wrote:

> wow, quick reply... ;-)
>
> That was what I first thought, then I stumbled on this thread:
> https://groups.google.com/forum/#!topic/golang-nuts/dP9SKOsG0AU where
> Julian Phillips states:
>
> To call a function in another file that is part of the same package you
> just call it, the package defines the scope.
>
> I tried it and when I run
>
> go run *.go
>
> it runs fine. But, indeed, you have to mention both files before it works.
>
> Would it not be a little limiting if everything needs to be in the same go
> file? Or am I missing something else here?
>
> (but then, I am still exploring go...)
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/555#issuecomment-32746493>
> .
>

@tombrus
Copy link
Author

tombrus commented Jan 20, 2014

ok, learning here...

I do not exactly know what cmd is fired off when I hit run, but I could imagine it could be turned into a "go run *.go" equivalent...

I chew on it a little, while waiting for my server to configure itself (will take another hour or so ;-)

@tombrus
Copy link
Author

tombrus commented Jan 20, 2014

did some chewing...

Indeed this limitation only applies to the main package.
Creating the same situation in a non main package is handled correctly.

So this probably only confuses the newbee go-er.

I would say the best way is to do the "*go run .go" equivalent when you see multiple files in the main package. This will not have any downsides when, as you describe is your standard way, you only have a single file in your main package. Easy change (right?), less confusion. After all it is worthwhile that newbee's stay on board!

I leave it up to the plugin developer to judge this enhancement request.

Anyway, thanks for writing the plugin!

Tom

@dlsniper
Copy link
Member

I think it could be added, as an option, just like the ones we have for running tests, shouldn't be a problem.
But it's definitely not on the high priority list right now (unless someone else wants to do it).

I'll close the issue and open a new one for the feature request.

@dlsniper
Copy link
Member

As for the command(s) that are run when you trigger a certain go action in the IDE, it should always be the first line of output in the console / window / tool panel :)

@mtoader
Copy link
Member

mtoader commented Jan 20, 2014

There a non so subtle thing at play here. You can imagine having two completely different main programs in the same folder (unrelated to each other). But if they are in the same folder they will have the same package name. This will confuse everyone when you try go run *.go.

To be more clear imagine the following scenario:

src/binary1.go:

package main

func main() {
    print("i'm the first binary");
}
`src/binary2.go`

package main

func main() {
   print("i'm the second binary");
}

What happens if you do a go run *.go ? normally you would have to a go run <files that belong to the same binary> but you can't do that without a semantic analysis. That's why i think the custom in go land is to put all the files belonging to a binary inside a folder or put all the code in libraries and just have a main entry point somewhere.

For now the current behaviour will do. Maybe later on we can add better analysis and do an automatic run (with the proper file list).

@tombrus
Copy link
Author

tombrus commented Jan 20, 2014

I thought about that scenario to: mutliple 'main' entries for the same code base. I guess you could 'go run' the main file plus all files NOT containing a main(). Only a heuristic solution I agree, someone might have two non-main() files each belonging to a separate main() containing file and these non-main() files could contain the same func's. My proposed strategy above would result in a redeclaration error probably.

But then this is not so high prio I agree, it just confused me and made me put a growing amount of code in my first real go file :-), learning, learning...

Put it on the list, others can find this discussion now, that will probably help enough for now.

Keep up the good work!
-Tom

@mtoader
Copy link
Member

mtoader commented Jan 20, 2014

tentatively targeted for 1.0.0

@dlsniper dlsniper modified the milestones: 1.0.0, 0.9.18 Feb 2, 2015
@ignatov ignatov removed this from the 0.9.18 milestone Feb 8, 2015
@tombrus tombrus removed this from the 0.9.18 milestone Feb 8, 2015
@dlsniper dlsniper added this to the 1.next milestone Feb 12, 2015
@ignatov ignatov assigned zolotov and unassigned ignatov Feb 14, 2015
@ignatov ignatov modified the milestones: 1.0.0, 1.next Feb 14, 2015
@kingcrunch
Copy link

Hi @dlsniper (or whoever I've to tag ;))

I know, how this sounds, but this issue is pushed forward since the beginning of 2014. It would be nice

Right now I help myself by just leaving the "File" field empty. The IDE constantly complains about an invalid run configuration and when I run it, I have to "Continue anyway", but after that it works :)

However, I'd really appreciate, if this actually quite common setup would be supported out of the box.

Thanks

@dlsniper
Copy link
Member

Hi @kingcrunch.

I do understand the frustration on the matter so let me give you a bit of context.
The issue is pushed back since 2014 as back then we had a different plugin (the current one is a complete rewrite by Sergey and Alexander with some contributions from me and other community members) / different setup for team that makes the plugin and so on.
However, in on itself, the issue is still valid, that's why it's still open.

Have you tried the package run configuration type? Does that help solving the issue for you? You can find this under Run | Edit Configurations | + | Go Application | Run kind....
This will produce a binary and run it afterwards. There's a request to unify the run configurations so hopefully this will become a bit more clear then.

If this doesn't help unfortunately there's not much I can do right now (and I guess others are busy as well) so the best way to have this faster would be to help out with some of the issues in the plugin (maybe even this one). I know it's not ideal but unfortunately that's the state of things.

Thank you for your understanding and Thank you! for not just +1-ing this.

Kind regards,
Florin

@yanickxia
Copy link

@kingcrunch Thanks, i make Run Kind File and File is . it's work. thanks for you

@DipenModi
Copy link

How to set/configure "Run | Edit Configurations | + | Go Application" this on visual studio code editor.

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

No branches or pull requests

8 participants