Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/getting-started/vscode-node/newWorkspaceInitializer.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { l10n } from 'vscode';
8
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext';
9
import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService';
10
import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService';
11
import { Disposable } from '../../../util/vs/base/common/lifecycle';
12
import { INewWorkspaceStoredData, NEW_WORKSPACE_STORAGE_KEY } from '../common/newWorkspaceContext';
13
14
export class NewWorkspaceInitializer extends Disposable {
15
constructor(
16
@IVSCodeExtensionContext private readonly _extensionContext: IVSCodeExtensionContext,
17
@IWorkspaceService private readonly workspaceService: IWorkspaceService,
18
@IFileSystemService private readonly fileSystemService: IFileSystemService
19
) {
20
super();
21
this._updateWorkspace();
22
}
23
24
private async _updateWorkspace(): Promise<void> {
25
const workspace = this.workspaceService.getWorkspaceFolders();
26
if (!workspace || workspace.length === 0) {
27
return;
28
}
29
30
const newWorkspaceContextsList = this._extensionContext.globalState.get<INewWorkspaceStoredData[]>(NEW_WORKSPACE_STORAGE_KEY, []);
31
const exactIndex = newWorkspaceContextsList.findIndex(c => c.workspaceURI === workspace[0].toString());
32
if (exactIndex === -1) {
33
return;
34
}
35
36
const context = newWorkspaceContextsList[exactIndex];
37
const confirm = l10n.t('Continue Setup');
38
const message = l10n.t('Continue Workspace Setup?');
39
const detail = l10n.t('Copilot will resume setting up the workspace by creating the necessary files.');
40
41
if (!context.initialized) {
42
context.initialized = true;
43
newWorkspaceContextsList[exactIndex] = context;
44
this._extensionContext.globalState.update(NEW_WORKSPACE_STORAGE_KEY, newWorkspaceContextsList);
45
46
const result = await vscode.window.showInformationMessage(message, { modal: true, detail }, confirm);
47
if (result === confirm) {
48
vscode.commands.executeCommand('workbench.action.chat.open', { mode: 'agent', query: `${l10n.t('Continue with #new workspace setup')}` });
49
} else {
50
newWorkspaceContextsList.splice(exactIndex, 1);
51
this._extensionContext.globalState.update(NEW_WORKSPACE_STORAGE_KEY, newWorkspaceContextsList);
52
}
53
54
return;
55
}
56
57
if ((await this.fileSystemService.readDirectory(workspace[0])).length > 0) {
58
// workspace is not empty and we've already initialized it
59
newWorkspaceContextsList.splice(exactIndex, 1);
60
this._extensionContext.globalState.update(NEW_WORKSPACE_STORAGE_KEY, newWorkspaceContextsList);
61
} else {
62
// workspace is still empty, so ask to setup again
63
const result = await vscode.window.showInformationMessage(message, { modal: true, detail }, confirm);
64
if (result === confirm) {
65
vscode.commands.executeCommand('workbench.action.chat.open', { mode: 'agent', query: context.userPrompt });
66
} else {
67
newWorkspaceContextsList.splice(exactIndex, 1);
68
this._extensionContext.globalState.update(NEW_WORKSPACE_STORAGE_KEY, newWorkspaceContextsList);
69
}
70
}
71
}
72
}
73