Skip to content

Commit 2669471

Browse files
committed
Remove triggerReload from ActiveSolutionTracker interface
1 parent 4c9c37c commit 2669471

8 files changed

Lines changed: 15 additions & 24 deletions

File tree

src/desktop/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const activate = async (context: ExtensionContext): Promise<CsolutionExte
221221
const fileDecorationProviderManager = new FileDecorationProviderManagerImpl();
222222
const treeViewProviderImpl = new TreeViewProviderImpl(SolutionOutlineView.treeViewId);
223223
const treeViewFileDecorationProvider = new TreeViewFileDecorationProvider(fileDecorationProviderManager, themeProvider);
224-
const mergeCommand = new MergeCommand(commandsProvider, activeSolutionTracker);
224+
const mergeCommand = new MergeCommand(commandsProvider);
225225
const buildCommand = new BuildCommand(buildTaskProvider, commandsProvider, buildTaskDefinitionBuilder);
226226
const runGeneratorCommand = new GeneratorCommand(commandsProvider, solutionManager, outputChannelProvider, cmsisToolboxManager);
227227
const armclangDefineGetter = new ArmclangDefineGetter(processManager, workspaceFsProvider);

src/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const CONFIG_AUTO_SHOW_CMSIS_VIEW = 'autoShowCMSISView';
4646
export const CONFIG_BUILD_OUTPUT_VERBOSITY = 'buildOutputVerbosity';
4747
export const MANAGE_COMPONENTS_PACKS_COMMAND_ID = `${PACKAGE_NAME}.manageComponentsPacks`;
4848
export const MERGE_FILE_COMMAND_ID = `${PACKAGE_NAME}.mergeFile`;
49+
export const REFRESH_COMMAND_ID = `${PACKAGE_NAME}.refresh`;
4950

5051
export const MIN_TOOLBOX_VERSION = '2.12.0';
5152

src/solutions/active-solution-tracker.factories.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export const activeSolutionTrackerFactory = makeFactory<MockActiveSolutionTracke
6969
solutions: () => [],
7070
activate: () => jest.fn(),
7171
getSolutionDetails: () => jest.fn(),
72-
triggerReload: (r) => jest.fn(() => r.onActiveSolutionFilesChangedEmitter?.fire()),
7372
suspendWatch: () => false,
7473
mockFireActiveSolutionFilesChanged: (r) => () => r.onActiveSolutionFilesChangedEmitter?.fire(),
7574
});

src/solutions/active-solution-tracker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ export interface ActiveSolutionTracker {
8383

8484
getSolutionDetails(solutionPath: string): SolutionDetails;
8585

86-
triggerReload(): void;
87-
8886
suspendWatch: boolean;
8987
}
9088

@@ -297,7 +295,7 @@ export class ActiveSolutionTrackerImpl implements ActiveSolutionTracker {
297295
return this.configurationProvider.getConfigVariable<string>(manifest.CONFIG_EXCLUDE) || undefined;
298296
}
299297

300-
public triggerReload(): void {
298+
private triggerReload(): void {
301299
this.activeSolutionFilesChangedEmitter.fire();
302300
}
303301

src/solutions/solution-manager.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'jest';
1818
import * as vscode from 'vscode';
1919
import * as path from 'path';
2020
import { SolutionLoadState, SolutionManagerImpl } from './solution-manager';
21+
import * as manifest from '../manifest';
2122
import { EventEmitter, Event, ExtensionContext, ConfigurationChangeEvent, } from 'vscode';
2223
import { ActiveSolutionTracker, SolutionDetails, } from './active-solution-tracker';
2324
import { waitTimeout } from '../__test__/test-waits';
@@ -47,7 +48,6 @@ describe('SolutionManager', () => {
4748
onDidChangeActiveSolution: Event<void>;
4849
onActiveSolutionFilesChanged: Event<void>;
4950
getSolutionDetails: jest.Mock;
50-
triggerReload: jest.Mock;
5151
suspendWatch: boolean;
5252
};
5353
let changeActiveSolutionEmitter: EventEmitter<void>;
@@ -102,7 +102,6 @@ describe('SolutionManager', () => {
102102
displayName: path.basename(solutionPath),
103103
}),
104104
),
105-
triggerReload: jest.fn(() => changeSolutionFilesEmitter.fire()),
106105
suspendWatch: false,
107106
};
108107

