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