Skip to content

Commit 1f93946

Browse files
Merge branch 'topic/do_not_show_again' into 'master'
Add a 'Do not show again' button in missing dirs' popup See merge request eng/ide/ada_language_server!1473
2 parents 5a09d97 + 4fbad6e commit 1f93946

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

integration/vscode/ada/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@
695695
},
696696
{
697697
"command": "ada.addMissingDirsToWorkspace",
698-
"title": "Ada: Add missing source directories to workspace",
698+
"title": "Ada: Add Missing Source Directories To Workspace",
699699
"when": "ADA_PROJECT_CONTEXT"
700700
},
701701
{

integration/vscode/ada/src/commands.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { getOrAskForProgram } from './debugConfigProvider';
99
import { adaExtState, mainOutputChannel } from './extension';
1010
import { getProjectFileRelPath } from './helpers';
1111
import { CustomTaskDefinition, getEnclosingSymbol } from './taskProviders';
12-
import { LanguageClient } from 'vscode-languageclient/node';
1312

1413
export function registerCommands(context: vscode.ExtensionContext, clients: ExtensionState) {
1514
context.subscriptions.push(vscode.commands.registerCommand('ada.otherFile', otherFileHandler));
@@ -52,15 +51,11 @@ export function registerCommands(context: vscode.ExtensionContext, clients: Exte
5251
'ada.addMissingDirsToWorkspace',
5352
async (
5453
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
55-
displayPopupWhenMissing: boolean = false,
54+
atStartup: boolean = false,
5655
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
57-
displayPopupOnSuccess: boolean = true
56+
displayYesNoPopup: boolean = true
5857
) => {
59-
await checkSrcDirectories(
60-
clients.adaClient,
61-
displayPopupWhenMissing,
62-
displayPopupOnSuccess
63-
);
58+
await checkSrcDirectories(atStartup, displayYesNoPopup);
6459
}
6560
)
6661
);
@@ -362,26 +357,27 @@ const otherFileHandler = () => {
362357
* Do nothing if the user did not setup any workspace file.
363358
*
364359
* @param alsClient - the running ALS client
365-
* @param displayPopupWhenMissing - whether or not we should display a yes/no popup
360+
* @param atStartup - whether or not the command is triggered when activating the extension
361+
* or explicitly by the user later via the Command Palette
362+
* @param displayYesNoPopup - whether or not we should display a yes/no popup
366363
* when missing directories
367-
* @param displayPopupOnSuccess - whether or not we should display a popup to notify
368-
* the user that there is no missing directory
369364
*/
370-
export async function checkSrcDirectories(
371-
alsClient: LanguageClient,
372-
displayPopupWhenMissing = true,
373-
displayPopupOnSuccess = true
374-
) {
365+
export async function checkSrcDirectories(atStartup = false, displayYesNoPopup = true) {
375366
type ALSSourceDirDescription = {
376367
name: string;
377368
uri: string;
378369
};
379370

380371
const foldersInSettings = vscode.workspace.getConfiguration().get('folders');
372+
const alsClient = adaExtState.adaClient;
373+
const doNotShowAgainKey = 'ada.addMissingDirsToWorkspace.doNotShowAgain';
374+
const doNotShowAgain = adaExtState.context.workspaceState.get(doNotShowAgainKey);
381375

382376
// Don't propose any popup if we multi-root workspace folders are already set
383-
// explicitly in the workspace's settings.
384-
if (foldersInSettings === undefined) {
377+
// explicitly in the workspace's settings, or if the command has been
378+
// triggered at startup while the user previously clicked on the
379+
// 'Don't show again' button for this workspace
380+
if (foldersInSettings === undefined && !(atStartup && doNotShowAgain)) {
385381
const sourceDirs: ALSSourceDirDescription[] = (await alsClient.sendRequest(
386382
ExecuteCommandRequest.type,
387383
{
@@ -429,17 +425,30 @@ export async function checkSrcDirectories(
429425
if (workspaceDirsToAdd.length > 0) {
430426
let doAdd = true;
431427

432-
if (displayPopupWhenMissing) {
428+
if (displayYesNoPopup) {
429+
const buttons: ('Yes' | 'No' | "Don't Show Again")[] = ['Yes', 'No'];
430+
431+
// Show the 'Don't Show Again' button only at startup
432+
if (atStartup) {
433+
buttons.push("Don't Show Again");
434+
}
435+
433436
await vscode.window
434437
.showInformationMessage(
435438
'Some project source directories are not \
436-
listed in your workspace: do you want to add them?',
437-
'Yes',
438-
'No'
439+
listed in your workspace: do you want to add them?',
440+
...buttons
439441
)
440442
.then((answer) => {
441443
if (answer !== 'Yes') {
442444
doAdd = false;
445+
446+
if (answer === "Don't Show Again") {
447+
void adaExtState.context.workspaceState.update(
448+
doNotShowAgainKey,
449+
true
450+
);
451+
}
443452
}
444453
});
445454
}
@@ -453,7 +462,7 @@ export async function checkSrcDirectories(
453462
...workspaceDirsToAdd
454463
);
455464
}
456-
} else if (displayPopupOnSuccess) {
465+
} else if (!atStartup) {
457466
void vscode.window.showInformationMessage(
458467
"All the project's source directories are already \
459468
available in the current workspace."

integration/vscode/ada/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
171171
/**
172172
* This can display a dialog to the User so don't wait on the result.
173173
*/
174-
void vscode.commands.executeCommand('ada.addMissingDirsToWorkspace', true, false);
174+
void vscode.commands.executeCommand('ada.addMissingDirsToWorkspace', true);
175175
}
176176

177177
function setUpLogging(context: vscode.ExtensionContext) {

integration/vscode/ada/test/suite/workspace_missing_dirs/workspace_missing_dirs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ suite('Extensions Advanced Test Suite', function () {
1818

1919
// Execute the 'ada.addMissingDirsToWorkspace' command, that imports the missing
2020
// source directories into the current workspace if needed
21-
await vscode.commands.executeCommand('ada.addMissingDirsToWorkspace', false);
21+
await vscode.commands.executeCommand('ada.addMissingDirsToWorkspace', false, false);
2222

2323
// Check that we have 3 workspace folders after executing the command
2424
folders = vscode.workspace.workspaceFolders;

0 commit comments

Comments
 (0)