-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathQuickPickWorkspace.ts
More file actions
35 lines (31 loc) · 1.03 KB
/
QuickPickWorkspace.ts
File metadata and controls
35 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright (c) 2020 Certinia Inc. All rights reserved.
*/
import { parse } from 'path';
import { window } from 'vscode';
import { Context } from '../Context.js';
import { Item, Options, QuickPick } from './QuickPick.js';
export class QuickPickWorkspace {
static async pickOrReturn(context: Context): Promise<string> {
const workspaceFolders = context.workspaceManager.workspaceFolders;
if (workspaceFolders.length > 1) {
const [workspace] = await QuickPick.pick(
workspaceFolders.map((ws) => new Item(ws.name(), ws.path(), '')),
new Options('Select a workspace:'),
);
if (workspace) {
return workspace.description;
} else {
throw new Error('No workspace selected');
}
} else if (workspaceFolders.length === 1) {
return workspaceFolders[0]?.path() || '';
} else {
if (window.activeTextEditor) {
return parse(window.activeTextEditor.document.fileName).dir;
} else {
throw new Error('No workspace selected');
}
}
}
}