-
Notifications
You must be signed in to change notification settings - Fork 645
Open generated Go files in readonly mode #1295
Comments
I don't think it's a good idea to force read only. What do you think about a notification like feature that notifies the user that this is a generated file? That way they understand that their changes will, probably, be overwritten with future generations. |
A notification at file open is too intrusive. However once I have the file open and I try to modify the content, it would be helpful to have a notification of why the file is in readonly mode (and how to disable that). |
If a file is being opened programatically say via a command registered by an extension, then the extension can use custom uri and register a content provider for the same which will result in the file being opened in a read only mode. But we are talking about files that are opened normally, from the file explorer or quick open etc. There are no apis that the extension can use to let the core know that the file needs to be opened in read only mode. One thing we (the Go extension) could do is to listen to the change event on the document. When this event occurs, check the first line for This is pretty easy to do and PRs are welcome. Hint: https://github.com/Microsoft/vscode-go/blob/0.6.67/src/goMain.ts#L135 removes test coverage when there is a file change |
* Check and notify if the file seems to be generated. Fixes #1295. Show a warning notification if the first line of the file matches the regexp: `^// Code generated .* DO NOT EDIT\.$`. * Fix lint errors. * Skip the first line check on non go files.
This is now out in the latest update to the Go extension (0.6.71) |
@ramya-rao-a Is there any way to make this notification go away when I close the file, or automatically time out? Right now I have to explicitly dismiss it, which is a bit of a pain. I've also seen this appear when I haven't tried to edit the file, but I have been unable to track down a reproduction scenario so far. |
You can always press the ESC key to make any notification in VS Code go away. There is no clear way to set timeouts on notification, but there is a feature request for the same in VS Code. See microsoft/vscode#23684
That's worrisome, its only supposed to show up on any change to the document. Please report an issue if you are able to get a repro consistently |
@ramya-rao-a It happens if the file is regenerated (deleted and recreated) while it is open in VSCode. I guess in some fashion that results in a "file edited" trigger. |
@gregmarr Does that happen often? |
In main my project, I'm working with a Swagger library that generates 4 different sets of code based on 3 different swagger files. I'm currently working on the services, so it's fairly often, but I don't expect it to be something that lots of people run into often. I also suspect that it would be difficult to differentiate between "delete, and create new" from "edit". |
The Go community has a standard for files marked as machine-generated: https://golang.org/s/generatedcode
It is expected that the generator may ran again and that any changes made by a human would be overwritten. So those files should not be modified by humans. It would be helpful if VSCode could help to enforce this.
So I propose that when a .go file is opened and it contains the
^// Code generated .* DO NOT EDIT\.$
pattern the readonly mode would be enabled.The text was updated successfully, but these errors were encountered: