修改插件命令调用机制,扩展支持两个插件,如果第一个自有插件未安装,则判断第二个插件是否安装,并给出选择;及后续操作

This commit is contained in:
zhangyun 2024-10-30 16:19:01 +08:00
parent 789b3f7517
commit dbf8abf240
11 changed files with 204 additions and 77 deletions

4
.gitignore vendored
View File

@ -131,4 +131,6 @@ dist
build
*.vsix
.VSCodeCounter
settings.json
settings.json
.clang-tidy
.clangd

View File

@ -15,8 +15,8 @@
- 在资源管理器展开“项目操作区”
- 基本操作:提供项目创建、配置、构建、调试、运行等相关功能入口;
- 执行任务通过解析当前工作区第一个项目的tasks.json显示各个任务按钮悬停显示任务信息点击可以执行具体任务。
- 执行调试通过解析当前工作区第一个项目的launch.json显示各个调试按钮悬停显示调试信息点击可以进入调试页面执行该调试。
- 任务列表通过解析当前工作区第一个项目的tasks.json显示各个任务按钮悬停显示任务信息点击可以执行具体任务。
- 调试配置列表通过解析当前工作区第一个项目的launch.json显示各个调试按钮悬停显示调试信息点击可以进入调试页面执行该调试。
- 执行CMake/Makefile通过通过解析当前工作区第一个项目的CMakeLists.txt/Makefile显示各个构建工具命令点击调起终端执行。暂不支持
- 执行Node.js配置脚本通过解析当前工作区第一个项目的package.json显示脚本按钮悬停显示脚本信息点击调起终端通过npm执行。
- 如果项目内容发生变化,可点击右上角刷新图标刷新操作区;
@ -26,23 +26,31 @@
- 点击右上角添加自定义按钮...
- 弹出下拉选择。
- 包括:
- 添加自定义IDE命令调用按钮
```
可以添加一个自定义按钮输入按钮标题、及IDE的commmand刷新操作区后点击该新增按钮可以执行该command
可以添加一个自定义按钮:
·输入按钮标题XXX
·输入Kylin-IDE的commmand
·刷新操作区后自定义按钮区显示XXX按钮
·点击该按钮可以执行该command
```
- 添加自定义终端命令执行按钮
```
可以添加一个自定义按钮输入按钮标题、及Linux终端命令刷新操作区后点击该新增按钮可以打开一个Kylin-ID内置终端并执行该命令
可以添加一个自定义按钮:
·输入按钮标题;
·输入Linux终端命令
·刷新操作区后自定义按钮区显示XXX按钮
·点击该按钮可以打开一个Kylin-ID内置终端并执行该命令
```
- 打开tasks.json添加任务配置
```
可以调起Kylin-IDE的任务配置选择或手动添加任务
可以调起Kylin-IDE的任务配置选择内置任务或手动输入添加任务;
```
- 打开launch.json添加调试配置
```
可以调起Kylin-IDE的调试配置选择或手动添加配置
```
可以调起Kylin-IDE的调试配置选择内置配置或手动添加配置
## 3、创建新的项目
@ -392,9 +400,9 @@ createProject”选择 PROJECT:创建项目,调起页面。
- Basic operation: Provide entry points for project creation, configuration, construction, debugging, running functions;
- Task Execution: By parsing the tasks.json of the first project in the current workspace, display various task buttons, hover to display task information, and click to execute specific tasks.
- Task List: By parsing the tasks.json of the first project in the current workspace, display various task buttons, hover to display task information, and click to execute specific tasks.
- Debugging execution: By parsing the launch. json of the first project in the current workspace, display various debugging buttons, hover to display debugging information, and click to enter the debugging page to execute the debugging.
- Debugging Configure List: By parsing the launch. json of the first project in the current workspace, display various debugging buttons, hover to display debugging information, and click to enter the debugging page to execute the debugging.
- Execute CMake/Makefile: Display various build tool commands by parsing the first project's CMakeLists.txt/Makefile in the current workspace, and click to start terminal execution.

View File

