From d223911191573132242f1828ea4f97bcc6feff5a Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 23 Jul 2026 14:52:51 +0200 Subject: [PATCH] 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). --- kate/ollie_kate.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ kate/ollie_kate.h | 2 ++ 2 files changed, 55 insertions(+) diff --git a/kate/ollie_kate.cpp b/kate/ollie_kate.cpp index 03d27f3..1acb7d9 100644 --- a/kate/ollie_kate.cpp +++ b/kate/ollie_kate.cpp @@ -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) diff --git a/kate/ollie_kate.h b/kate/ollie_kate.h index 383281b..85f8726 100644 --- a/kate/ollie_kate.h +++ b/kate/ollie_kate.h @@ -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);