mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
refactor(vscode-ide-companion): update message handling and configuration
This commit is contained in:
@@ -105,7 +105,6 @@ export const useMessageHandling = () => {
|
||||
const endStreaming = useCallback(() => {
|
||||
// Finalize streaming; content already lives in the placeholder message
|
||||
setIsStreaming(false);
|
||||
setIsWaitingForResponse(false);
|
||||
streamingMessageIndexRef.current = null;
|
||||
// Remove the thinking message if it exists (collapse thoughts)
|
||||
setMessages((prev) => {
|
||||
|
||||
@@ -14,6 +14,8 @@ interface UseMessageSubmitProps {
|
||||
setInputText: (text: string) => void;
|
||||
inputFieldRef: React.RefObject<HTMLDivElement>;
|
||||
isStreaming: boolean;
|
||||
// When true, do NOT auto-attach the active editor file/selection to context
|
||||
skipAutoActiveContext?: boolean;
|
||||
|
||||
fileContext: {
|
||||
getFileReference: (fileName: string) => string | undefined;
|
||||
@@ -38,6 +40,7 @@ export const useMessageSubmit = ({
|
||||
setInputText,
|
||||
inputFieldRef,
|
||||
isStreaming,
|
||||
skipAutoActiveContext = false,
|
||||
fileContext,
|
||||
messageHandling,
|
||||
}: UseMessageSubmitProps) => {
|
||||
@@ -94,8 +97,8 @@ export const useMessageSubmit = ({
|
||||
}
|
||||
}
|
||||
|
||||
// Add active file selection context if present
|
||||
if (fileContext.activeFilePath) {
|
||||
// Add active file selection context if present and not skipped
|
||||
if (fileContext.activeFilePath && !skipAutoActiveContext) {
|
||||
const fileName = fileContext.activeFileName || 'current file';
|
||||
context.push({
|
||||
type: 'file',
|
||||
@@ -115,7 +118,11 @@ export const useMessageSubmit = ({
|
||||
}
|
||||
| undefined;
|
||||
|
||||
if (fileContext.activeFilePath && fileContext.activeFileName) {
|
||||
if (
|
||||
fileContext.activeFilePath &&
|
||||
fileContext.activeFileName &&
|
||||
!skipAutoActiveContext
|
||||
) {
|
||||
fileContextForMessage = {
|
||||
fileName: fileContext.activeFileName,
|
||||
filePath: fileContext.activeFilePath,
|
||||
@@ -146,6 +153,7 @@ export const useMessageSubmit = ({
|
||||
inputFieldRef,
|
||||
vscode,
|
||||
fileContext,
|
||||
skipAutoActiveContext,
|
||||
messageHandling,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -112,6 +112,9 @@ export const useWebViewMessages = ({
|
||||
}: UseWebViewMessagesProps) => {
|
||||
// VS Code API for posting messages back to the extension host
|
||||
const vscode = useVSCode();
|
||||
// Track active long-running tool calls (execute/bash/command) so we can
|
||||
// keep the bottom "waiting" message visible until all of them complete.
|
||||
const activeExecToolCallsRef = useRef<Set<string>>(new Set());
|
||||
// Use ref to store callbacks to avoid useEffect dependency issues
|
||||
const handlersRef = useRef({
|
||||
sessionManagement,
|
||||
@@ -260,14 +263,19 @@ export const useWebViewMessages = ({
|
||||
// no-op: stream might not have been started
|
||||
console.warn('[PanelManager] Failed to end streaming:', err);
|
||||
}
|
||||
try {
|
||||
handlers.messageHandling.clearWaitingForResponse();
|
||||
} catch (err) {
|
||||
// no-op: already cleared
|
||||
console.warn(
|
||||
'[PanelManager] Failed to clear waiting for response:',
|
||||
err,
|
||||
);
|
||||
// Important: Do NOT blindly clear the waiting message if there are
|
||||
// still active tool calls running. We keep the waiting indicator
|
||||
// tied to tool-call lifecycle instead.
|
||||
if (activeExecToolCallsRef.current.size === 0) {
|
||||
try {
|
||||
handlers.messageHandling.clearWaitingForResponse();
|
||||
} catch (err) {
|
||||
// no-op: already cleared
|
||||
console.warn(
|
||||
'[PanelManager] Failed to clear waiting for response:',
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -293,6 +301,11 @@ export const useWebViewMessages = ({
|
||||
case 'streamEnd':
|
||||
handlers.messageHandling.endStreaming();
|
||||
handlers.messageHandling.clearThinking();
|
||||
// Clear the generic waiting indicator only if there are no active
|
||||
// long-running tool calls. Otherwise, keep it visible.
|
||||
if (activeExecToolCallsRef.current.size === 0) {
|
||||
handlers.messageHandling.clearWaitingForResponse();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
@@ -439,20 +452,33 @@ export const useWebViewMessages = ({
|
||||
const kind = (toolCallData.kind || '').toString().toLowerCase();
|
||||
const isExec =
|
||||
kind === 'execute' || kind === 'bash' || kind === 'command';
|
||||
if (isExec && (status === 'pending' || status === 'in_progress')) {
|
||||
const rawInput = toolCallData.rawInput;
|
||||
let cmd = '';
|
||||
if (typeof rawInput === 'string') {
|
||||
cmd = rawInput;
|
||||
} else if (rawInput && typeof rawInput === 'object') {
|
||||
const maybe = rawInput as { command?: string };
|
||||
cmd = maybe.command || '';
|
||||
|
||||
if (isExec) {
|
||||
const id = (toolCallData.toolCallId || '').toString();
|
||||
|
||||
// Maintain the active set by status
|
||||
if (status === 'pending' || status === 'in_progress') {
|
||||
activeExecToolCallsRef.current.add(id);
|
||||
|
||||
// Build a helpful hint from rawInput
|
||||
const rawInput = toolCallData.rawInput;
|
||||
let cmd = '';
|
||||
if (typeof rawInput === 'string') {
|
||||
cmd = rawInput;
|
||||
} else if (rawInput && typeof rawInput === 'object') {
|
||||
const maybe = rawInput as { command?: string };
|
||||
cmd = maybe.command || '';
|
||||
}
|
||||
const hint = cmd ? `Running: ${cmd}` : 'Running command...';
|
||||
handlers.messageHandling.setWaitingForResponse(hint);
|
||||
} else if (status === 'completed' || status === 'failed') {
|
||||
activeExecToolCallsRef.current.delete(id);
|
||||
}
|
||||
|
||||
// If no active exec tool remains, clear the waiting message.
|
||||
if (activeExecToolCallsRef.current.size === 0) {
|
||||
handlers.messageHandling.clearWaitingForResponse();
|
||||
}
|
||||
const hint = cmd ? `Running: ${cmd}` : 'Running command...';
|
||||
handlers.messageHandling.setWaitingForResponse(hint);
|
||||
}
|
||||
if (status === 'completed' || status === 'failed') {
|
||||
handlers.messageHandling.clearWaitingForResponse();
|
||||
}
|
||||
} catch (_err) {
|
||||
// Best-effort UI hint; ignore errors
|
||||
|
||||
Reference in New Issue
Block a user