kate: add "Review Diff" context menu via gitplusplus extension

Register an action with the gitplusplus plugin (kate-worktree) that
appears in the Git++ tree view context menu. When triggered, it reads
the computed diff from the gitplusplus lastDiff property and submits
it to the active ollie session for review.

Also adds a "Review Diff" entry to the standard KTextEditor context
menu when the document has Diff highlighting mode (fallback path).
This commit is contained in:
Levi Neely 2026-07-23 14:52:51 +02:00
parent 5ab7a46f4d
commit d223911191
2 changed files with 55 additions and 0 deletions

View File

@ -449,6 +449,9 @@ OllieKateView::OllieKateView(OllieKatePlugin *plugin, KTextEditor::MainWindow *m
// Set up context menu on initial active view
if (auto *view = mainWindow->activeView())
setupContextMenu(view);
// Register "Review Diff" action with Git++ plugin (kate-worktree)
setupGitPlusPlusDiffAction();
}
OllieKateView::~OllieKateView()
@ -948,6 +951,19 @@ void OllieKateView::setupGhostProvider()
}
}
void OllieKateView::setupGitPlusPlusDiffAction()
{
QObject *gitView = m_mainWindow->pluginView(QStringLiteral("gitplusplus"));
if (!gitView) return;
auto *action = new QAction(QIcon::fromTheme(QStringLiteral("document-preview")),
QStringLiteral("Ollie: Review Diff"), this);
connect(action, &QAction::triggered, this, &OllieKateView::reviewDiff);
QMetaObject::invokeMethod(gitView, "registerDiffAction",
Q_ARG(QAction *, action));
}
bool OllieKateView::eventFilter(QObject *obj, QEvent *event)
{
// Reposition scroll-to-bottom button when chat view resizes
@ -1065,6 +1081,14 @@ void OllieKateView::setupContextMenu(KTextEditor::View *view)
askAction->setObjectName(QStringLiteral("ollie_ctx_ask"));
connect(askAction, &QAction::triggered, this, &OllieKateView::askAboutFile);
// "Review Diff" — visible when the document is a diff
if (v->document()->highlightingMode() == QStringLiteral("Diff")) {
auto *reviewDiffAction = menu->addAction(QIcon::fromTheme(QStringLiteral("document-preview")),
QStringLiteral("Ollie: Review Diff"));
reviewDiffAction->setObjectName(QStringLiteral("ollie_ctx_review_diff"));
connect(reviewDiffAction, &QAction::triggered, this, &OllieKateView::reviewDiff);
}
if (!v->selection()) return;
auto *explainAction = menu->addAction(QIcon::fromTheme(QStringLiteral("help-contents")),
@ -1116,6 +1140,35 @@ void OllieKateView::submitSelectionPrompt(const QString &action)
m_iface->call("Submit", m_sessionId, prompt);
}
void OllieKateView::reviewDiff()
{
QString diff;
// Try to get diff from Git++ plugin (kate-worktree)
QObject *gitView = m_mainWindow->pluginView(QStringLiteral("gitplusplus"));
if (gitView) {
QByteArray data = gitView->property("lastDiff").toByteArray();
if (!data.isEmpty())
diff = QString::fromUtf8(data);
}
// Fall back to active document content (e.g. diff opened as plain text)
if (diff.isEmpty()) {
auto *view = m_mainWindow->activeView();
if (view && view->document())
diff = view->document()->text();
}
if (diff.trimmed().isEmpty()) return;
ensureSession();
if (m_sessionId.isEmpty()) return;
QString prompt = QStringLiteral("Review this diff. Point out potential issues, bugs, "
"or improvements:\n\n```diff\n") + diff + QStringLiteral("\n```");
m_iface->call("Submit", m_sessionId, prompt);
}
// --- Apply Code Blocks ---
void OllieKateView::applyCodeBlock(int index)

View File

@ -138,7 +138,9 @@ private:
// --- Editor Integration ---
void setupContextMenu(KTextEditor::View *view);
void setupGitPlusPlusDiffAction();
void submitSelectionPrompt(const QString &action);
void reviewDiff();
void applyCodeBlock(int index);
void clearAnnotations();
void annotateFileReferences(const QString &chatText);