async getChildren()

in src/objectExplorer/objectExplorerService.ts [317:390]


	async getChildren(element?: TreeNodeInfo): Promise<vscode.TreeItem[]> {
		if (element) {
			// set current node for very first expansion of disconnected node
			if (this._currentNode !== element) {
				this._currentNode = element;
			}
			// get cached children
			if (this._treeNodeToChildrenMap.has(element)) {
				return this._treeNodeToChildrenMap.get(element);
			} else {
				// check if session exists
				if (element.sessionId) {
					// clean created session promise
					this._sessionIdToPromiseMap.delete(element.sessionId);

					// node expansion
					let promise = new Deferred<TreeNodeInfo[]>();
					await this.expandNode(element, element.sessionId, promise);
					let children = await promise;
					if (children) {
						// clean expand session promise
						this.cleanExpansionPromise(element);
						return children;
					} else {
						return undefined;
					}
				} else {
					// start node session
					let promise = new Deferred<TreeNodeInfo>();
					const sessionId = await this.createSession(promise, element.connectionInfo);
					if (sessionId) {
						let node = await promise;
						// if the server was found but connection failed
						if (!node) {
							let profile = element.connectionInfo as IConnectionProfile;
							let password = await this._connectionManager.connectionStore.lookupPassword(profile);
							if (password) {
								return this.createSignInNode(element);
							} else {
								return this.createConnectTreeNode(element);
							}
						}
					} else {
						// If node create session failed (server wasn't found)
						return this.createSignInNode(element);
					}
					// otherwise expand the node by refreshing the root
					// to add connected context key
					this._objectExplorerProvider.refresh(undefined);
				}
			}
		} else {
			// retrieve saved connections first when opening object explorer
			// for the first time
			let savedConnections = this._connectionManager.connectionStore.loadAllConnections();
			// if there are no saved connections
			// show the add connection node
			if (savedConnections.length === 0) {
				return this.getAddConnectionNode();
			}
			// if OE doesn't exist the first time
			// then build the nodes off of saved connections
			if (!this._objectExplorerProvider.objectExplorerExists) {
				// if there are actually saved connections
				this._rootTreeNodeArray = [];
				this.getSavedConnections();
				this._objectExplorerProvider.objectExplorerExists = true;
				return this.sortByServerName(this._rootTreeNodeArray);
			} else {
				// otherwise returned the cached nodes
				return this.sortByServerName(this._rootTreeNodeArray);
			}
		}
	}