<ul dir="auto">
<li>VSCode Version: 1.0.0</li>
<li>OS Version: Mac OSX</li>
</ul>
<p dir="auto">It would be nice if extensions are able to distinguish the <code class="notranslate">autoSave</code> event from a manual <code class="notranslate">save</code>. We need this information in our <a href="https://github.com/editorconfig/editorconfig-vscode/issues/47" data-hovercard-type="issue" data-hovercard-url="/editorconfig/editorconfig-vscode/issues/47/hovercard">EditorConfig</a> extension.</p>
<p dir="auto">// <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bpasero/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bpasero">@bpasero</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jrieken/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jrieken">@jrieken</a></p>
<p dir="auto">It would be nice to have some extra events I guess. The first one I can think of is <code class="notranslate">onPreSaveTextDocument</code> (or <code class="notranslate">onSaveTextDocument</code>). One that will be invoked right before the document gets saved.</p>
<h3 dir="auto">Use Cases</h3>
<p dir="auto">The first one I can think of is my own plugin <a href="https://github.com/SamVerschueren/vscode-final-newline">final-newline</a> that will insert a final newline at the end of the file when the user saves the document. At the moment it is implemented like this: <kbd>Cmd</kbd> + <kbd>s</kbd> → <code class="notranslate">Save</code> → <code class="notranslate">Insert newline</code> (if necessary) → <code class="notranslate">Save</code><br>
That last save triggers a new iteration of my plugin which will detect a final newline is already present and will stop the execution. So my loop is triggered twice because the plugin is triggered after the document was saved instead of before.</p>
<p dir="auto">I think there will be other file manipulation plugins that want to manipulate the file before it gets saved as well.</p>
<p dir="auto">From Alex:</p>
<p dir="auto">I agree some sort of onBeforeSave action is indeed needed, we just need more thinking regarding how to expose this without causing any data loss. If we block the save to wait on extensions, I can imagine it possible that the wait could be indefinite, resulting in data loss. Maybe a time ceiling of 10s, after which the file gets saved...</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bpasero/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bpasero">@bpasero</a> What do you think?</p>