From 5f44e365934801800f911b1cfbe69484aeb14911 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 6 Apr 2016 12:48:54 +0200 Subject: [PATCH] fix issue #4945 --- .../vscode-api-tests/src/commands.test.ts | 32 ++++++++++++++++--- src/vs/vscode.d.ts | 2 +- src/vs/workbench/api/node/extHost.api.impl.ts | 9 +++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/extensions/vscode-api-tests/src/commands.test.ts b/extensions/vscode-api-tests/src/commands.test.ts index 52adb458da8..5ffd6fd2ac7 100644 --- a/extensions/vscode-api-tests/src/commands.test.ts +++ b/extensions/vscode-api-tests/src/commands.test.ts @@ -6,9 +6,10 @@ 'use strict'; import * as assert from 'assert'; -import {commands, workspace, Uri} from 'vscode'; +import {join} from 'path'; +import {commands, workspace, window, Uri} from 'vscode'; -suite("commands namespace tests", () => { +suite('commands namespace tests', () => { test('getCommands', function(done) { @@ -39,7 +40,7 @@ suite("commands namespace tests", () => { }, done); }); - test('api-command: workbench.html.preview', function() { + test('api-command: workbench.html.preview', function () { let registration = workspace.registerTextDocumentContentProvider('speciale', { provideTextDocumentContent(uri) { @@ -47,12 +48,33 @@ suite("commands namespace tests", () => { } }); - let virtualDocumentUri = Uri.parse('speciale://authority/path') + let virtualDocumentUri = Uri.parse('speciale://authority/path'); return commands.executeCommand('vscode.previewHtml', virtualDocumentUri).then(success => { assert.ok(success); registration.dispose(); }); - }) + }); + + test('editorCommand with extra args', function () { + + let args: IArguments; + let registration = commands.registerTextEditorCommand('t1', function() { + args = arguments; + }); + + return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => { + return window.showTextDocument(doc).then(editor => { + return commands.executeCommand('t1', 12345, commands); + }).then(() => { + assert.ok(args); + assert.equal(args.length, 4); + assert.ok(args[2] === 12345); + assert.ok(args[3] === commands); + registration.dispose(); + }); + }); + + }); }); diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 7d103a920ad..c8fbd682abf 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -2865,7 +2865,7 @@ declare namespace vscode { * @param thisArg The `this` context used when invoking the handler function. * @return Disposable which unregisters this command on disposal. */ - export function registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit) => void, thisArg?: any): Disposable; + export function registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => void, thisArg?: any): Disposable; /** * Executes the command denoted by the given command identifier. diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 3b8464ae159..745e7b5e81e 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -162,9 +162,8 @@ export class ExtHostAPIImplementation { registerCommand(id: string, command: (...args: any[]) => T | Thenable, thisArgs?: any): vscode.Disposable { return extHostCommands.registerCommand(id, command, thisArgs); }, - registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void, thisArg?: any): vscode.Disposable { - let actualCallback: typeof callback = thisArg ? callback.bind(thisArg) : callback; - return extHostCommands.registerCommand(id, () => { + registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => void, thisArg?: any): vscode.Disposable { + return extHostCommands.registerCommand(id, (...args: any[]) => { let activeTextEditor = extHostEditors.getActiveTextEditor(); if (!activeTextEditor) { console.warn('Cannot execute ' + id + ' because there is no active text editor.'); @@ -172,7 +171,9 @@ export class ExtHostAPIImplementation { } activeTextEditor.edit((edit: vscode.TextEditorEdit) => { - actualCallback(activeTextEditor, edit); + args.unshift(activeTextEditor, edit); + callback.apply(thisArg, args); + }).then((result) => { if (!result) { console.warn('Edits from command ' + id + ' were not applied.'); -- GitLab