GNOME Bugzilla – Bug 787792
Race with Python diagnostics and file saving
Last modified: 2018-01-11 10:40:59 UTC
Open a file that does not comply with PEP-8, go to a line that shows a light bulb, quickly fix the (e.g. spacing around operator) issue and save. All lightbulbs disappear from the gutter, a new one appears at the top of the file and the tooltip claims the there is no such file 'something/something/buffer.py'. The only way to get back to the list of lightbulbs to continue fixing your code is to close and reopen the file.
Those checks are performed by gnome-code-assistance. So there is a chance the issue is there. But upon investigating, I see we just use g_file_set_contents() in libide/buffers/ide-unsaved-files.c to save the temporary files (which are used to communicate with G-C-A). Perhaps we need to change that code to write a secondary temp file and then rename() over the previous file.
Created attachment 359940 [details] [review] unsaved-files: replace temp files atomically
Comment on attachment 359940 [details] [review] unsaved-files: replace temp files atomically I suspect this will fix it. Let me know or close appropriately. Attachment 359940 [details] pushed as a6ba90f - unsaved-files: replace temp files atomically
That doesn't seem to be enough, the problem is still present.
Then I'm inclined to think it is a bug in G-C-A and not Builder.
Maybe this happens because the G-C-A python backend opens the file 3 time? one time for using the python AST to check for syntax errors, one time when invoking pep8, and one time when invoking pylint. Builder deletes the temp file after the buffer is saved, right? So it could be that Builder asks G-C-A to parse the file, and then while it's parsing the user hits ctrl+s and the temp file is deleted, and then G-C-A gets to calling pep8 or pylint, and the file is no longer there, so it returns an error. If I'm correct, there are three ways we can fix this: 1) We could make G-C-A copy the temp file it gets to another temp file, to make sure it doesn't disappear (modifying it to only open the file once is also an option, but it doesn't sound easy because of the way it invokes external tools). 2) Builder could call G-C-A again after the file is saved, and this will probably work around this problem quite easily.
I think re-running diagnostics after saving is perfectly reasonable.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-builder/issues/286.