Skip to content

Commit 0f63e5c

Browse files
Merge pull request #590 from tylerl0706/add-save
add Save to FileContext API
2 parents 0e849e2 + 2eabe90 commit 0f63e5c

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ public static readonly
122122
RequestType<string, EditorCommandResponse, object, object>.Create("editor/closeFile");
123123
}
124124

125+
public class SaveFileRequest
126+
{
127+
public static readonly
128+
RequestType<string, EditorCommandResponse, object, object> Type =
129+
RequestType<string, EditorCommandResponse, object, object>.Create("editor/saveFile");
130+
}
131+
125132
public class ShowInformationMessageRequest
126133
{
127134
public static readonly

src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ public Task CloseFile(string filePath)
128128
true);
129129
}
130130

131+
public Task SaveFile(string filePath)
132+
{
133+
return
134+
this.messageSender.SendRequest(
135+
SaveFileRequest.Type,
136+
filePath,
137+
true);
138+
}
139+
131140
public string GetWorkspacePath()
132141
{
133142
return this.editorSession.Workspace.WorkspacePath;

src/PowerShellEditorServices/Extensions/FileContext.cs

+12
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ public void InsertText(string textToInsert, BufferRange insertRange)
228228
}
229229

230230
#endregion
231+
232+
#region File Manipulation
233+
234+
/// <summary>
235+
/// Saves this file.
236+
/// </summary>
237+
public void Save()
238+
{
239+
this.editorOperations.SaveFile(this.scriptFile.FilePath);
240+
}
241+
242+
#endregion
231243
}
232244
}
233245

src/PowerShellEditorServices/Extensions/IEditorOperations.cs

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public interface IEditorOperations
5454
/// <returns>A Task that can be tracked for completion.</returns>
5555
Task CloseFile(string filePath);
5656

57+
/// <summary>
58+
/// Causes a file to be saved in the editor.
59+
/// </summary>
60+
/// <param name="filePath">The path of the file to be saved.</param>
61+
/// <returns>A Task that can be tracked for completion.</returns>
62+
Task SaveFile(string filePath);
63+
5764
/// <summary>
5865
/// Inserts text into the specified range for the file at the specified path.
5966
/// </summary>

test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs

+5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public Task CloseFile(string filePath)
200200
throw new NotImplementedException();
201201
}
202202

203+
public Task SaveFile(string filePath)
204+
{
205+
throw new NotImplementedException();
206+
}
207+
203208
public Task InsertText(string filePath, string text, BufferRange insertRange)
204209
{
205210
throw new NotImplementedException();

0 commit comments

Comments
 (0)