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

x/tools/gopls: consider supporting script directories with multiple programs #41206

Open
stamblerre opened this issue Sep 3, 2020 · 4 comments
Open

Comments

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Sep 3, 2020

Currently, gopls only supports directories with a single main, no matter whether you open a single file or a directory. For single files, we load the entire directory, no matter what. Some users create directories with multiple mains, which they run using go run file.go. Should gopls support such directories? If so, how should it work?

@bcmills
Copy link
Member

@bcmills bcmills commented Sep 4, 2020

Most single files intended for use with go run should be tagged // +build ignore or similar, and they necessarily each declare a func main. Perhaps you could use unusual build constraints plus func main as a heuristic for which mode to use?

@myitcv
Copy link
Member

@myitcv myitcv commented Sep 4, 2020

Previous discussion: #33595

@myitcv
Copy link
Member

@myitcv myitcv commented Sep 4, 2020

Looking at the arguments against this, if someone can come up with a good enough name for the file that contains the build-ignore main package, they can use that name for a subdirectory ./internal/$NAME thereby obviating the need for any kind of single-file support in gopls.

The counter argument to this is that there is lots of preexisting code out there that does following the single-file approach.

@stamblerre stamblerre removed this from the Unreleased milestone Dec 16, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Dec 16, 2020
@mvdan
Copy link
Member

@mvdan mvdan commented Jan 3, 2021

Perhaps you could use unusual build constraints plus func main as a heuristic for which mode to use?

I think this would work reasonably well. I think it would have covered nearly all the times I've encountered gopls to error in this way.

they can use that name for a subdirectory ./internal/$NAME thereby obviating the need for any kind of single-file support in gopls.

While I see the point, I disagree. There's nothing wrong with build-tag-ignored one-off programs being part of an existing package. An extra directory with just one file will be more verbose, and an oddity that has never been needed in Go before. Coming up to all those users and telling them they need to change their workflow just to please gopls, and objectively for no other good reason, seems like it won't end well :)

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

Successfully merging a pull request may close this issue.

None yet
5 participants