@ -495,6 +495,22 @@
"language.downloadFileExtractedOpen": "The source code package has been downloaded and unzipped to {0}. Do you want to open the terminal to edit the source code? ",
"language.libraryAddTitle": "Enter the name of the library to be added. It is recommended to name it with the link library name as the default link file keyword",
"language.libraryAddCheckNotice": "Please enter a legal library name (including: a-z A-Z 0-9 _.-)",
"language.libraryAddDuplicateKey": "Library name conflict, Duplicate key!"
"language.libraryAddDuplicateKey": "Library name conflict, Duplicate key!",
"language.extensions.install": "install {0}",
"language.extensions.uninstallThanInstall": "Uninstall extension plugin, install {0}",
"language.extensions.enable": "Enable {0}",
"language.extensions.enableHolder": "Extension {0} Installed but not activated, is it enabled?",
"language.extensions.useInstalled": "Use the installed {0}",
"language.extensions.uninstallThanInstallHolder": "Extension {1} has been installed, do you want to use it directly? Or should we uninstall {1} and install {0}?",
"language.extensions.installHolder": "Extension {0} is not installed, do you want to install it?",
"language.extensions.todoUninstall": "Uninstalling extension: {0}...",
"language.extensions.uninstall": "Uninstall extension: {0}",
"language.extensions.uninstalling": "Uninstalling extension {0}...",
"language.extensions.uninstalled": "Extension {0} uninstalled",
"language.noticeReload": "Need to reload the window to take effect, do you want to reload?",
"language.reload": "reload"
}

View File

@ -496,6 +496,21 @@
"language.downloadFileExtractedOpen": "源码包已下载并解压到 {0},是否打开终端编辑源码?",
"language.libraryAddTitle": "输入要添加的库名,推荐以链接库名称命名,作为默认链接文件关键字",
"language.libraryAddCheckNotice": "请输入一个合法的库名包含a-z A-Z 0-9 _.-",
"language.libraryAddDuplicateKey": "库名冲突Duplicate key!"
"language.libraryAddDuplicateKey": "库名冲突Duplicate key!",
"language.extensions.install": "安装 {0} ",
"language.extensions.uninstallThanInstall": "卸载,并安装 {0}",
"language.extensions.enable": "启用 {0} ",
"language.extensions.enableHolder": "插件 {0} 已安装但未激活,是否启用?",
"language.extensions.useInstalled": "使用已安装的 {0} 插件",
"language.extensions.uninstallThanInstallHolder": "插件 {1} 已安装,是否直接使用? 还是卸载{1}后安装 {0} 插件?",
"language.extensions.installHolder": "插件 {0} 未安装,是否安装?",
"language.extensions.todoUninstall": "即将卸载扩展: {0}...",
"language.extensions.uninstall": "卸载扩展: {0}",
"language.extensions.uninstalling": "正在卸载扩展 {0}...",
"language.extensions.uninstalled": "扩展 {0} 已卸载",
"language.noticeReload": "需要重新加载窗口生效,是否重新加载?",
"language.reload": "重新加载"
}

View File

