Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not call getAllComponents() in activate #3880

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
70 changes: 32 additions & 38 deletions src/registriesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
QuickInputButtons, QuickPickItem, ThemeIcon, TreeDataProvider,
TreeItem, TreeItemCollapsibleState, TreeView, Uri, window
} from 'vscode';
import { quickBtn, inputValue } from './util/inputValue';
import {
ComponentTypeAdapter,
ComponentTypeDescription,
DevfileComponentType,
Registry
} 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 @@ -46,7 +45,14 @@
readonly odo = Odo.Instance;
private registries: Registry[];
private readonly compDescriptions: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
public subject: Subject<string> = new Subject<string>();
public subject: Subject<void> = new Subject<void>();

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) {
Expand Down Expand Up @@ -102,47 +108,35 @@
return this.registries;
}

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

Check warning on line 112 in src/registriesView.ts

View check run for this annotation

Codecov / codecov/patch

src/registriesView.ts#L111-L112

Added lines #L111 - L112 were not covered by tests
return this.compDescriptions;
}

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

public async getAllComponents(): Promise<void> {
return new Promise<void>((resolve) => {
let isError = false;
this.compDescriptions.clear();
void Odo.Instance.getComponentTypes().then(async (devFileComponentTypes: ComponentTypeAdapter[]) => {
await this.getRegistries();
devFileComponentTypes.forEach((component: ComponentTypeAdapter) => {
Odo.Instance.getDetailedComponentInformation(component) //
.then((componentDesc: ComponentTypeDescription) => {
// eslint-disable-next-line max-nested-callbacks
componentDesc.devfileData.devfile?.starterProjects?.map((starter: StarterProject) => {
starter.typeName = component.name;
});
this.compDescriptions.add(componentDesc);

if (devFileComponentTypes.length === this.compDescriptions.size) {
this.subject.next('refresh');
resolve();
}
}).catch(() => {
isError = true;
}).finally(() => {
if (isError && !this.subject.closed) {
this.subject.next('refresh');
resolve();
}
});
private async reloadComponentTypeList(): Promise<void> {
this.compDescriptions.clear();
try {
const devfileComponentTypes = await Odo.Instance.getComponentTypes();
await this.getRegistries();
await Promise.all(devfileComponentTypes.map(async (devfileComponentType) => {
const componentDesc: ComponentTypeDescription = await Odo.Instance.getDetailedComponentInformation(devfileComponentType);
componentDesc.devfileData.devfile?.starterProjects?.map((starter: StarterProject) => {
starter.typeName = devfileComponentType.name;
});
}).catch(() => {
this.subject.next('error');
resolve();
});
});
this.compDescriptions.add(componentDesc);

if (devfileComponentTypes.length === this.compDescriptions.size) {
this.subject.next();
}
}));
this.subject.next();
} catch (_) {
this.subject.next();

Check warning on line 138 in src/registriesView.ts

View check run for this annotation

Codecov / codecov/patch

src/registriesView.ts#L138

Added line #L138 was not covered by tests
}
}

// eslint-disable-next-line class-methods-use-this
Expand Down Expand Up @@ -362,7 +356,7 @@
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();

Check warning on line 359 in src/registriesView.ts

View check run for this annotation

Codecov / codecov/patch

src/registriesView.ts#L359

Added line #L359 was not covered by tests
ComponentTypesView.instance.refresh(false);
})
}
Expand All @@ -389,7 +383,7 @@
await Odo.Instance.removeRegistry(registry.name);
ComponentTypesView.instance.removeRegistry(registry);
if (!isEdit) {
await ComponentTypesView.instance.getAllComponents();
await ComponentTypesView.instance.reloadComponentTypeList();

Check warning on line 386 in src/registriesView.ts

View check run for this annotation

Codecov / codecov/patch

src/registriesView.ts#L386

Added line #L386 was not covered by tests
}
}
}
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 @@
*
* @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 @@
} as DevfileRegistry;
});

const components = ComponentTypesView.instance.getCompDescriptions();
const components = await ComponentTypesView.instance.getCompDescriptions();

Check warning on line 201 in src/webview/common-ext/createComponentHelpers.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/common-ext/createComponentHelpers.ts#L201

Added line #L201 was not covered by tests
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 @@
*
* @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();

Check warning on line 265 in src/webview/common-ext/createComponentHelpers.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/common-ext/createComponentHelpers.ts#L265

Added line #L265 was not covered by tests

const devfileTags: string[] = [
...new Set(
Expand Down
34 changes: 17 additions & 17 deletions src/webview/create-component/createComponentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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 @@
} 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 @@ -78,15 +78,15 @@
});

