Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

The generated file warning should appear even if the DO NOT EDIT comment is not on the first line #2617

Closed
kennytm opened this issue Jun 29, 2019 · 3 comments

Comments

@kennytm
Copy link

kennytm commented Jun 29, 2019

In #1425 (which fixes #1295), VSCode will show a warning if the first line of the code contains the comment matching ^// Code generated .* DO NOT EDIT\.$. However, as specified in https://golang.org/pkg/cmd/go/internal/generate/, this comment can appear anywhere, so it is wrong to just detect the first line.

To convey to humans and machine tools that code is generated, generated source should have a line that matches the following regular expression (in Go syntax):

^// Code generated .* DO NOT EDIT\.$

The line may appear anywhere in the file, but is typically placed near the beginning so it is easy to find.

@ramya-rao-a
Copy link
Contributor

#1425 was a best effort made under the circumstances to provide a warning.
In order to support the DO NOT EDIT comment on any line, we will have to parse the entire file which I would prefer not to do as it can get expensive on very large files.

Now that we have support for language servers, they are in a better state to handle parsed file contents.

@stamblerre Is this something you would consider gopls to do?

@stamblerre
Copy link
Contributor

Yes, gopls could do this and send it as a diagnostic.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 1, 2019

Thanks @stamblerre

@kennytm Please log a request in the Go issue tracker

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

No branches or pull requests

3 participants