Skip to content

Commit 09c4ab5

Browse files
committed
Do not call getAllComponents() in activate
Part of #3850 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent eb06f1c commit 09c4ab5

File tree

5 files changed

+61
-68
lines changed

5 files changed

+61
-68
lines changed

src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
204204
updateStatusBarItem(crcStatusItem, 'Stop CRC');
205205
void extendClusterExplorer();
206206

207-
await ComponentTypesView.instance.getAllComponents();
208207
await registerKubernetesCloudProvider();
209208
void startTelemetry(extensionContext);
210209
await verifyBinariesInRemoteContainer();

src/registriesView.ts

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import {
1010
QuickInputButtons, QuickPickItem, ThemeIcon, TreeDataProvider,
1111
TreeItem, TreeItemCollapsibleState, TreeView, Uri, window
1212
} from 'vscode';
13-
import { quickBtn, inputValue } from './util/inputValue';
1413
import {
15-
ComponentTypeAdapter,
1614
ComponentTypeDescription,
1715
DevfileComponentType,
1816
Registry
1917
} from './odo/componentType';
2018
import { StarterProject } from './odo/componentTypeDescription';
2119
import { Odo } from './odo/odoWrapper';
20+
import { inputValue, quickBtn } from './util/inputValue';
2221
import { Progress } from './util/progress';
2322
import { vsCommand, VsCommandError } from './vscommand';
2423
import fetch = require('make-fetch-happen');
@@ -46,7 +45,14 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
4645
readonly odo = Odo.Instance;
4746
private registries: Registry[];
4847
private readonly compDescriptions: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
49-
public subject: Subject<string> = new Subject<string>();
48+
public subject: Subject<void> = new Subject<void>();
49+
50+
private initialComponentTypeLoadPromise: Promise<void>;
51+
52+
constructor() {
53+
this.initialComponentTypeLoadPromise = this.reloadComponentTypeList();
54+
void Progress.execFunctionWithProgress('Loading component types', () => this.initialComponentTypeLoadPromise);
55+
}
5056