@ -211,13 +211,14 @@ export class BaseManager {
console.log(message.data);
ensureExtension(message.data.displayName, message.data.metadata).then(
(isCheck) => {
console.log(" isCheck:" + isCheck);
(extensionId) => {
console.log(" extensionId:" + extensionId);
let err = "false";
let msg = "";
if (!isCheck) {
if (extensionId === undefined) {
err = "true";
msg = localize("language.callExtensionError");
vscode.window.showErrorMessage(localize("language.callExtensionError"));
} else {
console.log("executeCommand: " + message.data.metadata.createCommandId);
let createCommandArgs = undefined;
@ -349,9 +350,9 @@ export class BaseManager {
createCommandId: "",
};
ensureExtension(metaData.extensionName, metaData).then(
(isCheck) => {
console.log(" isCheck:" + isCheck);
if (isCheck) {
(extensionId) => {
console.log(" isextensionIdCheck:" + extensionId);
if (extensionId !== undefined) {
callCommand(message.commandObj);
}
}

View File

@ -31,7 +31,7 @@ export const cmakeToolsDef = {
commandBuild: "cmake.build",// build command
commandRun: "cmake.launchTarget"// run command but debug
};
const extensionId = "ms-vscode.cmake-tools";// cmake-tools id
// const extensionId = "ms-vscode.cmake-tools";// cmake-tools id
const extensionName = "CMake Tools";
const commandBuild = "cmake.build";// build command
const commandRun = "cmake.launchTarget";// run command but debug
@ -48,9 +48,9 @@ export async function checkCmakeToolsAndCallCommand(flg:CmakeToolsTodo):Promise<
extensionName: cmakeToolsDef.name,
createCommandId: "",
};
let isCheck = await ensureExtension(metaData.extensionName, metaData);//.then((isCheck) => {
console.log(" isCheck:" + isCheck );
if(isCheck){
let extensionId = await ensureExtension(metaData.extensionName, metaData);//.then((isCheck) => {
console.log(" extensionId:" + extensionId );
if(extensionId !== undefined){
let command = undefined;
switch(flg){
case CmakeToolsTodo.debug:

View File

@ -1,7 +1,9 @@
import { commands, Disposable, Extension, ExtensionContext, extensions, QuickPickItem, Uri, window, workspace } from "vscode";
import * as vscode from 'vscode';
// import { commands, Disposable, Extension, ExtensionContext, extensions, QuickPickItem, Uri, window, workspace } from "vscode";
import {Commands} from "./commands"
import * as semver from "semver";
import localize from "./localize";
import { Choice, ChoiceClass } from './common/defines';
export interface IProjectType {
displayName: string;
@ -12,7 +14,7 @@ export interface IProjectType {
export interface IProjectTypeMetadata {
type: JavaProjectType|undefined;
extensionId: string;
extensionId: string; // 使用逗号分隔的插件 ID 字符串,最多支持两个。多了配置无效;逻辑就是有第一个用第一个;第一个未安装,则弹出询问是否安装。如果第后面已安装则增加选项是否直接使用后面的
extensionName: string;
leastExtensionVersion?: string;
createCommandId: string;
@ -30,51 +32,137 @@ export enum JavaProjectType {
PackageJar = "PackageJar"
}
export async function ensureExtension(typeName: string, metaData: IProjectTypeMetadata): Promise<boolean> {
/**
*
*
* @param typeName
* @param metaData extensionId idid为备用或者开源替代id
* @returns extensionId undefined
*/
export async function ensureExtension(typeName: string, metaData: IProjectTypeMetadata): Promise<string|undefined> {
if (!metaData.extensionId) {
return undefined;
}
const ids = metaData.extensionId.split(',').map(id => id.trim());
console.log(metaData);
console.log("ensureExtension: " + ids.join(', '));
const installedExtensions = ids.map(id => vscode.extensions.getExtension(id)).filter((ext): ext is vscode.Extension<any> => ext !== undefined);
// const missingExtensions = ids.filter(id => !installedExtensions.some(ext => ext.id === id));
// 如果第一个插件已安装,直接激活
if (installedExtensions.length > 0 && installedExtensions[0].id === ids[0]) {
await installedExtensions[0].activate();
return ids[0];
}
// 如果插件1未安装检查插件2是否已安装
if (installedExtensions.length > 0) {
const alternativeId = installedExtensions[0].id; // 其他安裝的插件
const alternativeExtension = vscode.extensions.getExtension(alternativeId);
if (alternativeExtension) {
// 插件2已安装弹出选择
const unInstall:ChoiceClass = {
title: localize("language.extensions.uninstallThanInstall", ids[0]),
choice: Choice.yes,
};
const useInstalled:ChoiceClass = {
title: localize("language.extensions.useInstalled", alternativeId),
choice: Choice.no,
};
const ret: ChoiceClass| undefined = await vscode.window.showInformationMessage(
localize("language.extensions.uninstallThanInstallHolder", ids[0], alternativeId),
{
modal: false, // 设置为模态对话框
detail: ""
},
unInstall,
useInstalled
);
if (ret?.choice === Choice.yes) {
// 卸载并安装需要reload。
// await vscode.commands.executeCommand("workbench.extensions.uninstallExtension", alternativeId);
await uninstallExtensionWithPrompt(alternativeId);
await promptInstallExtension(typeName, { ...metaData, extensionId: ids[0] }, false);
// 询问用户是否重载窗口
const reloadChoice = await vscode.window.showInformationMessage(
localize("language.noticeReload", metaData.extensionName),
localize("language.reload"),
localize("language.cancel")
);
if (reloadChoice === localize("language.reload")) {
await vscode.commands.executeCommand("workbench.action.reloadWindow");
}
}else if (ret?.choice === Choice.no) {
await alternativeExtension.activate();
return alternativeId;
}
return undefined; // 如果没有选择或未完成安装/使用操作
}
}
return await promptInstallExtension(typeName, { ...metaData, extensionId: ids[0] }, true);
}
async function uninstallExtensionWithPrompt(alternativeId: string): Promise<boolean> {
try{
// 提示用户即将卸载扩展
// vscode.window.showInformationMessage(localize("language.extensions.todoUninstall", alternativeId));
// 使用进度指示器执行卸载操作
await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: localize("language.extensions.uninstall", alternativeId),
cancellable: false
}, async (progress) => {
progress.report({ increment: 0, message: localize("language.extensions.uninstalling", alternativeId) });
await vscode.commands.executeCommand("workbench.extensions.uninstallExtension", alternativeId);
progress.report({ increment: 100, message: localize("language.extensions.uninstalled", alternativeId) });
});
// 卸载完成后,通知用户
vscode.window.showInformationMessage(localize("language.extensions.uninstalled", alternativeId));
}catch(error : any){
vscode.window.showErrorMessage(`uninstall error: ${error.message}`);
return false;
}
console.log(metaData)
console.log(" ensureExtension:" + metaData.extensionId);
const extension: Extension<any> | undefined = extensions.getExtension(metaData.extensionId);
if (extension === undefined) {
console.log(" ensureExtension install " + metaData.extensionId);
return await promptInstallExtension(typeName, metaData);
// return false;
}
if (metaData.leastExtensionVersion && semver.lt(extension.packageJSON.version, metaData.leastExtensionVersion)) {
return await promptUpdateExtension(typeName, metaData);
// return false;
}
await extension.activate();
return true;
}
async function promptInstallExtension(javaProjectType: string, metaData: IProjectTypeMetadata): Promise<boolean> {
const choice: string | undefined = await window.showInformationMessage(
localize("language.chooseInstallFiles.noticeInstall", metaData.extensionName, javaProjectType),
// `${metaData.extensionName} is required to create ${JavaProjectType} projects. Please re-run the command 'Java: Create Java Project...' after the extension is installed.`,
localize("language.install"));
if (choice === localize("language.install")) {
commands.executeCommand(Commands.INSTALL_EXTENSION, metaData.extensionId);
commands.executeCommand("workbench.extensions.installExtension", metaData.extensionId);
commands.executeCommand("extension.open", metaData.extensionId);
// commands.executeCommand("maven.archetype.generate");
return true;
async function promptInstallExtension(javaProjectType: string, metaData: IProjectTypeMetadata, isAsk: boolean): Promise<string|undefined> {
let choice: string|undefined = undefined;
if(isAsk){
choice = await vscode.window.showInformationMessage(
localize("language.chooseInstallFiles.noticeInstall", metaData.extensionName, javaProjectType),
// `${metaData.extensionName} is required to create ${JavaProjectType} projects. Please re-run the command 'Java: Create Java Project...' after the extension is installed.`,
localize("language.install"));
}
return false;
if (!isAsk || choice === localize("language.install")) {
const ids = metaData.extensionId.split(',').map(id => id.trim());
if(ids.length >= 1){
// vscode.commands.executeCommand(Commands.INSTALL_EXTENSION, ids[0]);
vscode.commands.executeCommand("extension.open", ids[0]);
await vscode.commands.executeCommand("workbench.extensions.installExtension", ids[0]);
// commands.executeCommand("maven.archetype.generate");
return ids[0];
}
}
return undefined;
}
async function promptUpdateExtension(javaProjectType: string, metaData: IProjectTypeMetadata): Promise<boolean> {
const choice: string | undefined = await window.showInformationMessage(
const choice: string | undefined = await vscode.window.showInformationMessage(
localize("language.chooseInstallFiles.noticeUpdate", metaData.extensionName, javaProjectType),
// `${metaData.extensionName} needs to be updated to create ${JavaProjectType} projects. Please re-run the command 'Java: Create Java Project...' after the extension is updated.`,
localize("language.update"));
if (choice === localize("language.update")) {
commands.executeCommand(Commands.INSTALL_EXTENSION, metaData.extensionId);
vscode.commands.executeCommand(Commands.INSTALL_EXTENSION, metaData.extensionId);
return true;
}
return false;

View File

@ -203,7 +203,7 @@ const options = {
},
metadata: {
"type": "Maven",
"extensionId": "KylinIDETeam.vscode-maven",
"extensionId": "KylinIDETeam.vscode-maven,vscjava.vscode-maven",
"extensionName": "Maven for Java",
"createCommandId": "maven.archetype.generate"
},
@ -226,7 +226,7 @@ const options = {
},
metadata: {
"type": "Gradle",
"extensionId": "KylinIDETeam.vscode-gradle",
"extensionId": "KylinIDETeam.vscode-gradle,vscjava.vscode-gradle",
"extensionName": "Gradle for Java",
"leastExtensionVersion": "3.10.0",
"createCommandId": "gradle.createProject"
@ -249,7 +249,7 @@ const options = {
},
metadata: {
"type": "JavaFX",
"extensionId": "KylinIDETeam.vscode-maven",
"extensionId": "KylinIDETeam.vscode-maven,vscjava.vscode-maven",
"extensionName": "Maven for Java",
"leastExtensionVersion": "0.35.0",
"createCommandId": "maven.archetype.generate",

View File

@ -18,10 +18,8 @@ import { Utility } from "../utility";
import { BaseManager } from "../BaseManager";
import * as java from "../common/java";
import { LangProConfig } from "../common/packageConfig";
import { ensureExtension, JavaProjectType } from "../installExternsionDeps";
import localize from "../localize";
import * as utils from "../utils";
import { Choice, ChoiceClass } from "../common/defines";
export class JavaManager extends BaseManager {

View File

@ -1403,21 +1403,21 @@ export class PackageManager extends BaseManager {
return ret;
}
public async isMavenForJavaExists(): Promise<boolean> {
var packageWarExtension: IProjectType = {
displayName: "Maven",
description: "create from archetype",
metadata: {
type: JavaProjectType.Maven,
extensionId: "KylinIDETeam.vscode-maven",
extensionName: "Maven for Java",
createCommandId: ""
}
};
// public async isMavenForJavaExists(): Promise<boolean> {
// var packageWarExtension: IProjectType = {
// displayName: "Maven",
// description: "create from archetype",
// metadata: {
// type: JavaProjectType.Maven,
// extensionId: "KylinIDETeam.vscode-maven",
// extensionName: "Maven for Java",
// createCommandId: ""
// }
// };
var ret = await ensureExtension(packageWarExtension.displayName, packageWarExtension.metadata);
return ret;
}
// var ret = await ensureExtension(packageWarExtension.displayName, packageWarExtension.metadata);
// return ret;
// }
public async warPackage() {
let mvnPom = new Meven();
@ -1548,8 +1548,8 @@ export class PackageManager extends BaseManager {
}
};
var ret = await ensureExtension(packageJarExtension.displayName, packageJarExtension.metadata);
if (ret === false) {
var extensionId = await ensureExtension(packageJarExtension.displayName, packageJarExtension.metadata);
if (extensionId === undefined) {
return;
}

View File

@ -99,7 +99,6 @@
v-else-if="item.type == 'select-input'"
class="pl-2 select-input"
>
{{`models[${item.model}]: ${models[item.model]}` }}
<el-col :span="24">
<select-input
v-model="models[item.model]"