Skip to content

Commit 0afb2ad

Browse files
committed
remove LoadPacks and getVersion calls from components-packs-webview-main.ts
1 parent 03ae955 commit 0afb2ad

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/json-rpc/csolution-rpc-client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CsolutionServiceImpl extends RpcMethods implements CsolutionService {
4343
private readonly debouncedLoadPacks = debounce(super.loadPacks.bind(this), 1000);
4444
private csolutionBin = 'csolution';
4545
private exitPromise: Promise<void> | undefined;
46+
private hasReportedVersionForSession = false;
4647
private readonly mutex: Mutex;
4748

4849
constructor(
@@ -75,6 +76,19 @@ class CsolutionServiceImpl extends RpcMethods implements CsolutionService {
7576
if (this.idxWatcher === undefined) {
7677
this.watchPackIdxFile();
7778
}
79+
80+
// Query daemon version once per launched session right before first LoadPacks.
81+
if (!this.hasReportedVersionForSession) {
82+
try {
83+
const version = await super.getVersion();
84+
console.log('csolution version:', version);
85+
} catch (error) {
86+
console.warn('Unable to query csolution version before loadPacks:', error);
87+
} finally {
88+
this.hasReportedVersionForSession = true;
89+
}
90+
}
91+
7892
return super.loadPacks();
7993
}
8094

@@ -131,6 +145,7 @@ class CsolutionServiceImpl extends RpcMethods implements CsolutionService {
131145
this.idxWatcher = undefined;
132146
this.connection?.dispose();
133147
this.connection = undefined;
148+
this.hasReportedVersionForSession = false;
134149
}
135150

136151
private async launch(): Promise<boolean> {

src/views/manage-components-packs/components-packs-webview-main.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,14 @@ describe('ComponentsPacksWebviewMain', () => {
602602
expect(stateMessages).toEqual(
603603
expect.arrayContaining([
604604
'Connecting to rpc daemon',
605-
'Loading Packs...',
606605
'Loading Solution...',
607606
'Retrieving assigned items...'
608607
])
609608
);
610-
expect(stateMessages.indexOf('Connecting to rpc daemon')).toBeLessThan(stateMessages.indexOf('Loading Packs...'));
611-
expect(stateMessages.indexOf('Loading Packs...')).toBeLessThan(stateMessages.indexOf('Loading Solution...'));
609+
expect(stateMessages.indexOf('Connecting to rpc daemon')).toBeLessThan(stateMessages.indexOf('Loading Solution...'));
610+
expect(stateMessages.indexOf('Loading Solution...')).toBeLessThan(stateMessages.indexOf('Retrieving assigned items...'));
612611

613-
expect(svc.getVersion).toHaveBeenCalled();
614-
expect(svc.loadPacks).toHaveBeenCalled();
612+
expect(svc.loadPacks).not.toHaveBeenCalled();
615613
expect(svc.loadSolution).toHaveBeenCalledWith({ solution: 'solPath', activeTarget: 'activeTs' });
616614
expect(svc.getUsedItems).toHaveBeenCalledWith({ context: 'activeCtx' });
617615
expect(svc.getPacksInfo).toHaveBeenCalledWith({ context: 'activeCtx', all: false });
@@ -634,7 +632,6 @@ describe('ComponentsPacksWebviewMain', () => {
634632
await (componentsPacksWebviewMain as any).loadSolution('solPath', 'activeTs', 'activeCtx', false);
635633

636634
// Heavy operations not called
637-
expect(svc.getVersion).not.toHaveBeenCalled();
638635
expect(svc.loadPacks).not.toHaveBeenCalled();
639636
expect(svc.loadSolution).not.toHaveBeenCalled();
640637

@@ -652,7 +649,7 @@ describe('ComponentsPacksWebviewMain', () => {
652649

653650
it('handles errors and sends error messages', async () => {
654651
const error = new Error('Boom failure');
655-
const svc = setupCsolutionServiceMocks({
652+
setupCsolutionServiceMocks({
656653
getComponentsTree: jest.fn().mockRejectedValue(error),
657654
getLogMessages: jest.fn().mockResolvedValue({
658655
errors: ['E1'],
@@ -677,9 +674,6 @@ describe('ComponentsPacksWebviewMain', () => {
677674

678675
// Ensure dirty flag cleared
679676
expect(calls.some(m => m.type === 'IS_DIRTY' && m.isDirty === false)).toBe(true);
680-
681-
// Heavy reload start still attempted before failure
682-
expect(svc.getVersion).toHaveBeenCalled();
683677
});
684678
});
685679

src/views/manage-components-packs/components-packs-webview-main.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,6 @@ export class ComponentsPacksWebviewMain {
393393
this.availablePacksCache = {};
394394
this.unlinkRequests.clear();
395395
await this.webviewManager.sendMessage({ type: 'SET_SOLUTION_STATE', stateMessage: 'Connecting to rpc daemon' });
396-
const version = await this.csolutionService.getVersion();
397-
console.log('csolution version:', version);
398-
399-
await this.webviewManager.sendMessage({ type: 'SET_SOLUTION_STATE', stateMessage: 'Loading Packs...' });
400-
await this.csolutionService.loadPacks();
401396

402397
await this.webviewManager.sendMessage({ type: 'SET_SOLUTION_STATE', stateMessage: 'Loading Solution...' });
403398
const solutionSuccess = await this.csolutionService.loadSolution({ solution: solutionPath, activeTarget: activeTargetSet });

0 commit comments

Comments
 (0)