mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
refactor(vscode-ide-companion): introduce ApprovalMode enum and improve mode handling
- Create new approvalModeTypes.ts with ApprovalMode enum and helper functions - Replace hardcoded string literals with ApprovalModeValue type - Consolidate mode mapping logic using new helper functions
This commit is contained in:
@@ -11,7 +11,8 @@ import type {
|
||||
PermissionOption,
|
||||
ToolCall as PermissionToolCall,
|
||||
} from '../components/PermissionDrawer/PermissionRequest.js';
|
||||
import type { ToolCallUpdate, EditMode } from '../../types/chatTypes.js';
|
||||
import type { ToolCallUpdate } from '../../types/chatTypes.js';
|
||||
import type { ApprovalModeValue } from '../../types/acpTypes.js';
|
||||
import type { PlanEntry } from '../../types/chatTypes.js';
|
||||
|
||||
interface UseWebViewMessagesProps {
|
||||
@@ -107,7 +108,7 @@ interface UseWebViewMessagesProps {
|
||||
inputFieldRef: React.RefObject<HTMLDivElement>;
|
||||
setInputText: (text: string) => void;
|
||||
// Edit mode setter (maps ACP modes to UI modes)
|
||||
setEditMode?: (mode: EditMode) => void;
|
||||
setEditMode?: (mode: ApprovalModeValue) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,20 +197,9 @@ export const useWebViewMessages = ({
|
||||
case 'modeInfo': {
|
||||
// Initialize UI mode from ACP initialize
|
||||
try {
|
||||
const current = (message.data?.currentModeId || 'default') as
|
||||
| 'plan'
|
||||
| 'default'
|
||||
| 'auto-edit'
|
||||
| 'yolo';
|
||||
setEditMode?.(
|
||||
(current === 'plan'
|
||||
? 'plan'
|
||||
: current === 'auto-edit'
|
||||
? 'auto'
|
||||
: current === 'yolo'
|
||||
? 'yolo'
|
||||
: 'ask') as EditMode,
|
||||
);
|
||||
const current = (message.data?.currentModeId ||
|
||||
'default') as ApprovalModeValue;
|
||||
setEditMode?.(current);
|
||||
} catch (_error) {
|
||||
// best effort
|
||||
}
|
||||
@@ -218,20 +208,9 @@ export const useWebViewMessages = ({
|
||||
|
||||
case 'modeChanged': {
|
||||
try {
|
||||
const modeId = (message.data?.modeId || 'default') as
|
||||
| 'plan'
|
||||
| 'default'
|
||||
| 'auto-edit'
|
||||
| 'yolo';
|
||||
setEditMode?.(
|
||||
(modeId === 'plan'
|
||||
? 'plan'
|
||||
: modeId === 'auto-edit'
|
||||
? 'auto'
|
||||
: modeId === 'yolo'
|
||||
? 'yolo'
|
||||
: 'ask') as EditMode,
|
||||
);
|
||||
const modeId = (message.data?.modeId ||
|
||||
'default') as ApprovalModeValue;
|
||||
setEditMode?.(modeId);
|
||||
} catch (_error) {
|
||||
// Ignore error when setting mode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user