Skip to content

Commit 8cffa08

Browse files
committed
Add client-side implementation of $psEditor.Workspace.NewFile()
This change adds the client-side message handelr implementation that wires up the new $psEditor.Workspace.NewFile() API. This API allows the user to create a new editor file from within a script or the Integrated Console. Resolves PowerShell/PowerShellEditorServices#435
1 parent fc86213 commit 8cffa08

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/features/ExtensionCommands.ts

+16
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ export namespace OpenFileRequest {
128128
'editor/openFile');
129129
}
130130

131+
export namespace NewFileRequest {
132+
export const type =
133+
new RequestType<string, EditorOperationResponse, void, void>(
134+
'editor/newFile');
135+
}
136+
131137
export namespace CloseFileRequest {
132138
export const type =
133139
new RequestType<string, EditorOperationResponse, void, void>(
@@ -211,6 +217,10 @@ export class ExtensionCommandsFeature implements IFeature {
211217
details => this.setSelection(details));
212218

213219
this.languageClient.onRequest(
220+
NewFileRequest.type,
221+
filePath => this.newFile());
222+
223+
this.languageClient.onRequest(
214224
OpenFileRequest.type,
215225
filePath => this.openFile(filePath));
216226

@@ -323,6 +333,12 @@ export class ExtensionCommandsFeature implements IFeature {
323333
}
324334
}
325335

336+
private newFile(): Thenable<EditorOperationResponse> {
337+
return vscode.workspace.openTextDocument('')
338+
.then(doc => vscode.window.showTextDocument(doc))
339+
.then(_ => EditorOperationResponse.Completed);
340+
}
341+
326342
private openFile(filePath: string): Thenable<EditorOperationResponse> {
327343

328344
// Make sure the file path is absolute

0 commit comments

Comments
 (0)