Skip to content

Commit 49b4bdd

Browse files
committed
Use REFRESH_COMMAND_ID
1 parent fe6e3c9 commit 49b4bdd

3 files changed

Lines changed: 20 additions & 14 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 mergeSessionCoordinator = new MergeSessionCoordinatorImpl(solutionManager);
224+
const mergeSessionCoordinator = new MergeSessionCoordinatorImpl(commandsProvider);
225225
const mergeCommand = new MergeCommand(commandsProvider, mergeSessionCoordinator);
226226
const buildCommand = new BuildCommand(buildTaskProvider, commandsProvider, buildTaskDefinitionBuilder);
227227
const runGeneratorCommand = new GeneratorCommand(commandsProvider, solutionManager, outputChannelProvider, cmsisToolboxManager);

src/views/solution-outline/commands/merge-session-coordinator.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import * as vscode from 'vscode';
2121
import { TestDataHandler } from '../../../__test__/test-data';
2222
import { MergeSessionCoordinatorImpl } from './merge-session-coordinator';
2323
import * as fsUtils from '../../../utils/fs-utils';
24+
import { commandsProviderFactory, MockCommandsProvider } from '../../../vscode-api/commands-provider.factories';
25+
import { REFRESH_COMMAND_ID } from '../../../manifest';
2426

2527
describe('MergeSessionCoordinator', () => {
2628
const testDataHandler = new TestDataHandler();
2729
let tmpDir: string;
28-
let solutionManager: { refresh: jest.Mock<Promise<void>, []> };
30+
let commandsProvider: MockCommandsProvider;
2931
let coordinator: MergeSessionCoordinatorImpl;
3032
let saveEmitter: vscode.EventEmitter<vscode.TextDocument>;
3133

@@ -39,11 +41,10 @@ describe('MergeSessionCoordinator', () => {
3941
saveEmitter = new vscode.EventEmitter<vscode.TextDocument>();
4042
(vscode.workspace as unknown as { onDidSaveTextDocument: vscode.Event<vscode.TextDocument> }).onDidSaveTextDocument = saveEmitter.event;
4143

42-
solutionManager = {
43-
refresh: jest.fn().mockResolvedValue(),
44-
};
44+
commandsProvider = commandsProviderFactory();
45+
commandsProvider.executeCommand.mockResolvedValue(undefined);
4546

46-
coordinator = new MergeSessionCoordinatorImpl(solutionManager);
47+
coordinator = new MergeSessionCoordinatorImpl(commandsProvider);
4748

4849
await coordinator.activate({ subscriptions: [] } as unknown as vscode.ExtensionContext);
4950
});
@@ -76,7 +77,8 @@ describe('MergeSessionCoordinator', () => {
7677
expect(fsUtils.fileExists(update)).toBeTruthy();
7778
expect(fsUtils.fileExists(`${local}.bak`)).toBeFalsy();
7879

79-
expect(solutionManager.refresh).toHaveBeenCalledTimes(1);
80+
expect(commandsProvider.executeCommand).toHaveBeenCalledTimes(1);
81+
expect(commandsProvider.executeCommand).toHaveBeenCalledWith(REFRESH_COMMAND_ID);
8082
});
8183

8284
it('ignores save events for unrelated files', async () => {
@@ -96,7 +98,7 @@ describe('MergeSessionCoordinator', () => {
9698
handleDidSaveTextDocument: (document: vscode.TextDocument) => Promise<void>
9799
}).handleDidSaveTextDocument({ uri: { fsPath: path.join(tmpDir, 'other.c') } } as vscode.TextDocument);
98100

99-
expect(solutionManager.refresh).not.toHaveBeenCalled();
101+
expect(commandsProvider.executeCommand).not.toHaveBeenCalled();
100102
expect(fsUtils.fileExists(merged)).toBeTruthy();
101103
});
102104

@@ -118,7 +120,7 @@ describe('MergeSessionCoordinator', () => {
118120
handleDidSaveTextDocument: (document: vscode.TextDocument) => Promise<void>
119121
}).handleDidSaveTextDocument({ uri: { fsPath: merged } } as vscode.TextDocument);
120122

121-
expect(solutionManager.refresh).not.toHaveBeenCalled();
123+
expect(commandsProvider.executeCommand).not.toHaveBeenCalled();
122124
expect(fsUtils.fileExists(merged)).toBeTruthy();
123125
});
124126

@@ -138,6 +140,7 @@ describe('MergeSessionCoordinator', () => {
138140

139141
expect(fsUtils.fileExists(local)).toBeTruthy();
140142
expect(fsUtils.readTextFile(local)).toContain('// merged');
141-
expect(solutionManager.refresh).toHaveBeenCalledTimes(1);
143+
expect(commandsProvider.executeCommand).toHaveBeenCalledTimes(1);
144+
expect(commandsProvider.executeCommand).toHaveBeenCalledWith(REFRESH_COMMAND_ID);
142145
});
143146
});

src/views/solution-outline/commands/merge-session-coordinator.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
import * as path from 'path';
1818
import * as vscode from 'vscode';
19-
import type { SolutionManager } from '../../../solutions/solution-manager';
19+
import { REFRESH_COMMAND_ID } from '../../../manifest';
2020
import * as fsUtils from '../../../utils/fs-utils';
2121
import { pathsEqual } from '../../../utils/path-utils';
22+
import type { CommandsProvider } from '../../../vscode-api/commands-provider';
2223

2324
export interface MergeSessionFiles {
2425
local: string;
@@ -40,7 +41,7 @@ export class MergeSessionCoordinatorImpl implements MergeSessionCoordinator {
4041
private finalizing = false;
4142

4243
constructor(
43-
private readonly solutionManager: Pick<SolutionManager, 'refresh'>,
44+
private readonly commandsProvider: Pick<CommandsProvider, 'executeCommand'>,
4445
) {
4546
}
4647

@@ -77,7 +78,7 @@ export class MergeSessionCoordinatorImpl implements MergeSessionCoordinator {
7778
}
7879
// Keep save handling non-destructive while the merge editor is still open.
7980
// The actual file rename/delete operations are performed on merge process exit.
80-
await this.solutionManager.refresh();
81+
void this.commandsProvider.executeCommand(REFRESH_COMMAND_ID);
8182
}
8283

8384
private async tryFinalizeOnExit(): Promise<void> {
@@ -95,7 +96,9 @@ export class MergeSessionCoordinatorImpl implements MergeSessionCoordinator {
9596
try {
9697
this.performPostMergeOperations(session);
9798
this.activeSession = undefined;
98-
await this.solutionManager.refresh();
99+
// Await is required here so merge finalization is not reported complete
100+
// before the refresh command has finished processing.
101+
await this.commandsProvider.executeCommand(REFRESH_COMMAND_ID);
99102
} finally {
100103
this.finalizing = false;
101104
}

0 commit comments

Comments
 (0)