-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathMCPOpenFileStep.ts
More file actions
45 lines (38 loc) · 2.36 KB
/
MCPOpenFileStep.ts
File metadata and controls
45 lines (38 loc) · 2.36 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
36
37
38
39
40
41
42
43
44
45
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtFsExtra, AzureWizardExecuteStep } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { Uri, ViewColumn, window, workspace } from 'vscode';
import { type MCPProjectWizardContext } from '../IProjectWizardContext';
export class MCPOpenFileStep extends AzureWizardExecuteStep<MCPProjectWizardContext> {
public priority: number = 240; // Execute before OpenFolderStep (priority 250) but after other project setup
public async execute(context: MCPProjectWizardContext): Promise<void> {
const mcpJsonFilePath: string = path.join(context.projectPath, '.vscode', 'mcp.json');
if (await AzExtFsExtra.pathExists(mcpJsonFilePath)) {
const mcpJsonFile = await workspace.openTextDocument(Uri.file(mcpJsonFilePath));
await window.showTextDocument(mcpJsonFile, { preview: false });
}
// Open sample tool file in a side-by-side editor
if (context.sampleToolFilePath) {
if (await AzExtFsExtra.pathExists(context.sampleToolFilePath)) {
const doc = await workspace.openTextDocument(Uri.file(context.sampleToolFilePath));
await window.showTextDocument(doc, { preview: false, viewColumn: ViewColumn.Beside });
}
}
}
public shouldExecute(context: MCPProjectWizardContext): boolean {
// Only execute if we're not opening the folder in a way that would reload the window
// If opening in current window or new window, the file open would be lost during reload
const openFolders = workspace.workspaceFolders || [];
// Handle AddToWorkspace: only if there are existing workspace folders
// (OpenFolderStep changes AddToWorkspace to OpenInCurrentWindow if no folders exist)
if (context.openBehavior === 'AddToWorkspace') {
return openFolders.length > 0;
}
// Always execute for these cases
return context.openBehavior === 'AlreadyOpen' ||
context.openBehavior === 'DontOpen';
}
}