Skip to content

Commit ac47839

Browse files
CopilotJustinGrote
andauthored
Add close operation to workspace documents API
Agent-Logs-Url: https://github.com/PowerShell/PowerShellEditorServices/sessions/6a4ffcb3-ffa5-431d-8a79-d5c87df48a9c Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com>
1 parent 4db3d1d commit ac47839

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/PowerShellEditorServices/Extensions/EditorWorkspace.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ internal EditorWorkspaceDocument(EditorWorkspace workspace, string path)
3030
/// Saves this document in the editor.
3131
/// </summary>
3232
public void Save() => _workspace.SaveFile(Path);
33+
34+
/// <summary>
35+
/// Closes this document in the editor.
36+
/// </summary>
37+
public void Close() => _workspace.CloseFile(Path);
3338
}
3439

3540
/// <summary>

‎test/PowerShellEditorServices.Test/Extensions/EditorWorkspaceTests.cs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void DocumentsReturnsOpenWorkspaceDocuments()
3232
}
3333

3434
[Fact]
35-
public void DocumentOpenAndSaveUseWorkspaceOperations()
35+
public void DocumentOpenSaveAndCloseUseWorkspaceOperations()
3636
{
3737
const string filePath = @"C:\test\file.ps1";
3838
TestEditorOperations editorOperations = new()
@@ -45,11 +45,13 @@ public void DocumentOpenAndSaveUseWorkspaceOperations()
4545

4646
document.Open();
4747
document.Save();
48+
document.Close();
4849

4950
Assert.Collection(
5051
editorOperations.Calls,
5152
call => Assert.Equal("OpenFile:" + filePath, call),
52-
call => Assert.Equal("SaveFile:" + filePath, call));
53+
call => Assert.Equal("SaveFile:" + filePath, call),
54+
call => Assert.Equal("CloseFile:" + filePath, call));
5355
}
5456

5557
private sealed class TestEditorOperations : IEditorOperations
@@ -80,7 +82,11 @@ public Task OpenFileAsync(string filePath)
8082

8183
public Task OpenFileAsync(string filePath, bool preview) => Task.CompletedTask;
8284

83-
public Task CloseFileAsync(string filePath) => Task.CompletedTask;
85+
public Task CloseFileAsync(string filePath)
86+
{
87+
Calls.Add("CloseFile:" + filePath);
88+
return Task.CompletedTask;
89+
}
8490

8591
public Task SaveFileAsync(string filePath)
8692
{

0 commit comments

Comments
 (0)