Skip to content

Commit 3698950

Browse files
authored
Replace prompt with quickpick (#14885)
1 parent 176b923 commit 3698950

File tree

3 files changed

+76
-39
lines changed

3 files changed

+76
-39
lines changed

package.nls.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,15 @@
221221
"StartPage.folderDesc": "- Open a <div class=\"link\" role=\"button\" onclick={0}>Folder</div><br /> - Open a <div class=\"link\" role=\"button\" onclick={1}>Workspace</div>",
222222
"StartPage.badWebPanelFormatString": "<html><body><h1>{0} is not a valid file name</h1></body></html>",
223223
"Jupyter.extensionRequired": "The Jupyter extension is required to perform that task. Click Yes to open the Jupyter extension installation page.",
224-
"TensorBoard.logDirectoryPrompt" : "Please select a log directory to start TensorBoard with.",
224+
"TensorBoard.useCurrentWorkingDirectory": "Use current working directory",
225+
"TensorBoard.currentDirectory": "Current: {0}",
226+
"TensorBoard.logDirectoryPrompt" : "Select a log directory to start TensorBoard with",
225227
"TensorBoard.progressMessage" : "Starting TensorBoard session...",
226228
"TensorBoard.failedToStartSessionError" : "We failed to start a TensorBoard session due to the following error: {0}",
227-
"TensorBoard.nativeTensorBoardPrompt" : "VS Code now has native TensorBoard support. Would you like to launch TensorBoard?",
228-
"TensorBoard.usingCurrentWorkspaceFolder": "We are using the current workspace folder as the log directory for your TensorBoard session.",
229-
"TensorBoard.selectAFolder": "Select a folder"
229+
"TensorBoard.nativeTensorBoardPrompt" : "VS Code now has native TensorBoard support. Would you like to launch TensorBoard? (Tip: Launch TensorBoard anytime by opening the command palette and searching for \"Launch TensorBoard\".)",
230+
"TensorBoard.selectAFolder": "Select a folder",
231+
"TensorBoard.selectAnotherFolder": "Select another folder",
232+
"TensorBoard.selectAFolderDetail": "Select a log directory containing tfevent files",
233+
"TensorBoard.selectAnotherFolderDetail": "Use the file explorer to select another folder",
234+
"TensorBoard.useCurrentWorkingDirectoryDetail": "TensorBoard will search for tfevent files in all subdirectories of the current working directory"
230235
}

src/client/common/utils/localize.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ export namespace Jupyter {
134134
}
135135

