|
8 | 8 | import './activityErrorQuickFix.css';
|
9 | 9 |
|
10 | 10 | // React.
|
11 |
| -import React, { useRef } from 'react'; |
| 11 | +import React, { useMemo, useRef } from 'react'; |
12 | 12 |
|
13 | 13 | // Other dependencies.
|
14 | 14 | import { localize } from '../../../../../nls.js';
|
15 | 15 | import { PositronButton } from '../../../../../base/browser/ui/positronComponents/button/positronButton.js';
|
16 | 16 | import { usePositronReactServicesContext } from '../../../../../base/browser/positronReactRendererContext.js';
|
| 17 | +import { ANSIOutputLine } from '../../../../../base/common/ansiOutput.js'; |
17 | 18 |
|
18 |
| -const fixPrompt = localize('positronConsoleErrorFixPrompt', "You are going to provide a quick fix for a Positron Console error. The Console session is attached. Provide the user an code snippet that can be applied to the Positron Console to fix the error, or explain why the error is occurring only if you cannot resolve it on your own."); |
19 |
| -const explainPrompt = localize('positronConsoleErrorExplainPrompt', "You are going to provide an explanation for a Positron Console error. The Console session is attached. Provide the user an explanation of why the error is occurring, and how they can resolve it. Do not provide a code snippet unless it is necessary to explain the error."); |
| 19 | +const fixPrompt = '/fix'; |
| 20 | +const explainPrompt = '/explain'; |
20 | 21 |
|
| 22 | +interface ConsoleQuickFixProps { |
| 23 | + outputLines: ANSIOutputLine[]; |
| 24 | + tracebackLines: ANSIOutputLine[]; |
| 25 | +} |
| 26 | + |
| 27 | +const formatOutput = (outputLines: ANSIOutputLine[], tracebackLines: ANSIOutputLine[]) => { |
| 28 | + return outputLines.map(line => line.outputRuns.map(run => run.text).join('')).join('\n') + '\n' + tracebackLines.map(line => line.outputRuns.map(run => run.text).join('')).join('\n'); |
| 29 | +}; |
21 | 30 |
|
22 | 31 | /**
|
23 | 32 | * Quick fix component.
|
24 | 33 | * @returns The rendered component.
|
25 | 34 | */
|
26 |
| -export const ConsoleQuickFix = () => { |
| 35 | +export const ConsoleQuickFix = (props: ConsoleQuickFixProps) => { |
27 | 36 | const buttonRef = useRef<HTMLDivElement>(undefined!);
|
28 | 37 | const { quickChatService } = usePositronReactServicesContext();
|
| 38 | + |
| 39 | + const formattedOutput = useMemo(() => { |
| 40 | + return formatOutput(props.outputLines, props.tracebackLines); |
| 41 | + }, [props.outputLines, props.tracebackLines]); |
29 | 42 | /**
|
30 | 43 | * onClick handlers.
|
31 | 44 | */
|
32 | 45 | const pressedFixHandler = async () => {
|
33 | 46 | // Handle console quick fix action.
|
34 |
| - quickChatService.openOne({ query: fixPrompt }); |
| 47 | + quickChatService.openOne({ |
| 48 | + query: props.outputLines ? `${fixPrompt}\n\`\`\`${formattedOutput}\`\`\`` : fixPrompt, |
| 49 | + renderInputOnTop: false |
| 50 | + }); |
35 | 51 | };
|
36 | 52 |
|
37 | 53 | const pressedExplainHandler = async () => {
|
38 | 54 | // Handle console quick explain action.
|
39 |
| - quickChatService.openOne({ query: explainPrompt }); |
| 55 | + quickChatService.openOne({ |
| 56 | + query: props.outputLines ? `${explainPrompt}\n\`\`\`${formattedOutput}\`\`\`` : explainPrompt, |
| 57 | + renderInputOnTop: false |
| 58 | + }); |
40 | 59 | };
|
41 | 60 |
|
42 | 61 | // Render.
|
|
0 commit comments