add new api command to compare two resources, fixes #1865

This commit is contained in:
Johannes Rieken 2016-05-17 16:21:51 +02:00
parent 6af3db5d8d
commit d8f6ac3501
3 changed files with 81 additions and 17 deletions

View file

@ -40,23 +40,6 @@ suite('commands namespace tests', () => {
}, done);
});
test('api-command: workbench.html.preview', function () {
let registration = workspace.registerTextDocumentContentProvider('speciale', {
provideTextDocumentContent(uri) {
return `content of URI <b>${uri.toString()}</b>`;
}
});
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;
@ -77,4 +60,46 @@ suite('commands namespace tests', () => {
});
});
test('api-command: vscode.previewHtm', function () {
let registration = workspace.registerTextDocumentContentProvider('speciale', {
provideTextDocumentContent(uri) {
return `content of URI <b>${uri.toString()}</b>`;
}
});
let virtualDocumentUri = Uri.parse('speciale://authority/path');
return commands.executeCommand('vscode.previewHtml', virtualDocumentUri).then(success => {
assert.ok(success);
registration.dispose();
});
});
test('api-command: vscode.diff', function () {
let registration = workspace.registerTextDocumentContentProvider('sc', {
provideTextDocumentContent(uri) {
return `content of URI <b>${uri.toString()}</b>#${Math.random()}`;
}
});
let a = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b'), 'DIFF').then(value => {
assert.ok(value === void 0);
registration.dispose();
});
let b = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b')).then(value => {
assert.ok(value === void 0);
registration.dispose();
});
let c = commands.executeCommand('vscode.diff').then(() => assert.ok(false), () => assert.ok(true));
let d = commands.executeCommand('vscode.diff', 1, 2, 3).then(() => assert.ok(false), () => assert.ok(true));
return Promise.all([a, b, c]);
});
});

View file

@ -197,6 +197,17 @@ class ExtHostApiCommands {
{ name: 'configuration', description: '(optional) Name of the debug configuration from \'launch.json\' to use. Or a configuration json object to use.' }
]
});
this._register('vscode.diff', (left: URI, right: URI, label: string) => {
return this._commands.executeCommand('_workbench.diff', [left, right, label]);
}, {
description: 'Opens the provided resources in the diff editor to compare their contents.',
args: [
{ name: 'left', description: 'Left-hand side resource of the diff editor', constraint: URI },
{ name: 'right', description: 'Right-hand side resource of the diff editor', constraint: URI },
{ name: 'title', description: '(optional) Human readable title for the diff editor', constraint: v => v === void 0 || typeof v === 'string' }
]
});
}
// --- command impl

View file

@ -5,12 +5,15 @@
'use strict';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import timer = require('vs/base/common/timer');
import paths = require('vs/base/common/paths');
import {Action} from 'vs/base/common/actions';
import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {EditorInput} from 'vs/workbench/common/editor';
import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
import nls = require('vs/nls');
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {IWindowConfiguration} from 'vs/workbench/electron-browser/window';
@ -459,4 +462,29 @@ KeybindingsRegistry.registerCommandDesc({
},
when: undefined,
primary: undefined
});
KeybindingsRegistry.registerCommandDesc({
id: '_workbench.diff',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(0),
handler(accessor: ServicesAccessor, args: [URI, URI, string]) {
const editorService = accessor.get(IWorkbenchEditorService);
let [left, right, label] = args;
if (!label) {
label = nls.localize('diffLeftRightLabel', "{0} ⟷ {1}", left.toString(true), right.toString(true));
}
return TPromise.join([editorService.inputToType({ resource: left }), editorService.inputToType({ resource: right })]).then(inputs => {
const [left, right] = inputs;
const diff = new DiffEditorInput(label, undefined, <EditorInput>left, <EditorInput>right);
return editorService.openEditor(diff);
}).then(() => {
return void 0;
});
},
when: undefined,
primary: undefined
});