Add API to open a file or diff editor on a specific selection range (fixes #30241)

This commit is contained in:
Benjamin Pasero
2017-07-07 12:20:34 +02:00
parent 6af048189e
commit f381ce961d
7 changed files with 37 additions and 10 deletions

View File

@@ -7,7 +7,7 @@
import * as assert from 'assert';
import { join } from 'path';
import { commands, workspace, window, Uri, ViewColumn } from 'vscode';
import { commands, workspace, window, Uri, ViewColumn, Range, Position } from 'vscode';
suite('commands namespace tests', () => {
@@ -114,10 +114,15 @@ suite('commands namespace tests', () => {
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));
let c = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b'), 'Title', { selection: new Range(new Position(1, 1), new Position(1, 2)) }).then(value => {
assert.ok(value === void 0);
registration.dispose();
});
return Promise.all([a, b, c, d]);
let d = commands.executeCommand('vscode.diff').then(() => assert.ok(false), () => assert.ok(true));
let e = commands.executeCommand('vscode.diff', 1, 2, 3).then(() => assert.ok(false), () => assert.ok(true));
return Promise.all([a, b, c, d, e]);
});
test('api-command: vscode.open', function () {

View File

@@ -260,6 +260,19 @@ suite('workspace-namespace', () => {
});
});
test('openTextDocument, with selection', function () {
return createRandomFile('foo\nbar\nbar').then(file => {
return vscode.workspace.openTextDocument(file).then(doc => {
return vscode.window.showTextDocument(doc, { selection: new vscode.Range(new vscode.Position(1, 1), new vscode.Position(1, 2)) }).then(editor => {
assert.equal(editor.selection.start.line, 1);
assert.equal(editor.selection.start.character, 1);
assert.equal(editor.selection.end.line, 1);
assert.equal(editor.selection.end.character, 2);
});
});
});
});
test('registerTextDocumentContentProvider, simple', function () {
let registration = vscode.workspace.registerTextDocumentContentProvider('foo', {