提交 1ec4b811 编写于 作者: M Matt Bierner

Adding vscode.executeTypeDefinitionProvider command

Fixes #45652
上级 834e1430
...@@ -46,6 +46,14 @@ export class ExtHostApiCommands { ...@@ -46,6 +46,14 @@ export class ExtHostApiCommands {
], ],
returns: 'A promise that resolves to an array of Location-instances.' returns: 'A promise that resolves to an array of Location-instances.'
}); });
this._register('vscode.executeTypeDefinitionProvider', this._executeTypeDefinitionProvider, {
description: 'Execute all type definition providers.',
args: [
{ name: 'uri', description: 'Uri of a text document', constraint: URI },
{ name: 'position', description: 'Position of a symbol', constraint: types.Position }
],
returns: 'A promise that resolves to an array of Location-instances.'
});
this._register('vscode.executeImplementationProvider', this._executeImplementationProvider, { this._register('vscode.executeImplementationProvider', this._executeImplementationProvider, {
description: 'Execute all implementation providers.', description: 'Execute all implementation providers.',
args: [ args: [
...@@ -284,6 +292,15 @@ export class ExtHostApiCommands { ...@@ -284,6 +292,15 @@ export class ExtHostApiCommands {
.then(tryMapWith(typeConverters.location.to)); .then(tryMapWith(typeConverters.location.to));
} }
private _executeTypeDefinitionProvider(resource: URI, position: types.Position): Thenable<types.Location[]> {
const args = {
resource,
position: position && typeConverters.fromPosition(position)
};
return this._commands.executeCommand<modes.Location[]>('_executeTypeDefinitionProvider', args)
.then(tryMapWith(typeConverters.location.to));
}
private _executeImplementationProvider(resource: URI, position: types.Position): Thenable<types.Location[]> { private _executeImplementationProvider(resource: URI, position: types.Position): Thenable<types.Location[]> {
const args = { const args = {
resource, resource,
......
...@@ -250,6 +250,49 @@ suite('ExtHostLanguageFeatureCommands', function () { ...@@ -250,6 +250,49 @@ suite('ExtHostLanguageFeatureCommands', function () {
}); });
}); });
// --- type definition
test('Type Definition, invalid arguments', function () {
const promises = [
commands.executeCommand('vscode.executeTypeDefinitionProvider'),
commands.executeCommand('vscode.executeTypeDefinitionProvider', null),
commands.executeCommand('vscode.executeTypeDefinitionProvider', undefined),
commands.executeCommand('vscode.executeTypeDefinitionProvider', true, false)
];
return TPromise.join(<any[]>promises).then(undefined, (err: any[]) => {
assert.equal(err.length, 4);
});
});
test('Type Definition, back and forth', function () {
disposables.push(extHost.registerTypeDefinitionProvider(defaultSelector, <vscode.TypeDefinitionProvider>{
provideTypeDefinition(doc: any): any {
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
}
}));
disposables.push(extHost.registerTypeDefinitionProvider(defaultSelector, <vscode.TypeDefinitionProvider>{
provideTypeDefinition(doc: any): any {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
];
}
}));
return rpcProtocol.sync().then(() => {
return commands.executeCommand<vscode.Location[]>('vscode.executeTypeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
assert.equal(values.length, 4);
for (const v of values) {
assert.ok(v.uri instanceof URI);
assert.ok(v.range instanceof types.Range);
}
});
});
});
// --- references // --- references
test('reference search, back and forth', function () { test('reference search, back and forth', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册