const registriesSubscription = ComponentTypesView.instance.subject.subscribe(() => {
sendUpdatedRegistries();
void sendUpdatedRegistries();

Check warning on line 81 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L81

Added line #L81 was not covered by tests
});

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

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

Check warning on line 89 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L89

Added line #L89 was not covered by tests
});

panel.onDidDispose(() => {
Expand Down Expand Up @@ -138,7 +138,7 @@
case 'getDevfileRegistries': {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileRegistries',
data: getDevfileRegistries(),
data: await getDevfileRegistries(),
});
break;
}
Expand All @@ -158,7 +158,7 @@
case 'getDevfileTags': {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileTags',
data: getDevfileTags(),
data: await getDevfileTags(),
});
break;
}
Expand Down Expand Up @@ -360,7 +360,7 @@
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);

Check warning on line 363 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L363

Added line #L363 was not covered by tests
const componentFolderUri = Uri.file(componentFolder);
if (!await isDevfileExists(componentFolderUri)) {
await Odo.Instance.createComponentFromLocation(
Expand Down Expand Up @@ -521,7 +521,7 @@
action: 'getRecommendedDevfileStart'
});
analyzeRes = await Odo.Instance.analyze(uri.fsPath);
compDescriptions = getCompDescription(analyzeRes);
compDescriptions = await getCompDescription(analyzeRes);

Check warning on line 524 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L524

Added line #L524 was not covered by tests
} 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 @@
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);

Check warning on line 539 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L539

Added line #L539 was not covered by tests
const endPoints = getEndPoints(compDescriptions[0]);
const devfileV2 = DevfileConverter.getInstance().devfileV1toDevfileV2(
devfileV1,
Expand All @@ -562,7 +562,7 @@
void CreateComponentLoader.panel.webview.postMessage({
action: 'getRecommendedDevfile'
});
const devfileRegistry: DevfileRegistry[] = getDevfileRegistries();
const devfileRegistry: DevfileRegistry[] = await getDevfileRegistries();

Check warning on line 565 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L565

Added line #L565 was not covered by tests
const allDevfiles: Devfile[] = devfileRegistry.flatMap((registry) => registry.devfiles);
const devfile: Devfile | undefined =
compDescriptions.length !== 0
Expand All @@ -583,8 +583,8 @@
}
}

function getCompDescription(devfiles: AnalyzeResponse[]): ComponentTypeDescription[] {
const compDescriptions = ComponentTypesView.instance.getCompDescriptions();
async function getCompDescription(devfiles: AnalyzeResponse[]): Promise<ComponentTypeDescription[]> {
const compDescriptions = await ComponentTypesView.instance.getCompDescriptions();

Check warning on line 587 in src/webview/create-component/createComponentLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/create-component/createComponentLoader.ts#L587

Added line #L587 was not covered by tests
if (devfiles.length === 0) {
return Array.from(compDescriptions);
}
Expand All @@ -598,9 +598,9 @@
);
}

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 @@ -661,11 +661,11 @@
}
}

function sendUpdatedRegistries() {
async function sendUpdatedRegistries() {
if (CreateComponentLoader.panel) {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileRegistries',
data: getDevfileRegistries(),
data: await getDevfileRegistries(),
});
}
}
Expand All @@ -679,11 +679,11 @@
}
}

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 @@
})
break;
case 'getDevfileRegistries':
RegistryViewLoader.sendUpdatedRegistries();
await RegistryViewLoader.sendUpdatedRegistries();

Check warning on line 39 in src/webview/devfile-registry/registryViewLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/devfile-registry/registryViewLoader.ts#L39

Added line #L39 was not covered by tests
break;
case 'getDevfileCapabilities':
RegistryViewLoader.sendUpdatedCapabilities();
break;
case 'getDevfileTags':
RegistryViewLoader.sendUpdatedTags();
await RegistryViewLoader.sendUpdatedTags();

Check warning on line 45 in src/webview/devfile-registry/registryViewLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/devfile-registry/registryViewLoader.ts#L45

Added line #L45 was not covered by tests
break;
case 'createComponent': {
const { projectFolder, componentName } = event.data;
Expand Down Expand Up @@ -198,9 +198,9 @@
return Promise.resolve();
}

static sendUpdatedRegistries() {
static async sendUpdatedRegistries() {
if (panel) {
let registries = getDevfileRegistries();
let registries = await getDevfileRegistries();

Check warning on line 203 in src/webview/devfile-registry/registryViewLoader.ts

View check run for this annotation

Codecov / codecov/patch

src/webview/devfile-registry/registryViewLoader.ts#L203

Added line #L203 was not covered by tests
if (RegistryViewLoader.url) {
registries = registries.filter((devfileRegistry) => devfileRegistry.url === RegistryViewLoader.url);
}
Expand All @@ -220,24 +220,24 @@
}
}

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();
});
Loading