Skip to content

Commit

Permalink
Do not call getAllComponents() in activate
Browse files Browse the repository at this point in the history
Part of redhat-developer#3850

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Feb 6, 2024
1 parent eb06f1c commit 7b19597
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
updateStatusBarItem(crcStatusItem, 'Stop CRC');
void extendClusterExplorer();

await ComponentTypesView.instance.getAllComponents();
await registerKubernetesCloudProvider();
void startTelemetry(extensionContext);
await verifyBinariesInRemoteContainer();
Expand Down
18 changes: 13 additions & 5 deletions src/registriesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
QuickInputButtons, QuickPickItem, ThemeIcon, TreeDataProvider,
TreeItem, TreeItemCollapsibleState, TreeView, Uri, window
} from 'vscode';
import { quickBtn, inputValue } from './util/inputValue';
import {
ComponentTypeAdapter,
ComponentTypeDescription,
Expand All @@ -19,6 +18,7 @@ import {
} from './odo/componentType';
import { StarterProject } from './odo/componentTypeDescription';
import { Odo } from './odo/odoWrapper';
import { inputValue, quickBtn } from './util/inputValue';
import { Progress } from './util/progress';
import { vsCommand, VsCommandError } from './vscommand';
import fetch = require('make-fetch-happen');
Expand Down Expand Up @@ -48,6 +48,13 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
private readonly compDescriptions: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
public subject: Subject<string> = new Subject<string>();

private initialComponentTypeLoadPromise: Promise<void>;

constructor() {
this.initialComponentTypeLoadPromise = this.reloadComponentTypeList();
void Progress.execFunctionWithProgress('Loading component types', () => this.initialComponentTypeLoadPromise);
}

createTreeView(id: string): TreeView<ComponentType> {
if (!this.treeView) {
this.treeView = window.createTreeView(id, {
Expand Down Expand Up @@ -102,15 +109,16 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
return this.registries;
}

public getCompDescriptions(): Set<ComponentTypeDescription> {
public async getCompDescriptions(): Promise<Set<ComponentTypeDescription>> {
await this.initialComponentTypeLoadPromise;
return this.compDescriptions;
}

public getListOfRegistries(): Registry[] {
return this.registries;
}

public async getAllComponents(): Promise<void> {
private async reloadComponentTypeList(): Promise<void> {
return new Promise<void>((resolve) => {
let isError = false;
this.compDescriptions.clear();
Expand Down Expand Up @@ -362,7 +370,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
void Progress.execFunctionWithProgress('Devfile registry is updating',async () => {
const newRegistry = await Odo.Instance.addRegistry(regName, regURL, token);
ComponentTypesView.instance.addRegistry(newRegistry);
await ComponentTypesView.instance.getAllComponents();
await ComponentTypesView.instance.reloadComponentTypeList();
ComponentTypesView.instance.refresh(false);
})
}
Expand All @@ -389,7 +397,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
await Odo.Instance.removeRegistry(registry.name);
ComponentTypesView.instance.removeRegistry(registry);
if (!isEdit) {
await ComponentTypesView.instance.getAllComponents();
await ComponentTypesView.instance.reloadComponentTypeList();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/webview/common-ext/createComponentHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function validatePortNumber(portNumber: number): string {
*
* @returns a list of the devfile registries with their devfiles attached
*/
export function getDevfileRegistries(): DevfileRegistry[] {
export async function getDevfileRegistries(): Promise<DevfileRegistry[]> {
const registries = ComponentTypesView.instance.getListOfRegistries();
if (!registries || registries.length === 0) {
throw new Error('No Devfile registries available. Default registry is missing');
Expand All @@ -198,7 +198,7 @@ export function getDevfileRegistries(): DevfileRegistry[] {
} as DevfileRegistry;
});

const components = ComponentTypesView.instance.getCompDescriptions();
const components = await ComponentTypesView.instance.getCompDescriptions();
for (const component of components) {
const devfileRegistry = devfileRegistries.find(
(devfileRegistry) => format(devfileRegistry.url) === format(component.registry.url),
Expand Down Expand Up @@ -261,8 +261,8 @@ export function getDevfileCapabilities(): string[] {
*
* @returns a list of the devfile tags
*/
export function getDevfileTags(url?: string): string[] {
const devfileRegistries = getDevfileRegistries();
export async function getDevfileTags(url?: string): Promise<string[]> {
const devfileRegistries = await getDevfileRegistries();

const devfileTags: string[] = [
...new Set(
Expand Down
26 changes: 13 additions & 13 deletions src/webview/create-component/createComponentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ComponentTypesView } from '../../registriesView';
import sendTelemetry from '../../telemetry';
import { ExtensionID } from '../../util/constants';
import { DevfileConverter } from '../../util/devfileConverter';
import { DevfileV1 } from '../../util/devfileV1Type';
import { getInitialWorkspaceFolder, selectWorkspaceFolder } from '../../util/workspace';
import {
getDevfileCapabilities,
Expand All @@ -29,7 +30,6 @@ import {
} from '../common-ext/createComponentHelpers';
import { loadWebviewHtml, validateGitURL } from '../common-ext/utils';
import { Devfile, DevfileRegistry, TemplateProjectIdentifier } from '../common/devfile';
import { DevfileV1 } from '../../util/devfileV1Type';

interface CloneProcess {
status: boolean;
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class CreateComponentLoader {
});

const tagsSubscription = ComponentTypesView.instance.subject.subscribe(() => {
sendUpdatedTags();
void sendUpdatedTags();
});

panel.onDidDispose(() => {
Expand Down Expand Up @@ -158,7 +158,7 @@ export default class CreateComponentLoader {
case 'getDevfileTags': {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileTags',
data: getDevfileTags(),
data: await getDevfileTags(),
});
break;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ export default class CreateComponentLoader {
await fs.mkdir(componentFolder, {recursive: true});
await fse.copy(tmpFolder.fsPath, componentFolder);
}
const devfileType = getDevfileType(message.data.devfileDisplayName);
const devfileType = await getDevfileType(message.data.devfileDisplayName);
const componentFolderUri = Uri.file(componentFolder);
if (!await isDevfileExists(componentFolderUri)) {
await Odo.Instance.createComponentFromLocation(
Expand Down Expand Up @@ -521,7 +521,7 @@ export default class CreateComponentLoader {
action: 'getRecommendedDevfileStart'
});
analyzeRes = await Odo.Instance.analyze(uri.fsPath);
compDescriptions = getCompDescription(analyzeRes);
compDescriptions = await getCompDescription(analyzeRes);
} catch (error) {
if (error.message.toLowerCase().indexOf('failed to parse the devfile') !== -1) {
const actions: Array<string> = ['Yes', 'Cancel'];
Expand All @@ -536,7 +536,7 @@ export default class CreateComponentLoader {
const devfileV1 = JSYAML.load(file.toString()) as DevfileV1;
await fs.unlink(devFileV1Path);
analyzeRes = await Odo.Instance.analyze(uri.fsPath);
compDescriptions = getCompDescription(analyzeRes);
compDescriptions = await getCompDescription(analyzeRes);
const endPoints = getEndPoints(compDescriptions[0]);
const devfileV2 = DevfileConverter.getInstance().devfileV1toDevfileV2(
devfileV1,
Expand All @@ -562,7 +562,7 @@ export default class CreateComponentLoader {
void CreateComponentLoader.panel.webview.postMessage({
action: 'getRecommendedDevfile'
});
const devfileRegistry: DevfileRegistry[] = getDevfileRegistries();
const devfileRegistry: DevfileRegistry[] = await getDevfileRegistries();
const allDevfiles: Devfile[] = devfileRegistry.flatMap((registry) => registry.devfiles);
const devfile: Devfile | undefined =
compDescriptions.length !== 0
Expand All @@ -583,8 +583,8 @@ export default class CreateComponentLoader {
}
}

function getCompDescription(devfiles: AnalyzeResponse[]): ComponentTypeDescription[] {
const compDescriptions = ComponentTypesView.instance.getCompDescriptions();
async function getCompDescription(devfiles: AnalyzeResponse[]): Promise<ComponentTypeDescription[]> {
const compDescriptions = await ComponentTypesView.instance.getCompDescriptions();
if (devfiles.length === 0) {
return Array.from(compDescriptions);
}
Expand All @@ -598,9 +598,9 @@ function getCompDescription(devfiles: AnalyzeResponse[]): ComponentTypeDescripti
);
}

function getDevfileType(devfileDisplayName: string): string {
async function getDevfileType(devfileDisplayName: string): Promise<string> {
const compDescriptions: Set<ComponentTypeDescription> =
ComponentTypesView.instance.getCompDescriptions();
await ComponentTypesView.instance.getCompDescriptions();
const devfileDescription: ComponentTypeDescription = Array.from(compDescriptions).find(
(description) => description.displayName === devfileDisplayName,
);
Expand Down Expand Up @@ -679,11 +679,11 @@ function sendUpdatedCapabilities() {
}
}

function sendUpdatedTags() {
async function sendUpdatedTags() {
if (CreateComponentLoader.panel) {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileTags',
data: getDevfileTags(),
data: await getDevfileTags(),
});
}
}
16 changes: 8 additions & 8 deletions src/webview/devfile-registry/registryViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ async function devfileRegistryViewerMessageListener(event: any): Promise<any> {
})
break;
case 'getDevfileRegistries':
RegistryViewLoader.sendUpdatedRegistries();
await RegistryViewLoader.sendUpdatedRegistries();
break;
case 'getDevfileCapabilities':
RegistryViewLoader.sendUpdatedCapabilities();
break;
case 'getDevfileTags':
RegistryViewLoader.sendUpdatedTags();
await RegistryViewLoader.sendUpdatedTags();
break;
case 'createComponent': {
const { projectFolder, componentName } = event.data;
Expand Down Expand Up @@ -198,9 +198,9 @@ export default class RegistryViewLoader {
return Promise.resolve();
}

static sendUpdatedRegistries() {
static async sendUpdatedRegistries() {
if (panel) {
let registries = getDevfileRegistries();
let registries = await getDevfileRegistries();
if (RegistryViewLoader.url) {
registries = registries.filter((devfileRegistry) => devfileRegistry.url === RegistryViewLoader.url);
}
Expand All @@ -220,24 +220,24 @@ export default class RegistryViewLoader {
}
}

static sendUpdatedTags() {
static async sendUpdatedTags() {
if (panel) {
void panel.webview.postMessage({
action: 'devfileTags',
data: getDevfileTags(RegistryViewLoader.url),
data: await getDevfileTags(RegistryViewLoader.url),
});
}
}
}

ComponentTypesView.instance.subject.subscribe(() => {
RegistryViewLoader.sendUpdatedRegistries();
void RegistryViewLoader.sendUpdatedRegistries();
});

ComponentTypesView.instance.subject.subscribe(() => {
RegistryViewLoader.sendUpdatedCapabilities();
});

ComponentTypesView.instance.subject.subscribe(() => {
RegistryViewLoader.sendUpdatedTags();
void RegistryViewLoader.sendUpdatedTags();
});

0 comments on commit 7b19597

Please sign in to comment.