-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add menuconfig abstraction framework with priority-based fallback #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b54d3d9
3c5f8ee
9af19c7
fbc23b0
952da81
4c4fefc
a081765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, MENUCONFIG_COMMANDS } from '../smart'; | ||||||||||||
|
|
||||||||||||
| let _currentProject: string = ''; | ||||||||||||
|
|
||||||||||||
|
|
@@ -28,9 +29,48 @@ 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 rt-thread-kconfig extension, it handles multi-BSP scenarios automatically | ||||||||||||
| 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 === 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: 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'; | ||||||||||||
| executeCommand(cmd); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| else { | ||||||||||||
| // Generic extension command | ||||||||||||
| executeCommand('cd ' + arg.fn); | ||||||||||||
| vscode.commands.executeCommand(menuconfigMethod.command!); | ||||||||||||
| } | ||||||||||||
|
||||||||||||
| else { | |
| // Generic extension command | |
| executeCommand('cd ' + arg.fn); | |
| vscode.commands.executeCommand(menuconfigMethod.command!); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,73 @@ 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 | ||
| } | ||
|
|
||
| /** | ||
| * Extension command constants for menuconfig | ||
| */ | ||
| export const MENUCONFIG_COMMANDS = { | ||
| RT_THREAD_KCONFIG: 'rt-thread-kconfig.menuconfig.windows', | ||
| KCONFIG_VISUAL_EDITOR: 'kconfig-visual-editor.open' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flyingcys 这里的扩展id对吗?谢谢 |
||
| }; | ||
|
|
||
| /** | ||
| * 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: MENUCONFIG_COMMANDS.RT_THREAD_KCONFIG | ||
| }; | ||
| } | ||
|
|
||
| // 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, | ||
| }; | ||
| } | ||
|
|
||
| // Priority 3: Fall back to terminal menuconfig | ||
| return { | ||
| type: 'terminal', | ||
| terminal: 'scons --menuconfig' | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.