Skip to content
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 @@ import {
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 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
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 @@ 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> {
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();
}
}

// eslint-disable-next-line class-methods-use-this
Expand Down Expand Up @@ -362,7 +356,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 +383,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
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 { 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 @@ -78,15 +78,15 @@ export default class CreateComponentLoader {
});

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

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

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

panel.onDidDispose(() => {
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class CreateComponentLoader {
case 'getDevfileRegistries': {
void CreateComponentLoader.panel.webview.postMessage({
action: 'devfileRegistries',
data: getDevfileRegistries(),
data: await getDevfileRegistries(),
});
break;
}
Expand All @@ -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 @@ -661,11 +661,11 @@ async function validateFolderPath(path: string) {
}
}

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