diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs index be66829a7..c66582700 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs @@ -122,6 +122,13 @@ public static readonly RequestType.Create("editor/closeFile"); } + public class SaveFileRequest + { + public static readonly + RequestType Type = + RequestType.Create("editor/saveFile"); + } + public class ShowInformationMessageRequest { public static readonly diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs index 2b2746d04..16e1aefc0 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs @@ -128,6 +128,15 @@ public Task CloseFile(string filePath) true); } + public Task SaveFile(string filePath) + { + return + this.messageSender.SendRequest( + SaveFileRequest.Type, + filePath, + true); + } + public string GetWorkspacePath() { return this.editorSession.Workspace.WorkspacePath; diff --git a/src/PowerShellEditorServices/Extensions/FileContext.cs b/src/PowerShellEditorServices/Extensions/FileContext.cs index 0227415ae..b725a1b54 100644 --- a/src/PowerShellEditorServices/Extensions/FileContext.cs +++ b/src/PowerShellEditorServices/Extensions/FileContext.cs @@ -228,6 +228,18 @@ public void InsertText(string textToInsert, BufferRange insertRange) } #endregion + + #region File Manipulation + + /// + /// Saves this file. + /// + public void Save() + { + this.editorOperations.SaveFile(this.scriptFile.FilePath); + } + + #endregion } } diff --git a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs index 584207f1f..35d747fc3 100644 --- a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs +++ b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs @@ -54,6 +54,13 @@ public interface IEditorOperations /// A Task that can be tracked for completion. Task CloseFile(string filePath); + /// + /// Causes a file to be saved in the editor. + /// + /// The path of the file to be saved. + /// A Task that can be tracked for completion. + Task SaveFile(string filePath); + /// /// Inserts text into the specified range for the file at the specified path. /// diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs index 84bee5562..be348a402 100644 --- a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs @@ -200,6 +200,11 @@ public Task CloseFile(string filePath) throw new NotImplementedException(); } + public Task SaveFile(string filePath) + { + throw new NotImplementedException(); + } + public Task InsertText(string filePath, string text, BufferRange insertRange) { throw new NotImplementedException();