diff --git a/src/vs/workbench/api/node/extHostApiCommands.ts b/src/vs/workbench/api/node/extHostApiCommands.ts index 9a397bc7233..7eb6e84e197 100644 --- a/src/vs/workbench/api/node/extHostApiCommands.ts +++ b/src/vs/workbench/api/node/extHostApiCommands.ts @@ -47,6 +47,14 @@ export class ExtHostApiCommands { ], returns: 'A promise that resolves to an array of Location-instances.' }); + this._register('vscode.executeDeclarationProvider', this._executeDeclaraionProvider, { + description: 'Execute all declaration provider.', + 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.executeTypeDefinitionProvider', this._executeTypeDefinitionProvider, { description: 'Execute all type definition providers.', args: [ @@ -292,6 +300,15 @@ export class ExtHostApiCommands { .then(tryMapWith(typeConverters.location.to)); } + private _executeDeclaraionProvider(resource: URI, position: types.Position): Thenable { + const args = { + resource, + position: position && typeConverters.Position.from(position) + }; + return this._commands.executeCommand('_executeDeclarationProvider', args) + .then(tryMapWith(typeConverters.location.to)); + } + private _executeTypeDefinitionProvider(resource: URI, position: types.Position): Thenable { const args = { resource, diff --git a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts index 8dfcbd3d4c4..863ca25a002 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts @@ -247,6 +247,36 @@ suite('ExtHostLanguageFeatureCommands', function () { }); }); + // --- declaration + + test('Declaration, back and forth', function () { + + disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, { + provideDeclaration(doc: any): any { + return new types.Location(doc.uri, new types.Range(0, 0, 0, 0)); + } + })); + disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, { + provideDeclaration(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.executeDeclarationProvider', model.uri, new types.Position(0, 0)).then(values => { + assert.equal(values.length, 4); + for (let v of values) { + assert.ok(v.uri instanceof URI); + assert.ok(v.range instanceof types.Range); + } + }); + }); + }); + // --- type definition test('Type Definition, invalid arguments', function () {