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

proposal: cmd/go: add Transparent Folders in Go #63745

Closed
codcodea opened this issue Oct 25, 2023 · 6 comments
Closed

proposal: cmd/go: add Transparent Folders in Go #63745

codcodea opened this issue Oct 25, 2023 · 6 comments
Labels
Milestone

Comments

@codcodea
Copy link

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.

myapp
  main.go
  myTypes.go
  (routes)
     handleRoot.go
     handleMultipart.go
     ...
  db
     connect.go
     dbTypes.go
     (auth)
         strategy1.go
         strategy2.go
         ...
@codcodea codcodea added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Oct 25, 2023
@gopherbot gopherbot added this to the Unreleased milestone Oct 25, 2023
@codcodea codcodea changed the title x/tools/gopls: x/tools/gopls: Feature Request: Transparent Folders in Go Oct 25, 2023
@Jorropo
Copy link
Member

Jorropo commented Oct 26, 2023

This change wouldn't be limited to gopls, all go tooling which don't operate directly on .go files (like some linters do) would need to be changed.

@ansaba ansaba removed gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Oct 26, 2023
@ansaba ansaba changed the title x/tools/gopls: Feature Request: Transparent Folders in Go proposal: Transparent Folders in Go Oct 26, 2023
@dmitshur
Copy link
Contributor

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:

Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".

An example of that is in the x/website repository: it has a "_content" directory for website content rather than Go packages.

@Jorropo
Copy link
Member

Jorropo commented Oct 27, 2023

@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.

@bcmills bcmills modified the milestones: Unreleased, Proposal Oct 27, 2023
@dmitshur
Copy link
Contributor

@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.

@earthboundkid
Copy link
Contributor

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.

@rsc rsc changed the title proposal: Transparent Folders in Go proposal: cmd/go: add Transparent Folders in Go Dec 4, 2023
@rsc
Copy link
Contributor

rsc commented Dec 4, 2023

This proposal has been declined as infeasible.
— rsc for the proposal review group

@rsc rsc closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Declined
Development

No branches or pull requests

8 participants