mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 21:09:26 -06:00
Fix Claude Explain view initialization and event handling
- Fix template structure to match framework expectations (no wrapper div) - Use standard toolOpened/toolClosed events instead of custom ones - This fixes automatic compilation trigger on view creation - This enables proper singleton tracking (mostly) - Add getCurrentState with toolId and selection for tool compatibility - Remove unused explainViewOpened/Closed from event map The view now properly integrates with the existing tool infrastructure, triggering compilation when opened and preventing duplicate instances. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,7 @@ export class ExplainTool extends BaseTool {
|
||||
}
|
||||
|
||||
// Return a minimal result with the API endpoint as custom data
|
||||
// TODO stop casting this and do something better.
|
||||
return {
|
||||
id: this.tool.id,
|
||||
name: this.tool.name,
|
||||
|
||||
@@ -141,8 +141,6 @@ export type EventMap = {
|
||||
ppViewClosed: (compilerId: number) => void;
|
||||
ppViewOpened: (compilerId: number) => void;
|
||||
ppViewOptionsUpdated: (compilerId: number, options: PPOptions, recompile: boolean) => void;
|
||||
explainViewClosed: (compilerId: number) => void;
|
||||
explainViewOpened: (compilerId: number) => void;
|
||||
renamePane: () => void;
|
||||
requestCompilation: (editorId: number | boolean, treeId: boolean | number) => void;
|
||||
requestMotd: () => void;
|
||||
|
||||
@@ -91,8 +91,8 @@ export class ExplainHtmlView extends Pane<PaneState> {
|
||||
this.contentElement.text('Waiting for compilation...');
|
||||
this.isAwaitingInitialResults = true;
|
||||
|
||||
// Emit singleton opened event
|
||||
this.eventHub.emit('explainViewOpened', this.compilerInfo.compilerId);
|
||||
// Emit standard tool opened event
|
||||
this.eventHub.emit('toolOpened', this.compilerInfo.compilerId, this.getCurrentState());
|
||||
}
|
||||
|
||||
override getInitialHTML(): string {
|
||||
@@ -275,8 +275,17 @@ export class ExplainHtmlView extends Pane<PaneState> {
|
||||
return 'Claude Explain';
|
||||
}
|
||||
|
||||
override getCurrentState() {
|
||||
const state = super.getCurrentState();
|
||||
return {
|
||||
...state,
|
||||
toolId: 'explain',
|
||||
selection: undefined, // Required for NewToolSettings type but we don't have a Monaco editor
|
||||
};
|
||||
}
|
||||
|
||||
override close(): void {
|
||||
this.eventHub.emit('explainViewClosed', this.compilerInfo.compilerId);
|
||||
this.eventHub.emit('toolClosed', this.compilerInfo.compilerId, this.getCurrentState());
|
||||
this.eventHub.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#explain-view
|
||||
.explain-container.d-flex.flex-column.h-100
|
||||
.top-bar.btn-toolbar.options-toolbar.bg-light.flex-shrink-0(role="toolbar")
|
||||
include ../../font-size
|
||||
.status.ms-auto.explain-loading.d-none
|
||||
i.fas.fa-circle-notch.fa-spin.me-2
|
||||
span Generating explanation...
|
||||
.explain-consent.d-none.flex-shrink-0
|
||||
p.mb-0 Claude Explain will send your code and compilation output to an external API. Continue?
|
||||
button.btn.btn-primary.mt-2.consent-btn Yes, explain this code
|
||||
.explain-content.content.markdown-body.flex-grow-1.overflow-auto
|
||||
.bottom-bar.bg-light.d-none.explain-bottom-bar.flex-shrink-0.px-3.d-flex
|
||||
span.explain-stats.ms-auto
|
||||
#explain
|
||||
.top-bar.btn-toolbar.options-toolbar.bg-light.flex-shrink-0(role="toolbar")
|
||||
include ../../font-size
|
||||
.status.ms-auto.explain-loading.d-none
|
||||
i.fas.fa-circle-notch.fa-spin.me-2
|
||||
span Generating explanation...
|
||||
.explain-consent.d-none.flex-shrink-0
|
||||
p.mb-0 Claude Explain will send your code and compilation output to an external API. Continue?
|
||||
button.btn.btn-primary.mt-2.consent-btn Yes, explain this code
|
||||
.explain-content.content.markdown-body.flex-grow-1.overflow-auto
|
||||
.bottom-bar.bg-light.d-none.explain-bottom-bar.flex-shrink-0.px-3.d-flex
|
||||
span.explain-stats.ms-auto
|
||||
Reference in New Issue
Block a user