private async loadContexts()

in src/docker/ContextManager.ts [211:260]


    private async loadContexts(): Promise<DockerContext[]> {
        return await callWithTelemetryAndErrorHandling(ext.dockerClient ? 'docker-context.change' : 'docker-context.initialize', async (actionContext: IActionContext) => {
            // docker-context.initialize and docker-context.change should be treated as "activation events", in that they aren't real user action
            actionContext.telemetry.properties.isActivationEvent = 'true';
            actionContext.errorHandling.rethrow = true; // Errors are handled outside of this scope
            actionContext.errorHandling.suppressDisplay = true;

            let contextList: DockerContext[] | undefined;

            // First, we'll try shortcutting by getting a fixed context from extension settings, then from environment, then from filesystem clues
            const fixedContext =
                this.tryGetContextFromSettings(actionContext) ||
                this.tryGetContextFromEnvironment(actionContext) ||
                this.tryGetContextFromFilesystemClues(actionContext);

            // A result from any of these three implies that there is only one context, or it is fixed by `docker.host` / `DOCKER_HOST`, or `docker.context` / `DOCKER_CONTEXT`
            // As such, we will lock to the current context
            // Otherwise, unlock in case we were previously locked
            if (fixedContext) {
                this.setVsCodeContext('vscode-docker:contextLocked', true);
            } else {
                this.setVsCodeContext('vscode-docker:contextLocked', false);
            }

            // If the result is undefined, there are (probably) multiple contexts and none is chosen by `docker.context` or `DOCKER_CONTEXT`, so we will need to do a context listing
            // If the result is a string, that means `docker.context` or `DOCKER_CONTEXT` are set, so we will also need to do a context listing
            if (typeof (fixedContext) === 'undefined' || typeof (fixedContext) === 'string') {
                contextList =
                    (await this.tryGetContextsFromApi(actionContext, fixedContext)) ||
                    (await this.tryGetContextsFromCli(actionContext, fixedContext));
            } else {
                contextList = [fixedContext];
            }

            if (!contextList || contextList.length === 0) {
                // If the load is empty, return the default
                // That way a returned value is ensured by this method
                // And `setHostProtocolFromContextList` will always have a non-empty input
                contextList = [{
                    ...defaultContext,
                    Current: true,
                    DockerEndpoint: isWindows() ? WindowsLocalPipe : UnixLocalPipe,
                } as DockerContext];
            }

            this.setHostProtocolFromContextList(actionContext, contextList);

            return contextList;
        });
    }