Skip to content

Commit 0aa63de

Browse files
committed
Remove extra command
1 parent 910ca89 commit 0aa63de

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

src/manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const OUTPUT_DIRECTORY = 'outputDirectory';
4444
export const CONFIG_AUTO_DEBUG_LAUNCH = 'autoDebugLaunch';
4545
export const CONFIG_BUILD_OUTPUT_VERBOSITY = 'buildOutputVerbosity';
4646
export const MANAGE_COMPONENTS_PACKS_COMMAND_ID = `${PACKAGE_NAME}.manageComponentsPacks`;
47-
export const MERGE_FILE_FROM_PATH_COMMAND_ID = `${PACKAGE_NAME}.mergeFileFromPath`;
47+
export const MERGE_FILE_COMMAND_ID = `${PACKAGE_NAME}.mergeFile`;
4848

4949
export const MIN_TOOLBOX_VERSION = '2.12.0';
5050

src/solutions/solution-problems.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { describe, it, expect, beforeEach } from '@jest/globals';
1818
import * as vscode from 'vscode';
1919
import { ExtensionContext } from 'vscode';
20-
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_FROM_PATH_COMMAND_ID } from '../manifest';
20+
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_COMMAND_ID } from '../manifest';
2121
import * as fsUtils from '../utils/fs-utils';
2222
import * as vscodeUtils from '../utils/vscode-utils';
2323
import { solutionManagerFactory, MockSolutionManager } from './solution-manager.factories';
@@ -258,15 +258,15 @@ describe('SolutionProblems', () => {
258258

259259
expect(diagnostic?.message).toBe("update required for config file 'config.c' from component 'Device'.");
260260
expect(code.value).toBe('Open in Merge View');
261-
expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`);
261+
expect(command).toBe(`command:${MERGE_FILE_COMMAND_ID}`);
262262
expect(JSON.parse(decodeURIComponent(args))).toEqual(['/packs/Component/config.c']);
263263
});
264264

265265
it('creates a merge command uri with encoded local path', () => {
266266
const result = solutionProblems['createMergeCommandUri']('/packs/Component/config.c');
267267
const [command, args] = result.toString().split('?');
268268

269-
expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`);
269+
expect(command).toBe(`command:${MERGE_FILE_COMMAND_ID}`);
270270
expect(JSON.parse(decodeURIComponent(args))).toEqual(['/packs/Component/config.c']);
271271
});
272272

@@ -280,7 +280,7 @@ describe('SolutionProblems', () => {
280280
message: "update required for config file 'config.c' from component 'Device'.",
281281
code: {
282282
value: 'Open in Merge View',
283-
target: vscode.Uri.parse(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}?${encodeURIComponent(JSON.stringify(['/packs/Component/config.c']))}`),
283+
target: vscode.Uri.parse(`command:${MERGE_FILE_COMMAND_ID}?${encodeURIComponent(JSON.stringify(['/packs/Component/config.c']))}`),
284284
},
285285
});
286286
});
@@ -318,7 +318,7 @@ describe('SolutionProblems', () => {
318318
expect(uri.fsPath).toContain('mylayer.clayer.yml');
319319
expect(diagnostic?.message).toBe("update recommended for config file 'mylayer.clayer.yml' has a new version available for merge.");
320320
expect(code.value).toBe('Open in Merge View');
321-
expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`);
321+
expect(command).toBe(`command:${MERGE_FILE_COMMAND_ID}`);
322322
expect(JSON.parse(decodeURIComponent(args))).toEqual([layerPath]);
323323
});
324324

