Skip to content

Commit 57ba12d

Browse files
committed
Scope mock commands
The command lint expects all command palette commands to have a common prefix which these violated. So, I've moved them to being a scoped command so we can have different lints.
1 parent a032678 commit 57ba12d

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

extensions/ql-vscode/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -647,15 +647,15 @@
647647
"enablement": "codeql.hasQLSource"
648648
},
649649
{
650-
"command": "codeQL.mockGitHubApiServer.startRecording",
650+
"command": "codeQLMockGitHubApiServer.startRecording",
651651
"title": "CodeQL Mock GitHub API Server: Start Scenario Recording"
652652
},
653653
{
654-
"command": "codeQL.mockGitHubApiServer.saveScenario",
654+
"command": "codeQLMockGitHubApiServer.saveScenario",
655655
"title": "CodeQL Mock GitHub API Server: Save Scenario"
656656
},
657657
{
658-
"command": "codeQL.mockGitHubApiServer.cancelRecording",
658+
"command": "codeQLMockGitHubApiServer.cancelRecording",
659659
"title": "CodeQL Mock GitHub API Server: Cancel Scenario"
660660
}
661661
],
@@ -1118,16 +1118,16 @@
11181118
"when": "false"
11191119
},
11201120
{
1121-
"command": "codeQL.mockGitHubApiServer.startRecording",
1122-
"when": "config.codeQL.variantAnalysis.mockGitHubApiServer && !codeQL.mockGitHubApiServer.recording"
1121+
"command": "codeQLMockGitHubApiServer.startRecording",
1122+
"when": "config.codeQL.variantAnalysis.mockGitHubApiServer && !codeQLMockGitHubApiServer.recording"
11231123
},
11241124
{
1125-
"command": "codeQL.mockGitHubApiServer.saveScenario",
1126-
"when": "codeQL.mockGitHubApiServer.recording"
1125+
"command": "codeQLMockGitHubApiServer.saveScenario",
1126+
"when": "codeQLMockGitHubApiServer.recording"
11271127
},
11281128
{
1129-
"command": "codeQL.mockGitHubApiServer.cancelRecording",
1130-
"when": "codeQL.mockGitHubApiServer.recording"
1129+
"command": "codeQLMockGitHubApiServer.cancelRecording",
1130+
"when": "codeQLMockGitHubApiServer.recording"
11311131
}
11321132
],
11331133
"editor/context": [

extensions/ql-vscode/src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,19 +1195,19 @@ async function activateWithInstalledDistribution(
11951195
ctx.subscriptions.push(mockServer);
11961196
ctx.subscriptions.push(
11971197
commandRunner(
1198-
'codeQL.mockGitHubApiServer.startRecording',
1198+
'codeQLMockGitHubApiServer.startRecording',
11991199
async () => await mockServer.recordScenario(),
12001200
)
12011201
);
12021202
ctx.subscriptions.push(
12031203
commandRunner(
1204-
'codeQL.mockGitHubApiServer.saveScenario',
1204+
'codeQLMockGitHubApiServer.saveScenario',
12051205
async () => await mockServer.saveScenario(),
12061206
)
12071207
);
12081208
ctx.subscriptions.push(
12091209
commandRunner(
1210-
'codeQL.mockGitHubApiServer.cancelRecording',
1210+
'codeQLMockGitHubApiServer.cancelRecording',
12111211
async () => await mockServer.cancelRecording(),
12121212
)
12131213
);

extensions/ql-vscode/src/mocks/mock-gh-api-server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class MockGitHubApiServer extends DisposableObject {
5656
}
5757

5858
this.recorder.start();
59-
await commands.executeCommand('setContext', 'codeQL.mockGitHubApiServer.recording', true);
59+
await commands.executeCommand('setContext', 'codeQLMockGitHubApiServer.recording', true);
6060

6161
await window.showInformationMessage('Recording scenario. To save the scenario, use the "CodeQL Mock GitHub API Server: Save Scenario" command.');
6262
}
@@ -67,7 +67,7 @@ export class MockGitHubApiServer extends DisposableObject {
6767
return;
6868
}
6969

70-
await commands.executeCommand('setContext', 'codeQL.mockGitHubApiServer.recording', false);
70+
await commands.executeCommand('setContext', 'codeQLMockGitHubApiServer.recording', false);
7171

7272
if (!this.recorder.isRecording) {
7373
void window.showErrorMessage('No scenario is currently being recorded.');
@@ -112,7 +112,7 @@ export class MockGitHubApiServer extends DisposableObject {
112112
}
113113

114114
private async stopRecording(): Promise<void> {
115-
await commands.executeCommand('setContext', 'codeQL.mockGitHubApiServer.recording', false);
115+
await commands.executeCommand('setContext', 'codeQLMockGitHubApiServer.recording', false);
116116

117117
await this.recorder.stop();
118118
await this.recorder.clear();

extensions/ql-vscode/test/pure-tests/command-lint.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('commands declared in package.json', function() {
2727
const scopedCmds: Set<string> = new Set<string>();
2828
const commandTitles: { [cmd: string]: string } = {};
2929

30+
// These are commands which are only used for testing/development
31+
const testCmds = new Set<string>();
32+
3033
commands.forEach((commandDecl: CmdDecl) => {
3134
const { command, title } = commandDecl;
3235
if (
@@ -48,6 +51,13 @@ describe('commands declared in package.json', function() {
4851
expect(title).not.to.be.undefined;
4952
commandTitles[command] = title!;
5053
}
54+
else if (
55+
command.match(/^codeQLMockGitHubApiServer\./)
56+
) {
57+
testCmds.add(command);
58+
expect(title).not.to.be.undefined;
59+
commandTitles[command] = title!;
60+
}
5161
else {
5262
expect.fail(`Unexpected command name ${command}`);
5363
}
@@ -82,13 +92,22 @@ describe('commands declared in package.json', function() {
8292
scopedCmds.forEach(command => {
8393
expect(commandTitles[command], `command ${command} should not be prefixed with 'CodeQL: ', since it is accessible from an extension-controlled context`).not.to.match(/^CodeQL: /);
8494
});
95+
96+
testCmds.forEach(command => {
97+
expect(commandTitles[command], `command ${command} should be prefixed with 'CodeQL ', since it is a testing/development command`).to.match(/^CodeQL /);
98+
expect(commandTitles[command], `command ${command} should not be prefixed with 'CodeQL: ', since it is a testing/development command`).not.to.match(/^CodeQL: /);
99+
});
85100
});
86101

87102
it('should have the right commands accessible from the command palette', function() {
88103
paletteCmds.forEach(command => {
89104
expect(disabledInPalette.has(command), `command ${command} should be enabled in the command palette`).to.be.false;
90105
});
91106

107+
testCmds.forEach(command => {
108+
expect(disabledInPalette.has(command), `command ${command} should be enabled in the command palette`).to.be.false;
109+
});
110+
92111
// Commands in contribContextMenuCmds may reasonbly be enabled or
93112
// disabled in the command palette; for example, codeQL.runQuery
94113
// is available there, since we heuristically figure out which

0 commit comments

Comments
 (0)