diff --git a/src/sql/parts/registeredServer/common/objectExplorerService.ts b/src/sql/parts/registeredServer/common/objectExplorerService.ts index 366444ef16..5b4b30aa93 100644 --- a/src/sql/parts/registeredServer/common/objectExplorerService.ts +++ b/src/sql/parts/registeredServer/common/objectExplorerService.ts @@ -68,6 +68,8 @@ export interface IObjectExplorerService { getServerTreeView(): ServerTreeView; + findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames?: string[]): Thenable; + getActiveConnectionNodes(): TreeNode[]; getTreeNode(connectionId: string, nodePath: string): Thenable; @@ -447,6 +449,24 @@ export class ObjectExplorerService implements IObjectExplorerService { return this._serverTreeView; } + public findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames?: string[]): Thenable { + let rootNode = this._activeObjectExplorerNodes[connectionId]; + if (!rootNode) { + return Promise.resolve([]); + } + let sessionId = rootNode.session.sessionId; + return this._providers[this._sessions[sessionId].connection.providerName].findNodes({ + type: type, + name: name, + schema: schema, + database: database, + parentObjectNames: parentObjectNames, + sessionId: sessionId + }).then(response => { + return response.nodes; + }); + } + public getActiveConnectionNodes(): TreeNode[] { return Object.values(this._activeObjectExplorerNodes); } diff --git a/src/sql/sqlops.d.ts b/src/sql/sqlops.d.ts index f73f06d7f7..25dc21151d 100644 --- a/src/sql/sqlops.d.ts +++ b/src/sql/sqlops.d.ts @@ -129,6 +129,18 @@ declare module 'sqlops' { */ export function getActiveConnectionNodes(): Thenable; + /** + * Find Object Explorer nodes that match the given information + * @param {string} connectionId The id of the connection that the node exists on + * @param {string} type The type of the object to retrieve + * @param {string} schema The schema of the object, if applicable + * @param {string} name The name of the object + * @param {string} database The database the object exists under, if applicable + * @param {string[]} parentObjectNames A list of names of parent objects in the tree, ordered from highest to lowest level + * (for example when searching for a table's column, provide the name of its parent table for this argument) + */ + export function findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable; + /** * Interface for representing and interacting with items in Object Explorer */ @@ -942,6 +954,15 @@ declare module 'sqlops' { nodePath: string; } + export interface FindNodesInfo { + sessionId: string; + type: string; + schema: string; + name: string; + database: string; + parentObjectNames: string[]; + } + export interface ObjectExplorerCloseSessionInfo { sessionId: string; } @@ -951,6 +972,10 @@ declare module 'sqlops' { success: boolean; } + export interface ObjectExplorerFindNodesResponse { + nodes: NodeInfo[]; + } + export interface ObjectExplorerProvider extends DataProvider { createNewSession(connInfo: ConnectionInfo): Thenable; @@ -960,6 +985,8 @@ declare module 'sqlops' { closeSession(closeSessionInfo: ObjectExplorerCloseSessionInfo): Thenable; + findNodes(findNodesInfo: FindNodesInfo): Thenable; + registerOnSessionCreated(handler: (response: ObjectExplorerSession) => any); registerOnExpandCompleted(handler: (response: ObjectExplorerExpandInfo) => any); diff --git a/src/sql/workbench/api/node/extHostDataProtocol.ts b/src/sql/workbench/api/node/extHostDataProtocol.ts index 8f9f35d19b..c71f5e5ff6 100644 --- a/src/sql/workbench/api/node/extHostDataProtocol.ts +++ b/src/sql/workbench/api/node/extHostDataProtocol.ts @@ -299,6 +299,10 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape { return this._resolveProvider(handle).closeSession(closeSessionInfo); } + public $findNodes(handle: number, findNodesInfo: sqlops.FindNodesInfo): Thenable { + return this._resolveProvider(handle).findNodes(findNodesInfo); + } + public $onObjectExplorerSessionCreated(handle: number, response: sqlops.ObjectExplorerSession): void { this._proxy.$onObjectExplorerSessionCreated(handle, response); } diff --git a/src/sql/workbench/api/node/extHostObjectExplorer.ts b/src/sql/workbench/api/node/extHostObjectExplorer.ts index ac567dc27f..49fa9d91b8 100644 --- a/src/sql/workbench/api/node/extHostObjectExplorer.ts +++ b/src/sql/workbench/api/node/extHostObjectExplorer.ts @@ -26,6 +26,10 @@ export class ExtHostObjectExplorer implements ExtHostObjectExplorerShape { public $getActiveConnectionNodes(): Thenable { return this._proxy.$getActiveConnectionNodes().then(results => results.map(result => new ExtHostObjectExplorerNode(result.nodeInfo, result.connectionId, this._proxy))); } + + public $findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable { + return this._proxy.$findNodes(connectionId, type, schema, name, database, parentObjectNames).then(results => results.map(result => new ExtHostObjectExplorerNode(result, connectionId, this._proxy))); + } } class ExtHostObjectExplorerNode implements sqlops.objectexplorer.ObjectExplorerNode { diff --git a/src/sql/workbench/api/node/mainThreadDataProtocol.ts b/src/sql/workbench/api/node/mainThreadDataProtocol.ts index c0d68cfd70..66c473a091 100644 --- a/src/sql/workbench/api/node/mainThreadDataProtocol.ts +++ b/src/sql/workbench/api/node/mainThreadDataProtocol.ts @@ -232,6 +232,9 @@ export class MainThreadDataProtocol implements MainThreadDataProtocolShape { }, closeSession(closeSessionInfo: sqlops.ObjectExplorerCloseSessionInfo): Thenable { return self._proxy.$closeObjectExplorerSession(handle, closeSessionInfo); + }, + findNodes(findNodesInfo: sqlops.FindNodesInfo): Thenable { + return self._proxy.$findNodes(handle, findNodesInfo); } }); diff --git a/src/sql/workbench/api/node/mainThreadObjectExplorer.ts b/src/sql/workbench/api/node/mainThreadObjectExplorer.ts index d335a638e8..0050bcae58 100644 --- a/src/sql/workbench/api/node/mainThreadObjectExplorer.ts +++ b/src/sql/workbench/api/node/mainThreadObjectExplorer.ts @@ -69,4 +69,8 @@ export class MainThreadObjectExplorer implements MainThreadObjectExplorerShape { public $isExpanded(connectionId: string, nodePath: string): Thenable { return this._objectExplorerService.getTreeNode(connectionId, nodePath).then(treeNode => treeNode.isExpanded()); } + + public $findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable { + return this._objectExplorerService.findNodes(connectionId, type, schema, name, database, parentObjectNames); + } } diff --git a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts index 9c8472f592..45d121ef6b 100644 --- a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts +++ b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts @@ -114,6 +114,9 @@ export function createApiFactory( }, getActiveConnectionNodes(): Thenable { return extHostObjectExplorer.$getActiveConnectionNodes(); + }, + findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable { + return extHostObjectExplorer.$findNodes(connectionId, type, schema, name, database, parentObjectNames); } }; diff --git a/src/sql/workbench/api/node/sqlExtHost.protocol.ts b/src/sql/workbench/api/node/sqlExtHost.protocol.ts index aeb83f9843..2974c4280a 100644 --- a/src/sql/workbench/api/node/sqlExtHost.protocol.ts +++ b/src/sql/workbench/api/node/sqlExtHost.protocol.ts @@ -100,6 +100,8 @@ export abstract class ExtHostDataProtocolShape { $closeObjectExplorerSession(handle: number, closeSessionInfo: sqlops.ObjectExplorerCloseSessionInfo): Thenable { throw ni(); } + $findNodes(handle: number, findNodesInfo: sqlops.FindNodesInfo): Thenable { throw ni(); } + /** * Tasks */ @@ -498,4 +500,5 @@ export interface MainThreadObjectExplorerShape extends IDisposable { $setSelected(connectionId: string, nodePath: string, selected: boolean, clearOtherSelections?: boolean): Thenable; $getChildren(connectionId: string, nodePath: string): Thenable; $isExpanded(connectionId: string, nodePath: string): Thenable; + $findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable; } diff --git a/src/sqltest/stubs/objectExplorerProviderTestService.ts b/src/sqltest/stubs/objectExplorerProviderTestService.ts index 0b14a5967a..b63d62c4c2 100644 --- a/src/sqltest/stubs/objectExplorerProviderTestService.ts +++ b/src/sqltest/stubs/objectExplorerProviderTestService.ts @@ -33,4 +33,8 @@ export class ObjectExplorerProviderTestService implements sqlops.ObjectExplorerP public registerOnExpandCompleted(handler: (response: sqlops.ObjectExplorerExpandInfo) => any): void { } + + public findNodes(findNodesInfo: sqlops.FindNodesInfo): Thenable { + return undefined; + } } \ No newline at end of file