Skip to content

Commit 02e73a8

Browse files
dfinkedaviwil
authored andcommitted
Implemented NewFile for $psEditor.Workspace.NewFile()
1 parent 6778c25 commit 02e73a8

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public static readonly
101101
public Position CursorPosition { get; set; }
102102
}
103103

104+
public class NewFileRequest
105+
{
106+
public static readonly
107+
RequestType<string, EditorCommandResponse, object, object> Type =
108+
RequestType<string, EditorCommandResponse, object, object>.Create("editor/newFile");
109+
}
110+
104111
public class OpenFileRequest
105112
{
106113
public static readonly

src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public EditorContext ConvertClientEditorContext(
101101
clientContext.SelectionRange.End.Character + 1));
102102
}
103103

104+
public Task NewFile()
105+
{
106+
return
107+
this.messageSender.SendRequest(
108+
NewFileRequest.Type,
109+
null,
110+
true);
111+
}
112+
104113
public Task OpenFile(string filePath)
105114
{
106115
return

src/PowerShellEditorServices/Extensions/EditorWorkspace.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ internal EditorWorkspace(IEditorOperations editorOperations)
4040

4141
#region Public Methods
4242

43+
public void NewFile()
44+
{
45+
this.editorOperations.NewFile().Wait();
46+
}
47+
4348
/// <summary>
4449
/// Opens a file in the workspace. If the file is already open
4550
/// its buffer will be made active.

src/PowerShellEditorServices/Extensions/IEditorOperations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface IEditorOperations
3333
/// <returns>The resolved file path.</returns>
3434
string GetWorkspaceRelativePath(string filePath);
3535

36+
Task NewFile();
37+
3638
/// <summary>
3739
/// Causes a file to be opened in the editor. If the file is
3840
/// already open, the editor must switch to the file.

test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ await this.extensionEventQueue.EnqueueAsync(
174174

175175
public class TestEditorOperations : IEditorOperations
176176
{
177+
177178
public string GetWorkspacePath()
178179
{
179180
throw new NotImplementedException();
@@ -184,6 +185,11 @@ public string GetWorkspaceRelativePath(string filePath)
184185
throw new NotImplementedException();
185186
}
186187

188+
public Task NewFile()
189+
{
190+
throw new NotImplementedException();
191+
}
192+
187193
public Task OpenFile(string filePath)
188194
{
189195
throw new NotImplementedException();

0 commit comments

Comments
 (0)