@@ -155,7 +154,7 @@ describe('SolutionManager', () => {
155154
it('register the command on activation', async () => {
156155
expect(commandsProvider.registerCommand).toHaveBeenCalledTimes(1);
157156
expect(commandsProvider.registerCommand).toHaveBeenCalledWith(
158-
SolutionManagerImpl.refreshCommandId,
157+
manifest.REFRESH_COMMAND_ID,
159158
expect.any(Function),
160159
expect.anything(),
161160
);
@@ -168,7 +167,7 @@ describe('SolutionManager', () => {
168167
await waitTimeout(100);
169168

170169
await commandsProvider.mockRunRegistered(
171-
SolutionManagerImpl.refreshCommandId,
170+
manifest.REFRESH_COMMAND_ID,
172171
);
173172

174173
await waitTimeout(100);

src/solutions/solution-manager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export interface SolutionManager {
7272
}
7373

7474
export class SolutionManagerImpl implements SolutionManager {
75-
public static readonly refreshCommandId = `${manifest.PACKAGE_NAME}.refresh`;
76-
7775
private readonly loadStateChangeEmitter = new vscode.EventEmitter<SolutionLoadStateChangeEvent>();
7876
public readonly onDidChangeLoadState = this.loadStateChangeEmitter.event;
7977

@@ -103,7 +101,7 @@ export class SolutionManagerImpl implements SolutionManager {
103101
this.activeSolutionTracker.onActiveSolutionFilesChanged(this.handleActiveSolutionFilesChanged, this),
104102
this.eventHub.onDidConvertCompleted(this.handleSolutionConvertCompleted, this),
105103
this.eventHub.onDidCbuildCompleted(this.handleCbuildCompleted, this),
106-
this.commandsProvider.registerCommand(SolutionManagerImpl.refreshCommandId, this.refresh, this),
104+
this.commandsProvider.registerCommand(manifest.REFRESH_COMMAND_ID, this.refresh, this),
107105
this.environmentManagerApiProvider.onActivate(environmentManagerApi => {
108106
environmentManagerApi.onDidActivate(() => {
109107
if (!this.isSolutionActivated()) {

src/views/solution-outline/commands/merge-command.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import * as vscode from 'vscode';
3636
import { extensionContextFactory } from '../../../vscode-api/extension-context.factories';
3737
import { commandsProviderFactory, MockCommandsProvider } from '../../../vscode-api/commands-provider.factories';
3838
import { MergeCommand } from './merge-command';
39-
import { activeSolutionTrackerFactory, MockActiveSolutionTracker } from '../../../solutions/active-solution-tracker.factories';
39+
import * as manifest from '../../../manifest';
4040
import { COutlineItem } from '../tree-structure/solution-outline-item';
4141
import * as child_process from 'child_process';
4242
import * as os from 'os';
@@ -48,7 +48,6 @@ jest.mock('os');
4848

4949
describe('MergeCommand', () => {
5050
let commandsProvider: MockCommandsProvider;
51-
let activeSolutionTracker: MockActiveSolutionTracker;
5251
let command: MergeCommand;
5352
const testDataHandler = new TestDataHandler();
5453
let tmpDir: string;
@@ -80,8 +79,7 @@ describe('MergeCommand', () => {
8079
fsUtils.writeTextFile(path.join(tmpDir, 'component.c.base@1.0.0'), '// base\n');
8180

8281
commandsProvider = commandsProviderFactory();
83-
activeSolutionTracker = activeSolutionTrackerFactory();
84-
command = new MergeCommand(commandsProvider, activeSolutionTracker);
82+
command = new MergeCommand(commandsProvider);
8583

8684
componentNode = new COutlineItem('component');
8785
componentNode.setTag('component');
@@ -358,7 +356,7 @@ describe('MergeCommand', () => {
358356
expect(warningSpy).toHaveBeenCalledWith('Merge exited with code 1. Conflicts may exist.');
359357
expect(deleteFileIfExistsSpy).not.toHaveBeenCalled();
360358
expect(renameFileSpy).not.toHaveBeenCalled();
361-
expect(activeSolutionTracker.triggerReload).not.toHaveBeenCalled();
359+
expect(commandsProvider.executeCommand).not.toHaveBeenCalledWith(manifest.REFRESH_COMMAND_ID);
362360
});
363361

364362
it('handles merge errors gracefully', async () => {
@@ -436,7 +434,7 @@ describe('MergeCommand', () => {
436434
expect(deleteFileIfExistsSpy).toHaveBeenCalledWith(base);
437435
expect(renameFileSpy).toHaveBeenCalledWith(update, expectedBase);
438436
expect(renameFileSpy).toHaveBeenCalledWith(merged, local);
439-
expect(activeSolutionTracker.triggerReload).toHaveBeenCalledTimes(1);
437+
expect(commandsProvider.executeCommand).toHaveBeenCalledWith(manifest.REFRESH_COMMAND_ID);
440438
});
441439
});
442440
});

src/views/solution-outline/commands/merge-command.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
import * as vscode from 'vscode';
1818
import { CommandsProvider } from '../../../vscode-api/commands-provider';
19-
import { PACKAGE_NAME } from '../../../manifest';
19+
import { PACKAGE_NAME, REFRESH_COMMAND_ID } from '../../../manifest';
2020
import { exec, ExecException, execSync } from 'child_process';
2121
import { COutlineItem } from '../tree-structure/solution-outline-item';
2222
import path from 'path';
2323
import * as os from 'os';
24-
import { ActiveSolutionTracker } from '../../../solutions/active-solution-tracker';
2524
import semver from 'semver';
2625
import { extractVersion } from '../../../utils/string-utils';
2726
import * as fsUtils from '../../../utils/fs-utils';
@@ -32,7 +31,6 @@ export class MergeCommand {
3231

3332
constructor(
3433
private readonly commandsProvider: CommandsProvider,
35-
private readonly activeSolutionTracker: ActiveSolutionTracker,
3634
) { }
3735

3836
public async activate(context: Pick<vscode.ExtensionContext, 'subscriptions'>) {
@@ -121,7 +119,7 @@ export class MergeCommand {
121119
}
122120

123121
if (exitCode === 0 && mergedMTimeAfter > mergedMTimeBefore) {
124-
this.performPostMergeOperations(local, update, base, merged);
122+
await this.performPostMergeOperations(local, update, base, merged);
125123
}
126124

127125
} catch (err) {
@@ -149,7 +147,7 @@ export class MergeCommand {
149147
return { local, update, base };
150148
}
151149

152-
private performPostMergeOperations(local: string, update: string, base: string, merged: string): void {
150+
private async performPostMergeOperations(local: string, update: string, base: string, merged: string): Promise<void> {
153151
// create .bak file of local file
154152
const backupPath = `${local}.bak`;
155153
fsUtils.copyFile(local, backupPath);
@@ -170,7 +168,7 @@ export class MergeCommand {
170168
fsUtils.renameFile(merged, local);
171169

172170
// refresh tree view to update file status
173-
this.activeSolutionTracker.triggerReload();
171+
await this.commandsProvider.executeCommand(REFRESH_COMMAND_ID);
174172
}
175173

176174
private getVSCodeExecutablePath(): string | undefined {

0 commit comments

Comments
 (0)