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
proposal: cmd/go: add Transparent Folders in Go #63745
Comments
This change wouldn't be limited to gopls, all go tooling which don't operate directly on |
The suggestion of a folder like "_folder" (starts with an underscore) not being considered by the the go tool by default is already implemented in Go. See the last paragraph of https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns:
An example of that is in the x/website repository: it has a "_content" directory for website content rather than Go packages. |
@dmitshur it does not behave as they suggest: a> tree
.
|-- _folder
| `-- b.go
|-- a.go
`-- go.mod // a.go
package main
func main() {
a()
} // b.go
package main
import "fmt"
func a() {
fmt.Println("Hello world")
} a> go run .
# aaa
./a.go:4:2: undefined: a https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns is thus more breaking changes. |
@Jorropo I misunderstood the original proposal, sorry. Indeed, the behavior of having a prefix in front of a folder name makes the go tool ignore its contents, not act as if its contents are in the parent directory as your described. |
Just name your files aaa-foo.go aaa-bar.go bbb-foo.go bbb-bar.go instead of aaa/foo.go aaa/bar.go bbb/foo.go bbb/bar.go. Adding a sub-folder makes everything more complicated for no net benefit. Put the files where they are supposed to be. We've seen the alternative in other languages, and it is bad. |
This proposal has been declined as infeasible. |
Feature Request: Transparent Folders in Go
In Go, folders serve as packages by default. While this is convenient, there are scenarios where we need folders for purely organizational and readability purposes, without introducing new packages.
I propose the concept of "transparent folders" denoted by using a semantic such as "(folder)" or "_folder” seen in for instance the Next.js app router.
These folders would act as a way to organize files within a package without creating new packages. They would remain linked to the package's root.
The text was updated successfully, but these errors were encountered: