// Save Project File Logic /// <summary> /// Causes the dirty changes to the editor to be saved to the disk. This is called by the <seealso cref="ITextBufferStateListener"/> /// when it detects the user has saved the temp buffer. /// </summary> public async Task SaveProjectFileAsync() { lock (_lock) { // If we're here and the editor is not open, there's a bug. Normally we'd use the assumes, // but because of https://github.com/dotnet/roslyn-project-system/issues/1077 we can't // and unit test the scenario. So we're throwing an InvalidOperationException instead. // Assumes.True(_currentState != EditorState.NoEditor); if (_currentState == EditorState.NoEditor) { throw new InvalidOperationException("In SaveProjectFileAsync with no editor open! Bug!"); } // In order to save, the editor must not be in the process of being updated. if (_currentState != EditorState.EditorOpen) { return; } _currentState = EditorState.WritingProjectFile; } // While saving the file, we disallow edits to the project file for sync purposes. We also make sure // that the buffer cannot get stuck in a read-only state if SaveAsync fails for some reason. try { await _textBufferManager.SetReadOnlyAsync(true).ConfigureAwait(false); await _textBufferManager.SaveAsync().ConfigureAwait(false); } finally { await _textBufferManager.SetReadOnlyAsync(false).ConfigureAwait(false); } lock (_lock) { _currentState = EditorState.EditorOpen; } }