import vscode = require('vscode');
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
import Window = vscode.window;

export function registerCodeActionCommands(client: LanguageClient): void {
    vscode.commands.registerCommand('PowerShell.ApplyCodeActionEdits', (edit: any) => {
        console.log("Applying edits");
        console.log(edit);

        var workspaceEdit = new vscode.WorkspaceEdit();
        workspaceEdit.set(
            vscode.Uri.file(edit.File),
            [
                new vscode.TextEdit(
                    new vscode.Range(
                        edit.StartLineNumber - 1,
                        edit.StartColumnNumber - 1,
                        edit.EndLineNumber - 1,
                        edit.EndColumnNumber - 1),
                    edit.Text)
            ]);
        vscode.workspace.applyEdit(workspaceEdit);
    });
}
import vscode = require('vscode');
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
import Window = vscode.window;

export function registerCodeActionCommands(client: LanguageClient): void {
    vscode.commands.registerCommand('PowerShell.ApplyCodeActionEdits', (edit: any) => {
        console.log("Applying edits");
        console.log(edit);
        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);
    });
}
Set file path in ApplyCodeActionEdits
Set file path in ApplyCodeActionEdits

EditorServices invokes PSScriptAnalyzer by passing `ScriptDefinition` paramter and not `Path` parameter. This results in null value of `ScriptPath` property of the returned diagnostic record which in turns leads to null value of `edit.file`. Therefore, we need to retrieve file path from the active editor.
