Skip to content

Commit 8107e27

Browse files
committed
Updates explain changes in Inspect view
1 parent 6ecc42a commit 8107e27

File tree

3 files changed

+46
-73
lines changed

3 files changed

+46
-73
lines changed

src/webviews/apps/commitDetails/components/gl-commit-details.ts

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,37 @@ export class GlCommitDetails extends GlDetailsBase {
151151
></commit-identity>
152152
`,
153153
)}
154-
<div class="message-block">
154+
<div>
155+
<div class="message-block">
156+
${when(
157+
index === -1,
158+
() =>
159+
html`<p class="message-block__text scrollable" data-region="message">
160+
<strong>${unsafeHTML(message)}</strong>
161+
</p>`,
162+
() =>
163+
html`<p class="message-block__text scrollable" data-region="message">
164+
<strong>${unsafeHTML(message.substring(0, index))}</strong><br /><span
165+
>${unsafeHTML(message.substring(index + 3))}</span
166+
>
167+
</p>`,
168+
)}
169+
</div>
155170
${when(
156-
index === -1,
157-
() =>
158-
html`<p class="message-block__text scrollable" data-region="message">
159-
<strong>${unsafeHTML(message)}</strong>
160-
</p>`,
161-
() =>
162-
html`<p class="message-block__text scrollable" data-region="message">
163-
<strong>${unsafeHTML(message.substring(0, index))}</strong><br /><span
164-
>${unsafeHTML(message.substring(index + 3))}</span
165-
>
166-
</p>`,
171+
this.state?.orgSettings.ai !== false,
172+
() => html`
173+
<div class="message-block-actions">
174+
<action-item
175+
label="Explain this ${this.isStash ? 'Stash' : 'Commit'}"
176+
icon="sparkle"
177+
data-action="explain-commit"
178+
aria-busy="${this.explainBusy ? 'true' : nothing}"
179+
?disabled="${this.explainBusy ? true : nothing}"
180+
@click=${this.onExplainChanges}
181+
@keydown=${this.onExplainChanges}
182+
></action-item>
183+
</div>
184+
`,
167185
)}
168186
</div>
169187
</div>
@@ -429,59 +447,6 @@ export class GlCommitDetails extends GlDetailsBase {
429447
`;
430448
}
431449

432-
private renderExplainAi() {
433-
if (this.state?.orgSettings.ai === false) return undefined;
434-
435-
const markdown =
436-
this.explain?.result != null ? `${this.explain.result.summary}\n\n${this.explain.result.body}` : undefined;
437-
438-
// TODO: add loading and response states
439-
return html`
440-
<webview-pane collapsable data-region="explain-pane">
441-
<span slot="title">Explain (AI)</span>
442-
<action-nav slot="actions">
443-
<action-item
444-
data-action="switch-ai"
445-
label="Switch AI Provider/Model"
446-
icon="arrow-swap"
447-
></action-item>
448-
</action-nav>
449-
450-
<div class="section">
451-
<p>Let AI assist in understanding the changes made with this commit.</p>
452-
<p class="button-container">
453-
<span class="button-group button-group--single">
454-
<gl-button
455-
full
456-
class="button--busy"
457-
data-action="explain-commit"
458-
aria-busy="${this.explainBusy ? 'true' : nothing}"
459-
@click=${this.onExplainChanges}
460-
@keydown=${this.onExplainChanges}
461-
><code-icon icon="loading" modifier="spin" slot="prefix"></code-icon>Explain
462-
Changes</gl-button
463-
>
464-
</span>
465-
</p>
466-
${markdown
467-
? html`<div class="ai-content" data-region="commit-explanation">
468-
<gl-markdown
469-
class="ai-content__summary scrollable"
470-
markdown="${markdown}"
471-
></gl-markdown>
472-
</div>`
473-
: this.explain?.error
474-
? html`<div class="ai-content has-error" data-region="commit-explanation">
475-
<p class="ai-content__summary scrollable">
476-
${this.explain.error.message ?? 'Error retrieving content'}
477-
</p>
478-
</div>`
479-
: undefined}
480-
</div>
481-
</webview-pane>
482-
`;
483-
}
484-
485450
override render(): unknown {
486451
if (this.state?.commit == null) {
487452
return this.renderEmptyContent();
@@ -495,7 +460,6 @@ export class GlCommitDetails extends GlDetailsBase {
495460
this.isStash ? 'stash' : 'commit',
496461
this.renderCommitStats(this.state.commit.stats),
497462
)}
498-
${this.renderExplainAi()}
499463
</webview-pane-group>
500464
`;
501465
}

src/webviews/apps/shared/styles/details-base.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ ul {
166166
}
167167
}
168168

169+
.message-block-actions {
170+
background: var(--color-background--level-075);
171+
display: flex;
172+
flex-direction: row;
173+
justify-content: flex-end;
174+
gap: 0.5rem;
175+
border-radius: 0 0 2px 2px;
176+
}
177+
169178
.commit-detail-panel {
170179
max-height: 100vh;
171180
overflow: auto;

src/webviews/commitDetails/commitDetailsWebview.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,14 +1126,14 @@ export class CommitDetailsWebviewProvider
11261126
private async explainRequest<T extends typeof ExplainRequest>(requestType: T, msg: IpcCallMessageType<T>) {
11271127
let params: DidExplainParams;
11281128
try {
1129-
const result = await this.container.ai.explainCommit(
1130-
this._context.commit!,
1131-
{ source: 'inspect', type: isStash(this._context.commit) ? 'stash' : 'commit' },
1132-
{ progress: { location: { viewId: this.host.id } } },
1133-
);
1134-
if (result == null) throw new Error('Error retrieving content');
1129+
const isStashCommit = isStash(this._context.commit);
1130+
await executeCommand(isStashCommit ? 'gitlens.ai.explainStash' : 'gitlens.ai.explainCommit', {
1131+
repoPath: this._context.commit!.repoPath,
1132+
ref: this._context.commit!.sha,
1133+
source: { source: 'inspect', type: isStashCommit ? 'stash' : 'commit' },
1134+
});
11351135

1136-
params = { result: result?.parsed };
1136+
params = { result: { summary: '', body: '' } };
11371137
} catch (ex) {
11381138
debugger;
11391139
params = { error: { message: ex.message } };

0 commit comments

Comments
 (0)