136136
export namespace TensorBoard {
137+
export const useCurrentWorkingDirectoryDetail = localize(
138+
'TensorBoard.useCurrentWorkingDirectoryDetail',
139+
'TensorBoard will search for tfevent files in all subdirectories of the current working directory'
140+
);
141+
export const useCurrentWorkingDirectory = localize(
142+
'TensorBoard.useCurrentWorkingDirectory',
143+
'Use current working directory'
144+
);
145+
export const currentDirectory = localize('TensorBoard.currentDirectory', 'Current: {0}');
137146
export const logDirectoryPrompt = localize(
138147
'TensorBoard.logDirectoryPrompt',
139-
'Please select a log directory to start TensorBoard with.'
148+
'Select a log directory to start TensorBoard with'
140149
);
141150
export const progressMessage = localize('TensorBoard.progressMessage', 'Starting TensorBoard session...');
142151
export const failedToStartSessionError = localize(
@@ -145,13 +154,18 @@ export namespace TensorBoard {
145154
);
146155
export const nativeTensorBoardPrompt = localize(
147156
'TensorBoard.nativeTensorBoardPrompt',
148-
'VS Code now has native TensorBoard support. Would you like to launch TensorBoard?'
149-
);
150-
export const usingCurrentWorkspaceFolder = localize(
151-
'TensorBoard.usingCurrentWorkspaceFolder',
152-
'We are using the current workspace folder as the log directory for your TensorBoard session.'
157+
'VS Code now has native TensorBoard support. Would you like to launch TensorBoard? (Tip: Launch TensorBoard anytime by opening the command palette and searching for "Launch TensorBoard".)'
153158
);
154159
export const selectAFolder = localize('TensorBoard.selectAFolder', 'Select a folder');
160+
export const selectAFolderDetail = localize(
161+
'TensorBoard.selectAFolderDetail',
162+
'Select a log directory containing tfevent files'
163+
);
164+
export const selectAnotherFolder = localize('TensorBoard.selectAnotherFolder', 'Select another folder');
165+
export const selectAnotherFolderDetail = localize(
166+
'TensorBoard.selectAnotherFolderDetail',
167+
'Use the file explorer to select another folder'
168+
);
155169
}
156170

157171
export namespace LanguageService {

src/client/tensorBoard/tensorBoardSession.ts

+47-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Progress,
1010
ProgressLocation,
1111
ProgressOptions,
12+
QuickPickItem,
1213
ViewColumn,
1314
WebviewPanel,
1415
window
@@ -20,7 +21,7 @@ import { _SCRIPTS_DIR, tensorboardLauncher } from '../common/process/internal/sc
2021
import { IProcessServiceFactory, ObservableExecutionResult } from '../common/process/types';
2122
import { IInstaller, InstallerResponse, Product } from '../common/types';
2223
import { createDeferred, sleep } from '../common/utils/async';
23-
import { Common, TensorBoard } from '../common/utils/localize';
24+
import { TensorBoard } from '../common/utils/localize';
2425
import { IInterpreterService } from '../interpreter/contracts';
2526

2627
/**
@@ -101,20 +102,56 @@ export class TensorBoardSession {
101102
}
102103
}
103104

104-
// Display a prompt asking the user to acknowledge our autopopulated log directory or
105+
private getQuickPickItems(logDir: string | undefined) {
106+
if (logDir) {
107+
const useCwd = {
108+
label: TensorBoard.useCurrentWorkingDirectory(),
109+
detail: TensorBoard.useCurrentWorkingDirectoryDetail()
110+
};
111+
const selectAnotherFolder = {
112+
label: TensorBoard.selectAnotherFolder(),
113+
detail: TensorBoard.selectAnotherFolderDetail()
114+
};
115+
return [useCwd, selectAnotherFolder];
116+
} else {
117+
const selectAFolder = {
118+
label: TensorBoard.selectAFolder(),
119+
detail: TensorBoard.selectAFolderDetail()
120+
};
121+
return [selectAFolder];
122+
}
123+
}
124+
125+
// Display a quickpick asking the user to acknowledge our autopopulated log directory or
105126
// select a new one using the file picker. Default this to the folder that is open in
106127
// the editor, if any, then the directory that the active text editor is in, if any.
107128
private async askUserForLogDir(): Promise<string | undefined> {
108129
const logDir = this.autopopulateLogDirectoryPath();
109-
const gotIt = Common.gotIt();
130+
const useCurrentWorkingDirectory = TensorBoard.useCurrentWorkingDirectory();
110131
const selectAFolder = TensorBoard.selectAFolder();
111-
const message = logDir ? TensorBoard.usingCurrentWorkspaceFolder() : TensorBoard.logDirectoryPrompt();
112-
const prompts = logDir ? [gotIt, selectAFolder] : [selectAFolder];
113-
const selection = await window.showInformationMessage(message, ...prompts);
114-
switch (selection) {
115-
case gotIt:
132+
const selectAnotherFolder = TensorBoard.selectAnotherFolder();
133+
const items: QuickPickItem[] = this.getQuickPickItems(logDir);
134+
const quickPick = window.createQuickPick();
135+
quickPick.title = TensorBoard.logDirectoryPrompt();
136+
quickPick.canSelectMany = false;
137+
quickPick.enabled = false;
138+
quickPick.items = items;
139+
if (logDir) {
140+
quickPick.placeholder = TensorBoard.currentDirectory().format(logDir);
141+
}
142+
const selection = createDeferred<QuickPickItem>();
143+
quickPick.onDidAccept(() => {
144+
quickPick.hide();
145+
selection.resolve(quickPick.selectedItems[0]);
146+
});
147+
quickPick.show();
148+
const item = await selection.promise;
149+
quickPick.dispose();
150+
switch (item.label) {
151+
case useCurrentWorkingDirectory:
116152
return logDir;
117153
case selectAFolder:
154+
case selectAnotherFolder:
118155
return this.showFilePicker();
119156
default:
120157
return undefined;
@@ -125,7 +162,6 @@ export class TensorBoardSession {
125162
// Times out if it hasn't started up after 1 minute.
126163
// Hold on to the process so we can kill it when the webview is closed.
127164
private async startTensorboardSession(logDir: string): Promise<boolean> {
128-
const cwd = this.getFullyQualifiedLogDirectory(logDir);
129165
const pythonExecutable = await this.interpreterService.getActiveInterpreter();
130166
if (!pythonExecutable) {
131167
return false;
@@ -145,12 +181,12 @@ export class TensorBoardSession {
145181

146182
const processService = await this.processServiceFactory.create();
147183
const args = tensorboardLauncher([logDir]);
148-
const observable = processService.execObservable(pythonExecutable.path, args, { cwd });
184+
const observable = processService.execObservable(pythonExecutable.path, args);
149185

150186
const result = await window.withProgress(
151187
progressOptions,
152188
(_progress: Progress<{}>, token: CancellationToken) => {
153-
traceInfo(`Starting TensorBoard with log directory ${cwd}...`);
189+
traceInfo(`Starting TensorBoard with log directory ${logDir}...`);
154190

155191
const spawnTensorBoard = this.waitForTensorBoardStart(observable);
156192
const userCancellation = createPromiseFromCancellation({
@@ -247,24 +283,6 @@ export class TensorBoardSession {
247283
}
248284
}
249285

250-
// TensorBoard accepts absolute or relative log directory paths to tfevent files.
251-
// It uses these files to populate its visualizations. If given a relative path,
252-
// TensorBoard resolves them against the current working directory. Make the
253-
// chosen filepath explicit in our logs. If a workspace folder is open, ensure
254-
// we pass it as cwd to the spawned process. If there is no rootPath available,
255-
// explicitly pass process.cwd, which is what `spawn` would use by default anyway.
256-
private getFullyQualifiedLogDirectory(logDir: string) {
257-
if (path.isAbsolute(logDir)) {
258-
return logDir;
259-
}
260-
const rootPath = this.workspaceService.rootPath;
261-
if (rootPath) {
262-
return path.resolve(rootPath, logDir);
263-
} else {
264-
return path.resolve(process.cwd(), logDir);
265-
}
266-
}
267-
268286
private autopopulateLogDirectoryPath(): string | undefined {
269287
if (this.workspaceService.rootPath) {
270288
return this.workspaceService.rootPath;

0 commit comments

Comments
 (0)