@@ -23,19 +23,19 @@ interface CommandExecutionProps {
2323export const CommandExecution = ( { executionId, text, icon, title } : CommandExecutionProps ) => {
2424 const { terminalShellIntegrationDisabled = false } = useExtensionState ( )
2525
26+ const { command, output : parsedOutput } = useMemo ( ( ) => parseCommandAndOutput ( text ) , [ text ] )
27+
2628 // If we aren't opening the VSCode terminal for this command then we default
2729 // to expanding the command execution output.
2830 const [ isExpanded , setIsExpanded ] = useState ( terminalShellIntegrationDisabled )
29-
30- const { command : initialCommand , output : initialOutput } = useMemo (
31- ( ) => ( text ? parseCommandAndOutput ( text ) : { command : "" , output : "" } ) ,
32- [ text ] ,
33- )
34-
35- const [ output , setOutput ] = useState ( initialOutput )
36- const [ command , setCommand ] = useState ( initialCommand )
31+ const [ streamingOutput , setStreamingOutput ] = useState ( "" )
3732 const [ status , setStatus ] = useState < CommandExecutionStatus | null > ( null )
3833
34+ // The command's output can either come from the text associated with the
35+ // task message (this is the case for completed commands) or from the
36+ // streaming output (this is the case for running commands).
37+ const output = streamingOutput || parsedOutput
38+
3939 const onMessage = useCallback (
4040 ( event : MessageEvent ) => {
4141 const message : ExtensionMessage = event . data
@@ -52,11 +52,10 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
5252
5353 switch ( data . status ) {
5454 case "started" :
55- setCommand ( data . command )
5655 setStatus ( data )
5756 break
5857 case "output" :
59- setOutput ( data . output )
58+ setStreamingOutput ( data . output )
6059 break
6160 case "fallback" :
6261 setIsExpanded ( true )
@@ -143,7 +142,11 @@ const OutputContainerInternal = ({ isExpanded, output }: { isExpanded: boolean;
143142
144143const OutputContainer = memo ( OutputContainerInternal )
145144
146- const parseCommandAndOutput = ( text : string ) => {
145+ const parseCommandAndOutput = ( text : string | undefined ) => {
146+ if ( ! text ) {
147+ return { command : "" , output : "" }
148+ }
149+
147150 const index = text . indexOf ( COMMAND_OUTPUT_STRING )
148151
149152 if ( index === - 1 ) {
0 commit comments