5157
createTreeView(id: string): TreeView<ComponentType> {
5258
if (!this.treeView) {
@@ -102,47 +108,35 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
102108
return this.registries;
103109
}
104110

105-
public getCompDescriptions(): Set<ComponentTypeDescription> {
111+
public async getCompDescriptions(): Promise<Set<ComponentTypeDescription>> {
112+
await this.initialComponentTypeLoadPromise;
106113
return this.compDescriptions;
107114
}
108115

109116
public getListOfRegistries(): Registry[] {
110117
return this.registries;
111118
}
112119

113-
public async getAllComponents(): Promise<void> {
114-
return new Promise<void>((resolve) => {
115-
let isError = false;
116-
this.compDescriptions.clear();
117-
void Odo.Instance.getComponentTypes().then(async (devFileComponentTypes: ComponentTypeAdapter[]) => {
118-
await this.getRegistries();
119-
devFileComponentTypes.forEach((component: ComponentTypeAdapter) => {
120-
Odo.Instance.getDetailedComponentInformation(component) //
121-
.then((componentDesc: ComponentTypeDescription) => {
122-
// eslint-disable-next-line max-nested-callbacks
123-
componentDesc.devfileData.devfile?.starterProjects?.map((starter: StarterProject) => {
124-
starter.typeName = component.name;
125-
});
126-
this.compDescriptions.add(componentDesc);
127-
128-
if (devFileComponentTypes.length === this.compDescriptions.size) {
129-
this.subject.next('refresh');
130-
resolve();
131-
}
132-
}).catch(() => {
133-
isError = true;
134-
}).finally(() => {
135-
if (isError && !this.subject.closed) {
136-
this.subject.next('refresh');
137-
resolve();
138-
}
139-
});
120+
private async reloadComponentTypeList(): Promise<void> {
121+
this.compDescriptions.clear();
122+
try {
123+
const devfileComponentTypes = await Odo.Instance.getComponentTypes();
124+
await this.getRegistries();
125+
await Promise.all(devfileComponentTypes.map(async (devfileComponentType) => {
126+
const componentDesc: ComponentTypeDescription = await Odo.Instance.getDetailedComponentInformation(devfileComponentType);
127+
componentDesc.devfileData.devfile?.starterProjects?.map((starter: StarterProject) => {
128+
starter.typeName = devfileComponentType.name;
140129
});
141-
}).catch(() => {
142-
this.subject.next('error');
143-
resolve();
144-
});
145-
});
130+
this.compDescriptions.add(componentDesc);
131+
132+
if (devfileComponentTypes.length === this.compDescriptions.size) {
133+
this.subject.next();
134+
}
135+
}));
136+
this.subject.next();
137+
} catch (_) {
138+
this.subject.next();
139+
}
146140
}
147141

148142
// eslint-disable-next-line class-methods-use-this
@@ -362,7 +356,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
362356
void Progress.execFunctionWithProgress('Devfile registry is updating',async () => {
363357
const newRegistry = await Odo.Instance.addRegistry(regName, regURL, token);
364358
ComponentTypesView.instance.addRegistry(newRegistry);
365-
await ComponentTypesView.instance.getAllComponents();
359+
await ComponentTypesView.instance.reloadComponentTypeList();
366360
ComponentTypesView.instance.refresh(false);
367361
})
368362
}
@@ -389,7 +383,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
389383
await Odo.Instance.removeRegistry(registry.name);
390384
ComponentTypesView.instance.removeRegistry(registry);
391385
if (!isEdit) {
392-
await ComponentTypesView.instance.getAllComponents();
386+
await ComponentTypesView.instance.reloadComponentTypeList();
393387
}
394388
}
395389
}

src/webview/common-ext/createComponentHelpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function validatePortNumber(portNumber: number): string {
185185
*
186186
* @returns a list of the devfile registries with their devfiles attached
187187
*/
188-
export function getDevfileRegistries(): DevfileRegistry[] {
188+
export async function getDevfileRegistries(): Promise<DevfileRegistry[]> {
189189
const registries = ComponentTypesView.instance.getListOfRegistries();
190190
if (!registries || registries.length === 0) {
191191
throw new Error('No Devfile registries available. Default registry is missing');
@@ -198,7 +198,7 @@ export function getDevfileRegistries(): DevfileRegistry[] {
198198
} as DevfileRegistry;
199199
});
200200

201-
const components = ComponentTypesView.instance.getCompDescriptions();
201+
const components = await ComponentTypesView.instance.getCompDescriptions();
202202
for (const component of components) {
203203
const devfileRegistry = devfileRegistries.find(
204204
(devfileRegistry) => format(devfileRegistry.url) === format(component.registry.url),
@@ -261,8 +261,8 @@ export function getDevfileCapabilities(): string[] {
261261
*
262262
* @returns a list of the devfile tags
263263
*/
264-
export function getDevfileTags(url?: string): string[] {
265-
const devfileRegistries = getDevfileRegistries();
264+
export async function getDevfileTags(url?: string): Promise<string[]> {
265+
const devfileRegistries = await getDevfileRegistries();
266266

267267
const devfileTags: string[] = [
268268
...new Set(

src/webview/create-component/createComponentLoader.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ComponentTypesView } from '../../registriesView';
1818
import sendTelemetry from '../../telemetry';
1919
import { ExtensionID } from '../../util/constants';
2020
import { DevfileConverter } from '../../util/devfileConverter';
21+
import { DevfileV1 } from '../../util/devfileV1Type';
2122
import { getInitialWorkspaceFolder, selectWorkspaceFolder } from '../../util/workspace';
2223
import {
2324
getDevfileCapabilities,
@@ -29,7 +30,6 @@ import {
2930
} from '../common-ext/createComponentHelpers';
3031
import { loadWebviewHtml, validateGitURL } from '../common-ext/utils';
3132
import { Devfile, DevfileRegistry, TemplateProjectIdentifier } from '../common/devfile';
32-
import { DevfileV1 } from '../../util/devfileV1Type';
3333

3434
interface CloneProcess {
3535
status: boolean;
@@ -78,15 +78,15 @@ export default class CreateComponentLoader {
7878
});
7979

8080
const registriesSubscription = ComponentTypesView.instance.subject.subscribe(() => {
81-
sendUpdatedRegistries();
81+
void sendUpdatedRegistries();
8282
});
8383

8484
const capabiliiesySubscription = ComponentTypesView.instance.subject.subscribe(() => {
8585
sendUpdatedCapabilities();
8686
});
8787

8888
const tagsSubscription = ComponentTypesView.instance.subject.subscribe(() => {
89-
sendUpdatedTags();
89+
void sendUpdatedTags();
9090
});
9191

9292
panel.onDidDispose(() => {
@@ -138,7 +138,7 @@ export default class CreateComponentLoader {
138138
case 'getDevfileRegistries': {
139139
void CreateComponentLoader.panel.webview.postMessage({
140140
action: 'devfileRegistries',
141-
data: getDevfileRegistries(),
141+
data: await getDevfileRegistries(),
142142
});
143143
break;
144144
}
@@ -158,7 +158,7 @@ export default class CreateComponentLoader {
158158
case 'getDevfileTags': {
159159
void CreateComponentLoader.panel.webview.postMessage({
160160
action: 'devfileTags',
161-
data: getDevfileTags(),
161+
data: await getDevfileTags(),
162162
});
163163
break;
164164
}
@@ -360,7 +360,7 @@ export default class CreateComponentLoader {
360360
await fs.mkdir(componentFolder, {recursive: true});
361361
await fse.copy(tmpFolder.fsPath, componentFolder);
362362
}
363-
const devfileType = getDevfileType(message.data.devfileDisplayName);
363+
const devfileType = await getDevfileType(message.data.devfileDisplayName);
364364
const componentFolderUri = Uri.file(componentFolder);
365365
if (!await isDevfileExists(componentFolderUri)) {
366366
await Odo.Instance.createComponentFromLocation(
@@ -521,7 +521,7 @@ export default class CreateComponentLoader {
521521
action: 'getRecommendedDevfileStart'
522522
});
523523
analyzeRes = await Odo.Instance.analyze(uri.fsPath);
524-
compDescriptions = getCompDescription(analyzeRes);
524+
compDescriptions = await getCompDescription(analyzeRes);
525525
} catch (error) {
526526
if (error.message.toLowerCase().indexOf('failed to parse the devfile') !== -1) {
527527
const actions: Array<string> = ['Yes', 'Cancel'];
@@ -536,7 +536,7 @@ export default class CreateComponentLoader {
536536
const devfileV1 = JSYAML.load(file.toString()) as DevfileV1;
537537
await fs.unlink(devFileV1Path);
538538
analyzeRes = await Odo.Instance.analyze(uri.fsPath);
539-
compDescriptions = getCompDescription(analyzeRes);
539+
compDescriptions = await getCompDescription(analyzeRes);
540540
const endPoints = getEndPoints(compDescriptions[0]);
541541
const devfileV2 = DevfileConverter.getInstance().devfileV1toDevfileV2(
542542
devfileV1,
@@ -562,7 +562,7 @@ export default class CreateComponentLoader {
562562
void CreateComponentLoader.panel.webview.postMessage({
563563
action: 'getRecommendedDevfile'
564564
});
565-
const devfileRegistry: DevfileRegistry[] = getDevfileRegistries();
565+
const devfileRegistry: DevfileRegistry[] = await getDevfileRegistries();
566566
const allDevfiles: Devfile[] = devfileRegistry.flatMap((registry) => registry.devfiles);
567567
const devfile: Devfile | undefined =
568568
compDescriptions.length !== 0
@@ -583,8 +583,8 @@ export default class CreateComponentLoader {
583583
}
584584
}
585585

586-
function getCompDescription(devfiles: AnalyzeResponse[]): ComponentTypeDescription[] {
587-
const compDescriptions = ComponentTypesView.instance.getCompDescriptions();
586+
async function getCompDescription(devfiles: AnalyzeResponse[]): Promise<ComponentTypeDescription[]> {
587+
const compDescriptions = await ComponentTypesView.instance.getCompDescriptions();
588588
if (devfiles.length === 0) {
589589
return Array.from(compDescriptions);
590590
}
@@ -598,9 +598,9 @@ function getCompDescription(devfiles: AnalyzeResponse[]): ComponentTypeDescripti
598598
);
599599
}
600600

601-
function getDevfileType(devfileDisplayName: string): string {
601+
async function getDevfileType(devfileDisplayName: string): Promise<string> {
602602
const compDescriptions: Set<ComponentTypeDescription> =
603-
ComponentTypesView.instance.getCompDescriptions();
603+
await ComponentTypesView.instance.getCompDescriptions();
604604
const devfileDescription: ComponentTypeDescription = Array.from(compDescriptions).find(
605605
(description) => description.displayName === devfileDisplayName,
606606
);
@@ -661,11 +661,11 @@ async function validateFolderPath(path: string) {
661661
}
662662
}
663663

664-
function sendUpdatedRegistries() {
664+
async function sendUpdatedRegistries() {
665665
if (CreateComponentLoader.panel) {
666666
void CreateComponentLoader.panel.webview.postMessage({
667667
action: 'devfileRegistries',
668-
data: getDevfileRegistries(),
668+
data: await getDevfileRegistries(),
669669
});
670670
}
671671
}
@@ -679,11 +679,11 @@ function sendUpdatedCapabilities() {
679679
}
680680
}
681681

682-
function sendUpdatedTags() {
682+
async function sendUpdatedTags() {
683683
if (CreateComponentLoader.panel) {
684684
void CreateComponentLoader.panel.webview.postMessage({
685685
action: 'devfileTags',
686-
data: getDevfileTags(),
686+
data: await getDevfileTags(),
687687
});
688688
}
689689
}

src/webview/devfile-registry/registryViewLoader.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ async function devfileRegistryViewerMessageListener(event: any): Promise<any> {
3636
})
3737
break;
3838
case 'getDevfileRegistries':
39-
RegistryViewLoader.sendUpdatedRegistries();
39+
await RegistryViewLoader.sendUpdatedRegistries();
4040
break;
4141
case 'getDevfileCapabilities':
4242
RegistryViewLoader.sendUpdatedCapabilities();
4343
break;
4444
case 'getDevfileTags':
45-
RegistryViewLoader.sendUpdatedTags();
45+
await RegistryViewLoader.sendUpdatedTags();
4646
break;
4747
case 'createComponent': {
4848
const { projectFolder, componentName } = event.data;
@@ -198,9 +198,9 @@ export default class RegistryViewLoader {
198198
return Promise.resolve();
199199
}
200200

201-
static sendUpdatedRegistries() {
201+
static async sendUpdatedRegistries() {
202202
if (panel) {
203-
let registries = getDevfileRegistries();
203+
let registries = await getDevfileRegistries();
204204
if (RegistryViewLoader.url) {
205205
registries = registries.filter((devfileRegistry) => devfileRegistry.url === RegistryViewLoader.url);
206206
}
@@ -220,24 +220,24 @@ export default class RegistryViewLoader {
220220
}
221221
}
222222

223-
static sendUpdatedTags() {
223+
static async sendUpdatedTags() {
224224
if (panel) {
225225
void panel.webview.postMessage({
226226
action: 'devfileTags',
227-
data: getDevfileTags(RegistryViewLoader.url),
227+
data: await getDevfileTags(RegistryViewLoader.url),
228228
});
229229
}
230230
}
231231
}
232232

233233
ComponentTypesView.instance.subject.subscribe(() => {
234-
RegistryViewLoader.sendUpdatedRegistries();
234+
void RegistryViewLoader.sendUpdatedRegistries();
235235
});
236236

237237
ComponentTypesView.instance.subject.subscribe(() => {
238238
RegistryViewLoader.sendUpdatedCapabilities();
239239
});
240240

241241
ComponentTypesView.instance.subject.subscribe(() => {
242-
RegistryViewLoader.sendUpdatedTags();
242+
void RegistryViewLoader.sendUpdatedTags();
243243
});

0 commit comments

Comments
 (0)