From 1667eef999fe213320bc60467f01d941824cf914 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Fri, 16 Dec 2016 23:43:32 -0800 Subject: [PATCH] Allow quick fix to work in untitled documents In the previous iteration of this feature, the edits can be applied to files open in a workspace. This commit removes that restriction. --- src/features/CodeActions.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/features/CodeActions.ts b/src/features/CodeActions.ts index 5c0c0601fd..6e549a1a97 100644 --- a/src/features/CodeActions.ts +++ b/src/features/CodeActions.ts @@ -9,21 +9,15 @@ export class CodeActionsFeature implements IFeature { constructor() { this.command = vscode.commands.registerCommand('PowerShell.ApplyCodeActionEdits', (edit: any) => { - var editor = Window.activeTextEditor; - var filePath = editor.document.fileName; - var workspaceEdit = new vscode.WorkspaceEdit(); - workspaceEdit.set( - vscode.Uri.file(filePath), - [ - new vscode.TextEdit( - new vscode.Range( - edit.StartLineNumber - 1, - edit.StartColumnNumber - 1, - edit.EndLineNumber - 1, - edit.EndColumnNumber - 1), - edit.Text) - ]); - vscode.workspace.applyEdit(workspaceEdit); + Window.activeTextEditor.edit((editBuilder) => { + editBuilder.replace( + new vscode.Range( + edit.StartLineNumber - 1, + edit.StartColumnNumber - 1, + edit.EndLineNumber - 1, + edit.EndColumnNumber - 1), + edit.Text); + }); }); }