finish plugin context
This commit is contained in:
parent
0ad95aaf60
commit
7a6b857bae
24
package.json
24
package.json
@ -113,6 +113,14 @@
|
|||||||
"title": "%openmcp.hook.test-news.title%",
|
"title": "%openmcp.hook.test-news.title%",
|
||||||
"category": "openmcp",
|
"category": "openmcp",
|
||||||
"icon": "$(test)"
|
"icon": "$(test)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "openmcp.sidebar.installed-connection.changeConnectionName",
|
||||||
|
"title": "%openmcp.sidebar.installed-connection.changeConnectionName.title%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "openmcp.sidebar.workspace-connection.changeConnectionName",
|
||||||
|
"title": "%openmcp.sidebar.workspace-connection.changeConnectionName.title%"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"menus": {
|
"menus": {
|
||||||
@ -172,6 +180,14 @@
|
|||||||
"view": "${viewItem}"
|
"view": "${viewItem}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "openmcp.sidebar.workspace-connection.changeConnectionName",
|
||||||
|
"group": "navigation@1",
|
||||||
|
"when": "view == openmcp.sidebar.workspace-connection && viewItem == workspace-item",
|
||||||
|
"args": {
|
||||||
|
"view": "${viewItem}"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "openmcp.sidebar.installed-connection.revealWebviewPanel",
|
"command": "openmcp.sidebar.installed-connection.revealWebviewPanel",
|
||||||
"group": "inline@1",
|
"group": "inline@1",
|
||||||
@ -187,6 +203,14 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"view": "${viewItem}"
|
"view": "${viewItem}"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "openmcp.sidebar.installed-connection.changeConnectionName",
|
||||||
|
"group": "navigation@1",
|
||||||
|
"when": "view == openmcp.sidebar.workspace-connection && viewItem == installed-item",
|
||||||
|
"args": {
|
||||||
|
"view": "${viewItem}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -14,5 +14,7 @@
|
|||||||
"openmcp.sidebar.workspace-connection.view.title": "MCP 接続(ワークスペース)",
|
"openmcp.sidebar.workspace-connection.view.title": "MCP 接続(ワークスペース)",
|
||||||
"openmcp.sidebar.installed-connection.view.title": "インストール済み MCP サーバー",
|
"openmcp.sidebar.installed-connection.view.title": "インストール済み MCP サーバー",
|
||||||
"openmcp.sidebar.help.view.title": "はじめに・ヘルプ",
|
"openmcp.sidebar.help.view.title": "はじめに・ヘルプ",
|
||||||
"openmcp.hook.test-news.title": "テストニュースレポート"
|
"openmcp.hook.test-news.title": "テストニュースレポート",
|
||||||
|
"openmcp.sidebar.installed-connection.changeConnectionName.title": "サーバー名を変更",
|
||||||
|
"openmcp.sidebar.workspace-connection.changeConnectionName.title": "サーバー名を変更"
|
||||||
}
|
}
|
@ -14,5 +14,7 @@
|
|||||||
"openmcp.sidebar.workspace-connection.view.title": "MCP Connections (Workspace)",
|
"openmcp.sidebar.workspace-connection.view.title": "MCP Connections (Workspace)",
|
||||||
"openmcp.sidebar.installed-connection.view.title": "Installed MCP Servers",
|
"openmcp.sidebar.installed-connection.view.title": "Installed MCP Servers",
|
||||||
"openmcp.sidebar.help.view.title": "Getting Started & Help",
|
"openmcp.sidebar.help.view.title": "Getting Started & Help",
|
||||||
"openmcp.hook.test-news.title": "test news report"
|
"openmcp.hook.test-news.title": "Test News Report",
|
||||||
|
"openmcp.sidebar.installed-connection.changeConnectionName.title": "Change Server Name",
|
||||||
|
"openmcp.sidebar.workspace-connection.changeConnectionName.title": "Change Server Name"
|
||||||
}
|
}
|
@ -14,5 +14,7 @@
|
|||||||
"openmcp.sidebar.workspace-connection.view.title": "MCP 连接 (工作区)",
|
"openmcp.sidebar.workspace-connection.view.title": "MCP 连接 (工作区)",
|
||||||
"openmcp.sidebar.installed-connection.view.title": "安装的 MCP 服务器",
|
"openmcp.sidebar.installed-connection.view.title": "安装的 MCP 服务器",
|
||||||
"openmcp.sidebar.help.view.title": "入门与帮助",
|
"openmcp.sidebar.help.view.title": "入门与帮助",
|
||||||
"openmcp.hook.test-news.title": "测试新闻报告"
|
"openmcp.hook.test-news.title": "测试新闻报告",
|
||||||
|
"openmcp.sidebar.installed-connection.changeConnectionName.title": "修改服务器名称",
|
||||||
|
"openmcp.sidebar.workspace-connection.changeConnectionName.title": "修改服务器名称"
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
|||||||
import { RegisterCommand, RegisterTreeDataProvider } from '../common/index.js';
|
import { RegisterCommand, RegisterTreeDataProvider } from '../common/index.js';
|
||||||
import { ConnectionViewItem } from './common.js';
|
import { ConnectionViewItem } from './common.js';
|
||||||
import { getConnectionConfig, getInstalledConnectionConfigPath, saveConnectionConfig } from '../global.js';
|
import { getConnectionConfig, getInstalledConnectionConfigPath, saveConnectionConfig } from '../global.js';
|
||||||
import { acquireInstalledConnection, deleteInstalledConnection } from './installed.service.js';
|
import { acquireInstalledConnection, changeInstalledConnectionName, deleteInstalledConnection } from './installed.service.js';
|
||||||
import { revealOpenMcpWebviewPanel } from '../webview/webview.service.js';
|
import { revealOpenMcpWebviewPanel } from '../webview/webview.service.js';
|
||||||
|
|
||||||
@RegisterTreeDataProvider('openmcp.sidebar.installed-connection')
|
@RegisterTreeDataProvider('openmcp.sidebar.installed-connection')
|
||||||
@ -14,6 +14,7 @@ export class McpInstalledConnectProvider implements vscode.TreeDataProvider<Conn
|
|||||||
|
|
||||||
// 实现 TreeDataProvider 接口
|
// 实现 TreeDataProvider 接口
|
||||||
getTreeItem(element: ConnectionViewItem): vscode.TreeItem {
|
getTreeItem(element: ConnectionViewItem): vscode.TreeItem {
|
||||||
|
element.contextValue = 'installed-item';
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,4 +76,10 @@ export class McpInstalledConnectProvider implements vscode.TreeDataProvider<Conn
|
|||||||
const connectionItem = view.item;
|
const connectionItem = view.item;
|
||||||
await deleteInstalledConnection(connectionItem);
|
await deleteInstalledConnection(connectionItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RegisterCommand('changeConnectionName')
|
||||||
|
public async changeConnectionName(context: vscode.ExtensionContext, view: ConnectionViewItem) {
|
||||||
|
const connectionItem = view.item;
|
||||||
|
await changeInstalledConnectionName(connectionItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,43 @@ export async function deleteInstalledConnection(item: McpOptions[] | McpOptions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function changeInstalledConnectionName(item: McpOptions[] | McpOptions) {
|
||||||
|
// 获取当前连接项
|
||||||
|
const masterNode = Array.isArray(item) ? item[0] : item;
|
||||||
|
const currentName = masterNode.name || '';
|
||||||
|
|
||||||
|
// 弹出输入框让用户输入新的服务器名称
|
||||||
|
const newName = await vscode.window.showInputBox({
|
||||||
|
prompt: t('openmcp.sidebar.installed-connection.changeConnectionName.title'),
|
||||||
|
value: currentName,
|
||||||
|
validateInput: (value) => {
|
||||||
|
if (!value || value.trim() === '') {
|
||||||
|
return t('error.connectionNameRequired');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 用户取消或输入无效名称
|
||||||
|
if (!newName || newName.trim() === '' || newName === currentName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取已安装的连接配置
|
||||||
|
const installedConnection = getConnectionConfig();
|
||||||
|
|
||||||
|
// 更新连接名称
|
||||||
|
masterNode.name = newName.trim();
|
||||||
|
|
||||||
|
// 保存更新后的配置
|
||||||
|
saveConnectionConfig();
|
||||||
|
|
||||||
|
// 刷新侧边栏视图
|
||||||
|
vscode.commands.executeCommand('openmcp.sidebar.installed-connection.refresh');
|
||||||
|
|
||||||
|
// 显示成功消息
|
||||||
|
vscode.window.showInformationMessage(t('connectionNameChanged', currentName, newName));
|
||||||
|
}
|
||||||
|
|
||||||
export async function acquireInstalledConnection(): Promise<McpOptions[]> {
|
export async function acquireInstalledConnection(): Promise<McpOptions[]> {
|
||||||
// 让用户选择连接类型
|
// 让用户选择连接类型
|
||||||
|
@ -3,7 +3,7 @@ import { RegisterCommand, RegisterTreeDataProvider } from '../common/index.js';
|
|||||||
import { getWorkspaceConnectionConfig, getWorkspaceConnectionConfigPath, getWorkspacePath, saveWorkspaceConnectionConfig } from '../global.js';
|
import { getWorkspaceConnectionConfig, getWorkspaceConnectionConfigPath, getWorkspacePath, saveWorkspaceConnectionConfig } from '../global.js';
|
||||||
import { ConnectionViewItem } from './common.js';
|
import { ConnectionViewItem } from './common.js';
|
||||||
import { revealOpenMcpWebviewPanel } from '../webview/webview.service.js';
|
import { revealOpenMcpWebviewPanel } from '../webview/webview.service.js';
|
||||||
import { acquireUserCustomConnection, deleteUserConnection } from './workspace.service.js';
|
import { acquireUserCustomConnection, changeUserConnectionName, deleteUserConnection } from './workspace.service.js';
|
||||||
import { t } from '../i18n/index.js';
|
import { t } from '../i18n/index.js';
|
||||||
|
|
||||||
@RegisterTreeDataProvider('openmcp.sidebar.workspace-connection')
|
@RegisterTreeDataProvider('openmcp.sidebar.workspace-connection')
|
||||||
@ -15,6 +15,7 @@ export class McpWorkspaceConnectProvider implements vscode.TreeDataProvider<Conn
|
|||||||
|
|
||||||
// 实现 TreeDataProvider 接口
|
// 实现 TreeDataProvider 接口
|
||||||
getTreeItem(element: ConnectionViewItem): vscode.TreeItem {
|
getTreeItem(element: ConnectionViewItem): vscode.TreeItem {
|
||||||
|
element.contextValue = 'workspace-item';
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
getChildren(element?: ConnectionViewItem): Thenable<ConnectionViewItem[]> {
|
getChildren(element?: ConnectionViewItem): Thenable<ConnectionViewItem[]> {
|
||||||
@ -96,4 +97,10 @@ export class McpWorkspaceConnectProvider implements vscode.TreeDataProvider<Conn
|
|||||||
const connectionItem = view.item;
|
const connectionItem = view.item;
|
||||||
await deleteUserConnection(connectionItem);
|
await deleteUserConnection(connectionItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RegisterCommand('changeConnectionName')
|
||||||
|
public async changeConnectionName(context: vscode.ExtensionContext, view: ConnectionViewItem) {
|
||||||
|
const connectionItem = view.item;
|
||||||
|
await changeUserConnectionName(connectionItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,48 @@ export async function deleteUserConnection(item: McpOptions[] | McpOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function changeUserConnectionName(item: McpOptions[] | McpOptions) {
|
||||||
|
// 获取当前连接项
|
||||||
|
const masterNode = Array.isArray(item) ? item[0] : item;
|
||||||
|
const currentName = masterNode.name || '';
|
||||||
|
|
||||||
|
// 弹出输入框让用户输入新的服务器名称
|
||||||
|
const newName = await vscode.window.showInputBox({
|
||||||
|
prompt: t('openmcp.sidebar.installed-connection.changeConnectionName.title'),
|
||||||
|
value: currentName,
|
||||||
|
validateInput: (value) => {
|
||||||
|
if (!value || value.trim() === '') {
|
||||||
|
return t('error.connectionNameRequired');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 用户取消或输入无效名称
|
||||||
|
if (!newName || newName.trim() === '' || newName === currentName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaceConnectionConfig = getWorkspaceConnectionConfig();
|
||||||
|
if (!workspaceConnectionConfig) {
|
||||||
|
vscode.window.showErrorMessage(t('error.notOpenWorkspace'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新连接名称
|
||||||
|
masterNode.name = newName.trim();
|
||||||
|
|
||||||
|
// 保存更新后的配置
|
||||||
|
const workspacePath = getWorkspacePath();
|
||||||
|
await saveWorkspaceConnectionConfig(workspacePath);
|
||||||
|
|
||||||
|
// 刷新侧边栏视图
|
||||||
|
vscode.commands.executeCommand('openmcp.sidebar.workspace-connection.refresh');
|
||||||
|
|
||||||
|
// 显示成功消息
|
||||||
|
vscode.window.showInformationMessage(t('connectionNameChanged', currentName, newName));
|
||||||
|
}
|
||||||
|
|
||||||
export async function acquireUserCustomConnection(): Promise<McpOptions[]> {
|
export async function acquireUserCustomConnection(): Promise<McpOptions[]> {
|
||||||
// 让用户选择连接类型
|
// 让用户选择连接类型
|
||||||
const connectionType = await vscode.window.showQuickPick(['STDIO', 'SSE', 'STREAMABLE_HTTP'], {
|
const connectionType = await vscode.window.showQuickPick(['STDIO', 'SSE', 'STREAMABLE_HTTP'], {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user