src/solutions/solution-problems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as path from 'node:path';
1818
import * as vscode from 'vscode';
1919
import { constructor } from '../generic/constructor';
20-
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_FROM_PATH_COMMAND_ID } from '../manifest';
20+
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_COMMAND_ID } from '../manifest';
2121
import { LogMessages } from '../json-rpc/csolution-rpc-client';
2222
import * as fsUtils from '../utils/fs-utils';
2323
import { getFileNameFromPath } from '../utils/path-utils';
@@ -337,7 +337,7 @@ export class SolutionProblemsImpl implements SolutionProblems {
337337

338338
private createMergeCommandUri(localPath: string): vscode.Uri {
339339
const args = this.encodeCommandArgs([localPath]);
340-
return vscode.Uri.parse(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}?${args}`);
340+
return vscode.Uri.parse(`command:${MERGE_FILE_COMMAND_ID}?${args}`);
341341
}
342342

343343
private createMergeDiagnosticAction(message: string, diagnosticFilePath: string): { message: string; code: NonNullable<vscode.Diagnostic['code']> } | undefined {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,43 @@ describe('MergeCommand', () => {
100100
it('registers the command on activation', async () => {
101101
await command.activate(extensionContextFactory());
102102

103-
expect(commandsProvider.registerCommand).toHaveBeenCalledTimes(2);
103+
expect(commandsProvider.registerCommand).toHaveBeenCalledTimes(1);
104104
expect(commandsProvider.registerCommand).toHaveBeenCalledWith(MergeCommand.mergeFile, expect.any(Function), expect.anything());
105-
expect(commandsProvider.registerCommand).toHaveBeenCalledWith(MergeCommand.mergeFileFromPath, expect.any(Function), expect.anything());
106105
});
107106

108-
it('forwards the mergeFileFromPath command argument to the merge handler', async () => {
107+
it('forwards string command argument to the merge handler', async () => {
109108
const runVSCodeMergeFromPathSpy = jest.spyOn(
110109
command as unknown as { runVSCodeMergeFromPath: (localPath: string) => Promise<void> },
111110
'runVSCodeMergeFromPath',
112111
).mockResolvedValue();
113112
const localPath = path.join(tmpDir, 'component.c');
114113

115114
await command.activate(extensionContextFactory());
116-
await commandsProvider.mockRunRegistered(MergeCommand.mergeFileFromPath, localPath);
115+
await commandsProvider.mockRunRegistered(MergeCommand.mergeFile, localPath);
117116

118117
expect(runVSCodeMergeFromPathSpy).toHaveBeenCalledWith(localPath);
119118
});
119+
120+
it('forwards COutlineItem command argument to the node merge handler', async () => {
121+
const runVSCodeMergeSpy = jest.spyOn(
122+
command as unknown as { runVSCodeMerge: (node: COutlineItem) => Promise<void> },
123+
'runVSCodeMerge',
124+
).mockResolvedValue();
125+
126+
await command.activate(extensionContextFactory());
127+
await commandsProvider.mockRunRegistered(MergeCommand.mergeFile, fileNode);
128+
129+
expect(runVSCodeMergeSpy).toHaveBeenCalledWith(fileNode);
130+
});
131+
132+
it('shows error for unsupported command argument type', async () => {
133+
const showErrorMessageSpy = jest.spyOn(vscode.window, 'showErrorMessage');
134+
135+
await command.activate(extensionContextFactory());
136+
await commandsProvider.mockRunRegistered(MergeCommand.mergeFile, undefined);
137+
138+
expect(showErrorMessageSpy).toHaveBeenCalledWith('Cannot open merge view: unsupported command argument.');
139+
});
120140
});
121141

122142
describe('merge file discovery', () => {

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import * as fsUtils from '../../../utils/fs-utils';
2828

2929
export class MergeCommand {
3030
public static readonly mergeFile = `${PACKAGE_NAME}.mergeFile`;
31-
public static readonly mergeFileFromPath = `${PACKAGE_NAME}.mergeFileFromPath`;
3231
private static readonly disallowedCmdChars = /[\r\n&|<>^%"']/;
3332

3433
constructor(
@@ -38,15 +37,24 @@ export class MergeCommand {
3837

3938
public async activate(context: Pick<vscode.ExtensionContext, 'subscriptions'>) {
4039
context.subscriptions.push(
41-
this.commandsProvider.registerCommand(MergeCommand.mergeFile, (node: COutlineItem) => {
42-
this.runVSCodeMerge(node);
43-
}, this),
44-
this.commandsProvider.registerCommand(MergeCommand.mergeFileFromPath, (localPath: string) => {
45-
this.runVSCodeMergeFromPath(localPath);
46-
}, this),
40+
this.commandsProvider.registerCommand(MergeCommand.mergeFile, this.handleMergeCommand, this),
4741
);
4842
}
4943

44+
private async handleMergeCommand(commandArg: COutlineItem | string | undefined): Promise<void> {
45+
if (commandArg instanceof COutlineItem) {
46+
await this.runVSCodeMerge(commandArg);
47+
return;
48+
}
49+
50+
if (typeof commandArg === 'string') {
51+
await this.runVSCodeMergeFromPath(commandArg);
52+
return;
53+
}
54+
55+
vscode.window.showErrorMessage('Cannot open merge view: unsupported command argument.');
56+
}
57+
5058
private async runVSCodeMergeFromPath(localPath: string): Promise<void> {
5159
if (!localPath) {
5260
vscode.window.showErrorMessage('Cannot open merge view: merge file path is missing.');

0 commit comments

Comments
 (0)