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

onDidSaveTextDocument event does not fire when saving a non-dirty file #66338

Closed
jomiller opened this issue Jan 10, 2019 · 9 comments
Closed
Assignees
Labels
api debt Code quality issues
Milestone

Comments

@jomiller
Copy link

When saving a file that has no unsaved changes (i.e. TextDocument.isDirty === false), the workspace.onWillSaveTextDocument event fires, but the workspace.onDidSaveTextDocument event does not fire. However, the non-dirty file is still saved to the file system (its timestamp is updated).

I'd like the state to be consistent between events firing and files being saved to the file system. So, either fire onDidSaveTextDocument, or do not save the file to the file system.

@vscodebot
Copy link

vscodebot bot commented Jan 10, 2019

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@bpasero bpasero added the under-discussion Issue is under discussion for relevance, priority, approach label Jan 11, 2019
@bpasero bpasero changed the title Fire onDidSaveTextDocument event when saving a non-dirty file onDidSaveTextDocument event does not fire when saving a non-dirty file Jan 11, 2019
@bpasero
Copy link
Member

bpasero commented Jan 11, 2019

Have to check if it makes sense to fire this event when the file is not dirty and what the implications are.

@bpasero bpasero added debt Code quality issues and removed under-discussion Issue is under discussion for relevance, priority, approach labels Jan 11, 2019
@bpasero
Copy link
Member

bpasero commented May 3, 2019

When saving a file that is not dirty, we run through a method doTouch that actually triggers save participants etc. but does not call the StateChange.SAVED event after done which normally causes the extension host to get this event.

I see not big reason why we could not add that one line into the touch method to have extensions be notified. The only gotcha is that previously every call to vscode.workspace.onDidSaveTextDocument would provide a document.version that is different from the previous one. Now with this change it would mean you might get the document with a same version in the event because the model did not change. But I think we can tolerate that, given the documentation says: The version number of this document (it will strictly increase after each change, including undo/redo).

@jrieken
Copy link
Member

jrieken commented May 3, 2019

@bpasero does the doTouch method actually change something on disk? Iff not then I would say the behaviour is correct, we fire will-save and when that doesn't yield in actual changes we don't save and therefore no did-save event happens. However, iff something on disk changes then we should consider this

@bpasero
Copy link
Member

bpasero commented May 3, 2019

@jrieken yeah it actually writes the contents to disk as they are to cause the OS to advance the mtime of the file. We do that so that you can e.g. force an external watcher to retrigger whatever it is doing (e.g. buil).

@jrieken
Copy link
Member

jrieken commented May 6, 2019

Ok, that's changes things and we should fire the change event when stuff actually changes on disk. cc @DanTup how will like this new insights.

@bpasero bpasero added this to the May 2019 milestone May 6, 2019
@DanTup
Copy link
Contributor

DanTup commented May 6, 2019

Indeed! :) I actually noticed this the other day - I changed my things over to use watchers (not specifically to workaround this, but so that changing branch in git could be detected too) and noticed that hitting Ctrl+S in the file with no changes still triggered it.

Even using the watcher it'll let me clean some things up, so this would be a nice change :-) (and if any handlers don't want to do work when the file wasn't actually changed, I presume they're able to check the isDirty flag themselves anyway).

@jrieken thanks for the heads-up! :)

bpasero added a commit that referenced this issue May 6, 2019
bpasero added a commit that referenced this issue May 6, 2019
@bpasero
Copy link
Member

bpasero commented May 13, 2019

via #73123

@bpasero bpasero closed this as completed May 13, 2019
jomiller added a commit to jomiller/vscode-rtags that referenced this issue May 17, 2019
Update the minimum VS Code version to 1.35.0, in which the issue was
fixed.
@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api debt Code quality issues
Projects
None yet
Development

No branches or pull requests

5 participants