| 247 | } |
| 248 | |
| 249 | KDevelop::ContextMenuExtension ProblemReporterPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 250 | { |
| 251 | KDevelop::ContextMenuExtension extension; |
| 252 | |
| 253 | auto* editorContext = dynamic_cast<KDevelop::EditorContext*>(context); |
| 254 | if (editorContext) { |
| 255 | DUChainReadLocker lock(DUChain::lock(), 1000); |
| 256 | if (!lock.locked()) { |
| 257 | qCDebug(PLUGIN_PROBLEMREPORTER) << "failed to lock duchain in time"; |
| 258 | return extension; |
| 259 | } |
| 260 | |
| 261 | QString title; |
| 262 | QList<QAction*> actions; |
| 263 | |
| 264 | TopDUContext* top = DUChainUtils::standardContextForUrl(editorContext->url()); |
| 265 | if (top) { |
| 266 | const auto problems = top->problems(); |
| 267 | for (auto& problem : problems) { |
| 268 | if (problem->range().contains( |
| 269 | top->transformToLocalRevision(KTextEditor::Cursor(editorContext->position())))) { |
| 270 | KDevelop::IAssistant::Ptr solution = problem->solutionAssistant(); |
| 271 | if (solution) { |
| 272 | title = solution->title(); |
| 273 | const auto solutionActions = solution->actions(); |
| 274 | for (auto& action : solutionActions) { |
| 275 | actions << action->toQAction(parent); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (!actions.isEmpty()) { |
| 283 | QString text; |
| 284 | if (title.isEmpty()) |
| 285 | text = i18nc("@action:inmenu", "Solve Problem"); |
| 286 | else { |
| 287 | text = i18nc("@action:inmenu", "Solve: %1", KDevelop::htmlToPlainText(title)); |
| 288 | } |
| 289 | |
| 290 | auto* menu = new QMenu(text, parent); |
| 291 | for (QAction* action : std::as_const(actions)) { |
| 292 | menu->addAction(action); |
| 293 | } |
| 294 | |
| 295 | extension.addAction(ContextMenuExtension::ExtensionGroup, menu->menuAction()); |
| 296 | } |
| 297 | } |
| 298 | return extension; |
| 299 | } |
| 300 | |
| 301 | void ProblemReporterPlugin::updateOpenedDocumentsHighlight() |
| 302 | { |
nothing calls this directly
no test coverage detected