From b54d3d978d65f860dc8c90ccd9b51164d5d34b59 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:28:44 +0000 Subject: [PATCH 1/7] Initial plan From 3c5f8ee3d87bd5e66b9c2035648f746840219c31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:35:08 +0000 Subject: [PATCH 2/7] feat: Add support for vscode-kconfig-visual-editor and menuconfig configuration option Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- package.json | 8 ++++++ src/dock.ts | 22 ++++++++++------ src/project/cmd.ts | 21 +++++++++++++--- src/smart.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 099eb82..ed29845 100644 --- a/package.json +++ b/package.json @@ -180,6 +180,14 @@ "markdownDescription": "并行编译使用的 CPU 核心数(默认为 1)。\n\n设置大于 1 的值可以加快编译速度,例如:\n- `1`: 单核编译\n- `4`: 使用 4 个核心并行编译\n- `8`: 使用 8 个核心并行编译", "scope": "resource", "order": 1 + }, + "smart.useTerminalMenuconfig": { + "type": "boolean", + "default": false, + "description": "是否只使用 scons --menuconfig 方式进行配置(默认为 false)。启用后将不使用图形化 Kconfig 编辑器插件。", + "markdownDescription": "是否只使用 `scons --menuconfig` 方式进行配置(默认为 false)。\n\n- `false`: 优先使用已安装的 Kconfig 图形化编辑器插件\n- `true`: 始终使用终端字符界面方式", + "scope": "resource", + "order": 2 } } }, diff --git a/src/dock.ts b/src/dock.ts index 3508976..177efa0 100644 --- a/src/dock.ts +++ b/src/dock.ts @@ -5,6 +5,7 @@ import fs from 'fs'; import { getWorkspaceFolder, isRTThreadProject, isRTThreadWorksapce } from './api'; import { buildGroupsTree, buildProjectTree, buildEmptyProjectTree, ProjectTreeItem, listFolderTreeItem, buildBSPTree, setTreeDataChangeEmitter } from './project/tree'; import { cmds } from './cmds/index'; +import { getMenuconfigMethod } from './smart'; class CmdTreeDataProvider implements vscode.TreeDataProvider { getTreeItem(element: vscode.TreeItem): vscode.TreeItem { @@ -107,18 +108,25 @@ class CmdTreeDataProvider implements vscode.TreeDataProvider { } else { let children:any = []; - const kconfig = vscode.extensions.getExtension('rt-thread.rt-thread-kconfig'); - for (const [key, value] of Object.entries(cmds)) { if (element.label === value.label) { for (const cmdItem of value.subcmds) { let item = new vscode.TreeItem(cmdItem.name); item.iconPath = new vscode.ThemeIcon(cmdItem.iconId); - if (cmdItem.name === 'menuconfig' && kconfig !== undefined) { - item.command = { - command: "rt-thread-kconfig.menuconfig.windows", - title: cmdItem.cmd.title - }; + if (cmdItem.name === 'menuconfig') { + const menuconfigMethod = getMenuconfigMethod(); + if (menuconfigMethod.type === 'extension') { + item.command = { + command: menuconfigMethod.command!, + title: cmdItem.cmd.title + }; + } else { + item.command = { + command: "extension.executeCommand", + title: cmdItem.cmd.title, + arguments: [menuconfigMethod.terminal!], + }; + } } else { item.command = { diff --git a/src/project/cmd.ts b/src/project/cmd.ts index 3d54c8e..0aecdd7 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import { getWorkspaceFolder } from '../api'; import { executeCommand } from '../terminal'; import { readWorkspaceJson, writeWorkspaceJson } from '../webviews/project'; +import { getMenuconfigMethod } from '../smart'; let _currentProject: string = ''; @@ -28,9 +29,23 @@ export function fastBuildProject(arg: any) { export function configProject(arg: any) { if (arg) { - let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; - - executeCommand(cmd); + const menuconfigMethod = getMenuconfigMethod(); + + if (menuconfigMethod.type === 'extension') { + // For extension-based menuconfig, we need to: + // 1. Set the current working directory to the project + // 2. Execute the extension command + + // Change to the BSP directory first + executeCommand('cd ' + arg.fn); + + // Execute the extension command + vscode.commands.executeCommand(menuconfigMethod.command!); + } else { + // For terminal-based menuconfig + let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; + executeCommand(cmd); + } } return; diff --git a/src/smart.ts b/src/smart.ts index 6a7a113..67509e9 100644 --- a/src/smart.ts +++ b/src/smart.ts @@ -15,3 +15,65 @@ export function getParallelBuildNumber() { return parallel; } + +/* get whether to use terminal menuconfig only */ +export function getUseTerminalMenuconfig() { + const config = vscode.workspace.getConfiguration('smart'); + const useTerminal = config.get('useTerminalMenuconfig') as boolean; + + return useTerminal; +} + +/** + * Menuconfig method type + */ +export interface MenuconfigMethod { + type: 'extension' | 'terminal'; + command?: string; // VS Code command for extension type + terminal?: string; // Terminal command for terminal type +} + +/** + * Get the appropriate menuconfig method based on installed extensions and configuration + * Priority: + * 1. If useTerminalMenuconfig is true, always use terminal + * 2. Check for rt-thread.rt-thread-kconfig extension + * 3. Check for ai-embedded.vscode-kconfig-visual-editor extension + * 4. Fall back to terminal scons --menuconfig + * + * @param kconfigPath Optional Kconfig file path for vscode-kconfig-visual-editor + * @returns MenuconfigMethod object describing the method to use + */ +export function getMenuconfigMethod(kconfigPath?: string): MenuconfigMethod { + // Check if user wants to force terminal menuconfig + if (getUseTerminalMenuconfig()) { + return { + type: 'terminal', + terminal: 'scons --menuconfig' + }; + } + + // Priority 1: Check for rt-thread-kconfig extension + const rtThreadKconfig = vscode.extensions.getExtension('rt-thread.rt-thread-kconfig'); + if (rtThreadKconfig !== undefined) { + return { + type: 'extension', + command: 'rt-thread-kconfig.menuconfig.windows' + }; + } + + // Priority 2: Check for vscode-kconfig-visual-editor extension + const kconfigVisualEditor = vscode.extensions.getExtension('ai-embedded.vscode-kconfig-visual-editor'); + if (kconfigVisualEditor !== undefined) { + return { + type: 'extension', + command: 'kconfig-visual-editor.open', + }; + } + + // Priority 3: Fall back to terminal menuconfig + return { + type: 'terminal', + terminal: 'scons --menuconfig' + }; +} From 9af19c76d2f8dd70ebd94ee441b7cd7775c0af33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:37:14 +0000 Subject: [PATCH 3/7] refine: Improve BSP menuconfig handling for vscode-kconfig-visual-editor Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- src/project/cmd.ts | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/project/cmd.ts b/src/project/cmd.ts index 0aecdd7..cc7e2f2 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -32,15 +32,32 @@ export function configProject(arg: any) { const menuconfigMethod = getMenuconfigMethod(); if (menuconfigMethod.type === 'extension') { - // For extension-based menuconfig, we need to: - // 1. Set the current working directory to the project - // 2. Execute the extension command - - // Change to the BSP directory first - executeCommand('cd ' + arg.fn); - - // Execute the extension command - vscode.commands.executeCommand(menuconfigMethod.command!); + // For rt-thread-kconfig extension, it handles multi-BSP scenarios automatically + if (menuconfigMethod.command === 'rt-thread-kconfig.menuconfig.windows') { + // Change to the BSP directory first + executeCommand('cd ' + arg.fn); + // Execute the extension command + vscode.commands.executeCommand(menuconfigMethod.command); + } + // For vscode-kconfig-visual-editor, we need to open the Kconfig file explicitly + else if (menuconfigMethod.command === 'kconfig-visual-editor.open') { + const kconfigPath = path.join(arg.fn, 'Kconfig'); + if (fs.existsSync(kconfigPath)) { + // Open the Kconfig file with the visual editor + vscode.workspace.openTextDocument(kconfigPath).then(doc => { + vscode.window.showTextDocument(doc); + }); + } else { + // Fallback to terminal if Kconfig doesn't exist + let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; + executeCommand(cmd); + } + } + else { + // Generic extension command + executeCommand('cd ' + arg.fn); + vscode.commands.executeCommand(menuconfigMethod.command!); + } } else { // For terminal-based menuconfig let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; From fbc23b04f8b75467d674a7efdafb5f4a9536b635 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:41:15 +0000 Subject: [PATCH 4/7] refactor: Address code review feedback - extract constants and add error handling Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- src/project/cmd.ts | 20 ++++++++++++++------ src/smart.ts | 12 ++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/project/cmd.ts b/src/project/cmd.ts index cc7e2f2..b3960f0 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import { getWorkspaceFolder } from '../api'; import { executeCommand } from '../terminal'; import { readWorkspaceJson, writeWorkspaceJson } from '../webviews/project'; -import { getMenuconfigMethod } from '../smart'; +import { getMenuconfigMethod, MENUCONFIG_COMMANDS } from '../smart'; let _currentProject: string = ''; @@ -33,20 +33,28 @@ export function configProject(arg: any) { if (menuconfigMethod.type === 'extension') { // For rt-thread-kconfig extension, it handles multi-BSP scenarios automatically - if (menuconfigMethod.command === 'rt-thread-kconfig.menuconfig.windows') { + if (menuconfigMethod.command === MENUCONFIG_COMMANDS.RT_THREAD_KCONFIG) { // Change to the BSP directory first executeCommand('cd ' + arg.fn); // Execute the extension command vscode.commands.executeCommand(menuconfigMethod.command); } // For vscode-kconfig-visual-editor, we need to open the Kconfig file explicitly - else if (menuconfigMethod.command === 'kconfig-visual-editor.open') { + else if (menuconfigMethod.command === MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR) { const kconfigPath = path.join(arg.fn, 'Kconfig'); if (fs.existsSync(kconfigPath)) { // Open the Kconfig file with the visual editor - vscode.workspace.openTextDocument(kconfigPath).then(doc => { - vscode.window.showTextDocument(doc); - }); + vscode.workspace.openTextDocument(kconfigPath).then( + doc => { + vscode.window.showTextDocument(doc); + }, + (error: Error) => { + vscode.window.showErrorMessage(`Failed to open Kconfig file: ${error.message}`); + // Fallback to terminal on error + let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; + executeCommand(cmd); + } + ); } else { // Fallback to terminal if Kconfig doesn't exist let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; diff --git a/src/smart.ts b/src/smart.ts index 67509e9..dfd30c1 100644 --- a/src/smart.ts +++ b/src/smart.ts @@ -33,6 +33,14 @@ export interface MenuconfigMethod { terminal?: string; // Terminal command for terminal type } +/** + * Extension command constants for menuconfig + */ +export const MENUCONFIG_COMMANDS = { + RT_THREAD_KCONFIG: 'rt-thread-kconfig.menuconfig.windows', + KCONFIG_VISUAL_EDITOR: 'kconfig-visual-editor.open' +}; + /** * Get the appropriate menuconfig method based on installed extensions and configuration * Priority: @@ -58,7 +66,7 @@ export function getMenuconfigMethod(kconfigPath?: string): MenuconfigMethod { if (rtThreadKconfig !== undefined) { return { type: 'extension', - command: 'rt-thread-kconfig.menuconfig.windows' + command: MENUCONFIG_COMMANDS.RT_THREAD_KCONFIG }; } @@ -67,7 +75,7 @@ export function getMenuconfigMethod(kconfigPath?: string): MenuconfigMethod { if (kconfigVisualEditor !== undefined) { return { type: 'extension', - command: 'kconfig-visual-editor.open', + command: MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR, }; } From 952da814113bff500c5cbf6c80ff70cea61ae7fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:43:06 +0000 Subject: [PATCH 5/7] refactor: Extract terminal menuconfig fallback logic to reduce duplication Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- src/project/cmd.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/project/cmd.ts b/src/project/cmd.ts index b3960f0..e718e8e 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -27,6 +27,15 @@ export function fastBuildProject(arg: any) { return; } +/** + * Helper function to execute terminal-based menuconfig for a BSP project + * @param bspPath The path to the BSP project + */ +function executeTerminalMenuconfig(bspPath: string) { + let cmd = 'scons -C ' + bspPath + ' --menuconfig'; + executeCommand(cmd); +} + export function configProject(arg: any) { if (arg) { const menuconfigMethod = getMenuconfigMethod(); @@ -48,17 +57,15 @@ export function configProject(arg: any) { doc => { vscode.window.showTextDocument(doc); }, - (error: Error) => { + error => { vscode.window.showErrorMessage(`Failed to open Kconfig file: ${error.message}`); // Fallback to terminal on error - let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; - executeCommand(cmd); + executeTerminalMenuconfig(arg.fn); } ); } else { // Fallback to terminal if Kconfig doesn't exist - let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; - executeCommand(cmd); + executeTerminalMenuconfig(arg.fn); } } else { @@ -68,8 +75,7 @@ export function configProject(arg: any) { } } else { // For terminal-based menuconfig - let cmd = 'scons -C ' + arg.fn + ' --menuconfig'; - executeCommand(cmd); + executeTerminalMenuconfig(arg.fn); } } From 4c4fefc0becdf79075ccad08577edcab6032813a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 03:45:24 +0000 Subject: [PATCH 6/7] style: Use const instead of let for immutable variable Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- src/project/cmd.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project/cmd.ts b/src/project/cmd.ts index e718e8e..2fe99dd 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -32,7 +32,7 @@ export function fastBuildProject(arg: any) { * @param bspPath The path to the BSP project */ function executeTerminalMenuconfig(bspPath: string) { - let cmd = 'scons -C ' + bspPath + ' --menuconfig'; + const cmd = 'scons -C ' + bspPath + ' --menuconfig'; executeCommand(cmd); } From a0817651d86a85301aca69ce433e62d5a73966bb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:05:30 +0000 Subject: [PATCH 7/7] refactor: Comment out vscode-kconfig-visual-editor support until ready - Comment out vscode-kconfig-visual-editor detection and handling - Keep the abstraction framework with TODO comments - Fix error message to be more accurate (open or display) - Remove unreachable else block as it's no longer needed Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com> --- src/project/cmd.ts | 45 ++++++++++++++++++++------------------------- src/smart.ts | 17 +++++++++-------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/project/cmd.ts b/src/project/cmd.ts index 2fe99dd..2e6db86 100644 --- a/src/project/cmd.ts +++ b/src/project/cmd.ts @@ -47,32 +47,27 @@ export function configProject(arg: any) { executeCommand('cd ' + arg.fn); // Execute the extension command vscode.commands.executeCommand(menuconfigMethod.command); - } - // For vscode-kconfig-visual-editor, we need to open the Kconfig file explicitly - else if (menuconfigMethod.command === MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR) { - const kconfigPath = path.join(arg.fn, 'Kconfig'); - if (fs.existsSync(kconfigPath)) { - // Open the Kconfig file with the visual editor - vscode.workspace.openTextDocument(kconfigPath).then( - doc => { - vscode.window.showTextDocument(doc); - }, - error => { - vscode.window.showErrorMessage(`Failed to open Kconfig file: ${error.message}`); - // Fallback to terminal on error - executeTerminalMenuconfig(arg.fn); - } - ); - } else { - // Fallback to terminal if Kconfig doesn't exist - executeTerminalMenuconfig(arg.fn); - } - } - else { - // Generic extension command - executeCommand('cd ' + arg.fn); - vscode.commands.executeCommand(menuconfigMethod.command!); } + // TODO: Add handling for vscode-kconfig-visual-editor when it's ready + // else if (menuconfigMethod.command === MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR) { + // const kconfigPath = path.join(arg.fn, 'Kconfig'); + // if (fs.existsSync(kconfigPath)) { + // // Open the Kconfig file with the visual editor + // vscode.workspace.openTextDocument(kconfigPath).then( + // doc => { + // vscode.window.showTextDocument(doc); + // }, + // error => { + // vscode.window.showErrorMessage(`Failed to open or display Kconfig file: ${error.message}`); + // // Fallback to terminal on error + // executeTerminalMenuconfig(arg.fn); + // } + // ); + // } else { + // // Fallback to terminal if Kconfig doesn't exist + // executeTerminalMenuconfig(arg.fn); + // } + // } } else { // For terminal-based menuconfig executeTerminalMenuconfig(arg.fn); diff --git a/src/smart.ts b/src/smart.ts index dfd30c1..60a7806 100644 --- a/src/smart.ts +++ b/src/smart.ts @@ -46,7 +46,7 @@ export const MENUCONFIG_COMMANDS = { * Priority: * 1. If useTerminalMenuconfig is true, always use terminal * 2. Check for rt-thread.rt-thread-kconfig extension - * 3. Check for ai-embedded.vscode-kconfig-visual-editor extension + * 3. Check for ai-embedded.vscode-kconfig-visual-editor extension (currently disabled) * 4. Fall back to terminal scons --menuconfig * * @param kconfigPath Optional Kconfig file path for vscode-kconfig-visual-editor @@ -71,13 +71,14 @@ export function getMenuconfigMethod(kconfigPath?: string): MenuconfigMethod { } // Priority 2: Check for vscode-kconfig-visual-editor extension - const kconfigVisualEditor = vscode.extensions.getExtension('ai-embedded.vscode-kconfig-visual-editor'); - if (kconfigVisualEditor !== undefined) { - return { - type: 'extension', - command: MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR, - }; - } + // TODO: Uncomment when vscode-kconfig-visual-editor is ready + // const kconfigVisualEditor = vscode.extensions.getExtension('ai-embedded.vscode-kconfig-visual-editor'); + // if (kconfigVisualEditor !== undefined) { + // return { + // type: 'extension', + // command: MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR, + // }; + // } // Priority 3: Fall back to terminal menuconfig return {