Skip to content

Commit e6e9d3a

Browse files
Use constants to reference commands in the status bar item
For eng/ide/ada_language_server#1520
1 parent 3ccd882 commit e6e9d3a

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import {
2323
createSparkTaskProvider,
2424
} from './taskProviders';
2525
import { isAbsolute } from 'path';
26+
import {
27+
CMD_SHOW_EXTENSION_LOGS,
28+
CMD_SHOW_ADA_LS_OUTPUT,
29+
CMD_SHOW_GPR_LS_OUTPUT,
30+
CMD_RELOAD_PROJECT,
31+
CMD_RESTART_LANG_SERVERS,
32+
} from './commands';
2633

2734
/**
2835
* Return type of the 'als-source-dirs' LSP request.
@@ -268,18 +275,18 @@ export class ExtensionState {
268275
this.statusBar.tooltip.appendMarkdown('\n\n---\n\n');
269276
}
270277
this.statusBar.tooltip.appendMarkdown(
271-
`[$(terminal) Open Extension Logs](command:ada.showExtensionOutput
278+
`[$(terminal) Open Extension Logs](command:${CMD_SHOW_EXTENSION_LOGS}
272279
"Show Ada Extension Output")
273280
274-
[$(terminal) Open Logs for Ada & SPARK](command:ada.showAdaLSOutput
281+
[$(terminal) Open Logs for Ada & SPARK](command:${CMD_SHOW_ADA_LS_OUTPUT}
275282
"Show Ada Language Server for Ada & SPARK Output")
276283
277-
[$(terminal) Open Logs for GPR](command:ada.showGprLSOutput
284+
[$(terminal) Open Logs for GPR](command:${CMD_SHOW_GPR_LS_OUTPUT}
278285
"Show Ada Language Server for GPR Output")
279286
280-
[$(refresh) Reload Project](command:als-reload-project "Reload Project")
287+
[$(refresh) Reload Project](command:${CMD_RELOAD_PROJECT} "Reload Project")
281288
282-
[$(debug-restart) Restart Language Servers](command:ada.restartLanguageServers
289+
[$(debug-restart) Restart Language Servers](command:${CMD_RESTART_LANG_SERVERS}
283290
"Restart Ada Language Servers")`,
284291
);
285292
};

integration/vscode/ada/src/alsExecuteCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ReplaceTypeCommandArgs,
4141
} from './refactoring/alsReplaceTypeCommand';
4242
import { adaExtState } from './extension';
43+
import { CMD_RELOAD_PROJECT } from './commands';
4344

4445
/**
4546
* Type alias for a function that intercepts a command and executes it by return a promise that
@@ -90,7 +91,7 @@ export const alsCommandExecutor = (client: LanguageClient): CommandExecutor => {
9091
args[0] as ReplaceTypeCommandArgs,
9192
);
9293
if (!proceedWithExecution) return Promise.resolve(undefined);
93-
} else if (command === 'als-reload-project') {
94+
} else if (command === CMD_RELOAD_PROJECT) {
9495
// Clear the cache and the predefined tasks when the project
9596
// has been reloaded.
9697
adaExtState.clearCacheAndTasks('project is being reloaded: clearing caches and tasks');

integration/vscode/ada/src/commands.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,35 @@ export const CMD_SPARK_LIMIT_SUBP_ARG = 'ada.spark.limitSubpArg';
8686
export const CMD_SPARK_LIMIT_REGION_ARG = 'ada.spark.limitRegionArg';
8787
export const CMD_SPARK_PROVE_SUBP = 'ada.spark.proveSubprogram';
8888

89+
/**
90+
* Identifier for the command that shows the extension's output in the Output panel.
91+
*/
92+
export const CMD_SHOW_EXTENSION_LOGS = 'ada.showExtensionOutput';
93+
94+
/**
95+
* Identifier for the command that shows the output of the ALS for Ada in the Output panel.
96+
*/
97+
export const CMD_SHOW_ADA_LS_OUTPUT = 'ada.showAdaLSOutput';
98+
99+
/**
100+
* Identifier for the command that shows the output of the ALS for GPR in the Output panel.
101+
*/
102+
export const CMD_SHOW_GPR_LS_OUTPUT = 'ada.showGprLSOutput';
103+
104+
/**
105+
* Identifier for the command that reloads the currently loaded project on server-side.
106+
*/
107+
export const CMD_RELOAD_PROJECT = 'als-reload-project';
108+
109+
/**
110+
* Identifier for the command that restarts all the language servers spawned by the extension
111+
* (Ada and GPR).
112+
*/
113+
export const CMD_RESTART_LANG_SERVERS = 'ada.restartLanguageServers';
114+
89115
export function registerCommands(context: vscode.ExtensionContext, clients: ExtensionState) {
90116
context.subscriptions.push(
91-
vscode.commands.registerCommand('ada.restartLanguageServers', restartLanguageServers),
117+
vscode.commands.registerCommand(CMD_RESTART_LANG_SERVERS, restartLanguageServers),
92118
);
93119
context.subscriptions.push(
94120
vscode.commands.registerCommand('ada.createHelloWorldProject', createHelloWorldProject),
@@ -116,15 +142,15 @@ export function registerCommands(context: vscode.ExtensionContext, clients: Exte
116142
vscode.commands.registerCommand('ada.subprogramBox', addSubprogramBoxCommand),
117143
);
118144
context.subscriptions.push(
119-
vscode.commands.registerCommand('ada.showExtensionOutput', () => mainOutputChannel.show()),
145+
vscode.commands.registerCommand(CMD_SHOW_EXTENSION_LOGS, () => mainOutputChannel.show()),
120146
);
121147
context.subscriptions.push(
122-
vscode.commands.registerCommand('ada.showAdaLSOutput', () =>
148+
vscode.commands.registerCommand(CMD_SHOW_ADA_LS_OUTPUT, () =>
123149
clients.adaClient.outputChannel.show(),
124150
),
125151
);
126152
context.subscriptions.push(
127-
vscode.commands.registerCommand('ada.showGprLSOutput', () =>
153+
vscode.commands.registerCommand(CMD_SHOW_GPR_LS_OUTPUT, () =>
128154
clients.gprClient.outputChannel.show(),
129155
),
130156
);

integration/vscode/ada/test/general/extension.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { activate, assertEqualToFileContent } from '../utils';
55

66
import { readFileSync, writeFileSync } from 'fs';
77
import * as vscode from 'vscode';
8+
import { CMD_RESTART_LANG_SERVERS } from '../../src/commands';
89

910
suite('Extensions Test Suite', function () {
1011
// Make sure the extension is activated
@@ -139,7 +140,7 @@ suite('Extensions Test Suite', function () {
139140
// Restart the server and check that we still have the same project
140141
// loaded on ALS side
141142
const oldAlsUri = await adaExtState.getProjectUri();
142-
await vscode.commands.executeCommand('ada.restartLanguageServers');
143+
await vscode.commands.executeCommand(CMD_RESTART_LANG_SERVERS);
143144
const newAlsUri = await adaExtState.getProjectUri();
144145
assert.deepStrictEqual(
145146
oldAlsUri?.fsPath,

0 commit comments

Comments
 (0)