| 59 | } |
| 60 | |
| 61 | void CodeUtilsPlugin::documentDeclaration() |
| 62 | { |
| 63 | View* view = ICore::self()->documentController()->activeTextDocumentView(); |
| 64 | if ( !view ) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | DUChainReadLocker lock; |
| 69 | TopDUContext* topCtx = DUChainUtils::standardContextForUrl(view->document()->url()); |
| 70 | if ( !topCtx ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | Declaration* dec = DUChainUtils::declarationInLine( KTextEditor::Cursor( view->cursorPosition() ), |
| 75 | topCtx ); |
| 76 | if ( !dec || dec->isForwardDeclaration() ) { |
| 77 | return; |
| 78 | } |
| 79 | // finally - we found the declaration :) |
| 80 | int line = dec->range().start.line; |
| 81 | Cursor insertPos( line, 0 ); |
| 82 | |
| 83 | TemplateRenderer renderer; |
| 84 | renderer.setEmptyLinesPolicy(TemplateRenderer::TrimEmptyLines); |
| 85 | renderer.addVariable(QStringLiteral("brief"), i18n( "..." )); |
| 86 | |
| 87 | /* |
| 88 | QString indentation = textDoc->line( insertPos.line() ); |
| 89 | if (!indentation.isEmpty()) { |
| 90 | int lastSpace = 0; |
| 91 | while (indentation.at(lastSpace).isSpace()) { |
| 92 | ++lastSpace; |
| 93 | } |
| 94 | indentation.truncate(lastSpace); |
| 95 | } |
| 96 | */ |
| 97 | |
| 98 | if (dec->isFunctionDeclaration()) |
| 99 | { |
| 100 | FunctionDescription description = FunctionDescription(DeclarationPointer(dec)); |
| 101 | renderer.addVariable(QStringLiteral("function"), QVariant::fromValue(description)); |
| 102 | qCDebug(PLUGIN_CODEUTILS) << "Found function" << description.name << "with" << description.arguments.size() << "arguments"; |
| 103 | } |
| 104 | |
| 105 | lock.unlock(); |
| 106 | |
| 107 | // TODO: Choose the template based on the language |
| 108 | QLatin1String templateName = QLatin1String("doxygen_cpp"); |
| 109 | auto languages = core()->languageController()->languagesForUrl(view->document()->url()); |
| 110 | if (!languages.isEmpty()) |
| 111 | { |
| 112 | QString languageName = languages.first()->name(); |
| 113 | if (languageName == QLatin1String("Php")) |
| 114 | { |
| 115 | templateName = QLatin1String("phpdoc_php"); |
| 116 | } |
| 117 | else if (languageName == QLatin1String("Python")) |
| 118 | { |
nothing calls this directly
no test coverage detected