Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
grzpab committed Dec 1, 2023
1 parent aff726a commit 9ee4fbd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/components/messageBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const enum MessageKind {

mainWebviewViewVisibilityChange = 38,
executionQueueChange = 39,

loadHomeDirectoryData = 40,
}

export type Command =
Expand Down Expand Up @@ -161,6 +163,9 @@ export type Message =
| Readonly<{
kind: MessageKind.executionQueueChange;
queuedCodemodHashes: ReadonlyArray<CodemodHash>;
}>
| Readonly<{
kind: MessageKind.loadHomeDirectoryData;
}>;

type EmitterMap<K extends MessageKind> = {
Expand Down
37 changes: 37 additions & 0 deletions src/data/readHomeDirectoryCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from './schemata/surfaceAgnosticJobSchema';
import { CodemodEntry } from '../codemods/types';
import EventEmitter from 'events';
import { MessageBus, MessageKind } from '../components/messageBus';
import { Store } from '.';

interface HomeDirectoryEventEmitter extends EventEmitter {
emit(event: 'start'): boolean;
Expand Down Expand Up @@ -205,3 +207,38 @@ export const readHomeDirectoryCases = async (

return eventEmitter;
};

export class HomeDirectoryService {
public constructor(
private readonly __messageBus: MessageBus,
private readonly __store: Store,
private readonly __rootUri: Uri | null,
) {
__messageBus.subscribe(MessageKind.loadHomeDirectoryData, async () => {
if (!this.__rootUri) {
return;
}

const eventEmitter = await readHomeDirectoryCases(
this.__rootUri,
this.__store.getState().codemod.entities,
);

const jobHandler = (kase: Case, jobs: ReadonlyArray<Job>) => {
this.__messageBus.publish({
kind: MessageKind.upsertCase,
kase,
jobs,
});
};

eventEmitter?.once('end', () => {
eventEmitter.off('job', jobHandler);
});

eventEmitter?.on('job', jobHandler);

eventEmitter?.emit('start');
});
}
}
35 changes: 12 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {
} from './data/codemodConfigSchema';
import { parsePrivateCodemodsEnvelope } from './data/privateCodemodsEnvelopeSchema';
import { GlobalStateTokenStorage, UserService } from './components/userService';
import { readHomeDirectoryCases } from './data/readHomeDirectoryCases';
import {
HomeDirectoryService,
readHomeDirectoryCases,

Check warning on line 50 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

'readHomeDirectoryCases' is defined but never used
} from './data/readHomeDirectoryCases';
import { Job } from './jobs/types';

Check warning on line 52 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

'Job' is defined but never used

export const enum SEARCH_PARAMS_KEYS {
Expand Down Expand Up @@ -1261,27 +1264,13 @@ export async function activate(context: vscode.ExtensionContext) {
kind: MessageKind.bootstrapEngine,
});

// load the cases and jobs from the homedir
if (rootUri !== null) {
const eventEmitter = await readHomeDirectoryCases(
rootUri,
store.getState().codemod.entities,
);

const jobHandler = (kase: Case, jobs: ReadonlyArray<Job>) => {
messageBus.publish({
kind: MessageKind.upsertCase,
kase,
jobs,
});
};

eventEmitter?.once('end', () => {
eventEmitter.off('job', jobHandler);
});

eventEmitter?.on('job', jobHandler);
const homeDirectoryService = new HomeDirectoryService(

Check warning on line 1267 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

'homeDirectoryService' is assigned a value but never used
messageBus,
store,
rootUri,
);

eventEmitter?.emit('start');
}
messageBus.publish({
kind: MessageKind.loadHomeDirectoryData,
});
}

0 comments on commit 9ee4fbd

Please sign in to comment.