Skip to content

Adds quick fix button in Console #8609

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/base/browser/positronReactServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { IPositronConnectionsService } from '../../workbench/services/positronCo
import { IPositronWebviewPreloadService } from '../../workbench/services/positronWebviewPreloads/browser/positronWebviewPreloadService.js';
import { IPositronNotebookOutputWebviewService } from '../../workbench/contrib/positronOutputWebview/browser/notebookOutputWebviewService.js';
import { IPositronDataExplorerService } from '../../workbench/services/positronDataExplorer/browser/interfaces/positronDataExplorerService.js';
import { IQuickChatService } from '../../workbench/contrib/chat/browser/chat.js';
import { IActionWidgetService } from '../../platform/actionWidget/browser/actionWidget.js';

/**
* PositronReactServices interface.
Expand All @@ -78,6 +80,7 @@ export class PositronReactServices {
*/
public constructor(
@IAccessibilityService public readonly accessibilityService: IAccessibilityService,
@IActionWidgetService public readonly actionWidgetService: IActionWidgetService,
@IClipboardService public readonly clipboardService: IClipboardService,
@ICommandService public readonly commandService: ICommandService,
@IConfigurationService public readonly configurationService: IConfigurationService,
Expand Down Expand Up @@ -114,6 +117,7 @@ export class PositronReactServices {
@IPositronVariablesService public readonly positronVariablesService: IPositronVariablesService,
@IPositronWebviewPreloadService public readonly positronWebviewPreloadService: IPositronWebviewPreloadService,
@IPreferencesService public readonly preferencesService: IPreferencesService,
@IQuickChatService public readonly quickChatService: IQuickChatService,
@IQuickInputService public readonly quickInputService: IQuickInputService,
@IRuntimeSessionService public readonly runtimeSessionService: IRuntimeSessionService,
@IRuntimeStartupService public readonly runtimeStartupService: IRuntimeStartupService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { localize } from '../../../../../nls.js';
import { ConsoleOutputLines } from './consoleOutputLines.js';
import { PositronButton } from '../../../../../base/browser/ui/positronComponents/button/positronButton.js';
import { ActivityItemErrorMessage } from '../../../../services/positronConsole/browser/classes/activityItemErrorMessage.js';
import { ConsoleQuickFix } from './activityErrorQuickFix.js';

// ActivityErrorProps interface.
export interface ActivityErrorMessageProps {
Expand Down Expand Up @@ -81,6 +82,8 @@ export const ActivityErrorMessage = (props: ActivityErrorMessageProps) => {
);
};



// Render.
return (
<div ref={activityErrorMessageRef} className='activity-error-message'>
Expand All @@ -89,9 +92,12 @@ export const ActivityErrorMessage = (props: ActivityErrorMessageProps) => {
{props.activityItemErrorMessage.messageOutputLines.length > 0 &&
<ConsoleOutputLines outputLines={props.activityItemErrorMessage.messageOutputLines} />
}
{props.activityItemErrorMessage.tracebackOutputLines.length > 0 &&
<Traceback />
}
<div className='error-footer'>
{props.activityItemErrorMessage.tracebackOutputLines.length > 0 &&
<Traceback />
}
<ConsoleQuickFix />
</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2025 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/

.activity-error-message .quick-fix {
display: flex;
flex-direction: row;
justify-content: flex-start;
gap: 8px;
}

.activity-error-message .quick-fix .assistant-action .link-text {
text-decoration: underline;
color: var(--vscode-textLink-foreground);
cursor: pointer;

.codicon {
color: var(--vscode-textLink-foreground);
font-size: 12px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2025 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/


// CSS.
import './activityErrorQuickFix.css';

// React.
import React, { useRef } from 'react';

// Other dependencies.
import { localize } from '../../../../../nls.js';
import { PositronButton } from '../../../../../base/browser/ui/positronComponents/button/positronButton.js';
import { usePositronReactServicesContext } from '../../../../../base/browser/positronReactRendererContext.js';

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.");
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.");


/**
* Quick fix component.
* @returns The rendered component.
*/
export const ConsoleQuickFix = () => {
const buttonRef = useRef<HTMLDivElement>(undefined!);
const { quickChatService } = usePositronReactServicesContext();
/**
* onClick handlers.
*/
const pressedFixHandler = async () => {
// Handle console quick fix action.
quickChatService.open({ query: fixPrompt });
};

const pressedExplainHandler = async () => {
// Handle console quick explain action.
quickChatService.open({ query: explainPrompt });
};

// Render.
return (
<div className='quick-fix'>
<PositronButton className='assistant-action' onPressed={pressedFixHandler}>
<div ref={buttonRef} className='link-text'>
<span className='codicon codicon-sparkle' />
{localize('positronConsoleAssistantFix', "Fix")}
</div>
</PositronButton>
<PositronButton className='assistant-action' onPressed={pressedExplainHandler}>
<div ref={buttonRef} className='link-text'>
<span className='codicon codicon-sparkle' />
{localize('positronConsoleAssistantExplain', "Explain")}
</div>
</PositronButton>
</div>
);
};