microsoft / vscode

Visual Studio Code

Home Page:https://code.visualstudio.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extension broke 10.3 to 10.5 => Objects passed as command arguments are now stripped of functions

hoovercj opened this issue · comments

I have an extension that works in version 0.10.3 but does not work in 0.10.5+.

The cause of this breakage is that functions on objects passed in the arguments array of a Command were available when executing the actions in 0.10.3 but are not available in 10.5+

This is illustrated in the following example:

class Repro implements vscode.CodeActionProvider {
    public commandId = 'hoovercj.reproCommand';
    private command;

    constructor() {
        this.command = vscode.commands.registerCommand(this.commandId, this.runCodeAction, this);
    }

    public provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): vscode.Command[] {
        return [<vscode.Command>{
            title: "Broken Command",
            command: this.commandId,
            arguments: [document, { 
                broken: () => { return 5; },
                works: 5
            }]
        }];
    }

    public runCodeAction(document: vscode.TextDocument, test:any) {
        try {
            test.works;
            test.broken();
            document.getText();
        } catch (error) {
                        // This should show up in 10.5+ but should not show up in 10.3
            vscode.window.showErrorMessage(error);
        }
    }

The issue is that we trigger the action on the main side but cannot serialise over such arguments. Before we would keep them cached on the extension side and create a dummy action for it. Tho, that is likely to result in memory leakage. Needs thinking...

Verified in code. Joe and I discussed the solution when he implemented it.