File indexing completed on 2024-05-05 04:39:24
0001 /* 0002 SPDX-FileCopyrightText: 2009 Aleix Pol <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "cmakedocumentation.h" 0008 #include "cmakeutils.h" 0009 0010 #include <QProcess> 0011 #include <QString> 0012 #include <QStringListModel> 0013 #include <QMimeDatabase> 0014 #include <QStandardPaths> 0015 #include <QIcon> 0016 #include <KLocalizedString> 0017 #include <KDescendantsProxyModel> 0018 0019 #include <interfaces/iproject.h> 0020 #include <KPluginFactory> 0021 #include <documentation/standarddocumentationview.h> 0022 #include <language/duchain/declaration.h> 0023 #include <serialization/indexedstring.h> 0024 #include <interfaces/iprojectcontroller.h> 0025 #include <interfaces/icore.h> 0026 0027 #include "cmakemanager.h" 0028 #include "cmakehelpdocumentation.h" 0029 #include "cmakebuilderconfig.h" 0030 #include "cmakedoc.h" 0031 #include "cmakecommandscontents.h" 0032 #include "debug.h" 0033 0034 K_PLUGIN_FACTORY_WITH_JSON(CMakeSupportDocFactory, "kdevcmakedocumentation.json", registerPlugin<CMakeDocumentation>(); ) 0035 0036 CMakeDocumentation* CMakeDoc::s_provider=nullptr; 0037 KDevelop::IDocumentationProvider* CMakeDoc::provider() const { return s_provider; } 0038 0039 CMakeDocumentation::CMakeDocumentation(QObject* parent, const QVariantList&) 0040 : KDevelop::IPlugin( QStringLiteral("kdevcmakedocumentation"), parent ) 0041 , m_index(new CMakeCommandsContents(this)) 0042 , m_flatIndex(new KDescendantsProxyModel(m_index)) 0043 { 0044 m_flatIndex->setSourceModel(m_index); 0045 if (CMakeBuilderSettings::self()->cmakeExecutable().isEmpty()) { 0046 setErrorDescription(i18n("Unable to find a CMake executable. Is one installed on the system?")); 0047 return; 0048 } 0049 0050 CMakeDoc::s_provider=this; 0051 } 0052 0053 QVector<QString> CMakeDocumentation::names(CMakeDocumentation::Type t) const 0054 { 0055 return m_index->names(t); 0056 } 0057 0058 QString CMakeDocumentation::descriptionForIdentifier(const QString& id, Type t) const 0059 { 0060 return m_index->descriptionForIdentifier(id, t); 0061 } 0062 0063 KDevelop::IDocumentation::Ptr CMakeDocumentation::description(const QString& identifier, const QUrl &file) const 0064 { 0065 if (!file.isEmpty() && !QMimeDatabase().mimeTypeForUrl(file).inherits(QStringLiteral("text/x-cmake"))) { 0066 return KDevelop::IDocumentation::Ptr(); 0067 } 0068 0069 0070 Type t = m_index->typeFor(identifier); 0071 QString desc=descriptionForIdentifier(identifier, t); 0072 0073 KDevelop::IProject* p=KDevelop::ICore::self()->projectController()->findProjectForUrl(file); 0074 ICMakeManager* m=nullptr; 0075 if(p) 0076 m=p->managerPlugin()->extension<ICMakeManager>(); 0077 if(m) 0078 { 0079 QPair<QString, QString> entry = m->cacheValue(p, identifier); 0080 if(!entry.first.isEmpty()) 0081 desc += i18n("<br /><em>Cache Value:</em> %1\n", entry.first); 0082 0083 if(!entry.second.isEmpty()) 0084 desc += i18n("<br /><em>Cache Documentation:</em> %1\n", entry.second); 0085 } 0086 0087 if(desc.isEmpty()) 0088 return KDevelop::IDocumentation::Ptr(); 0089 else 0090 return KDevelop::IDocumentation::Ptr(new CMakeDoc(identifier, desc)); 0091 } 0092 0093 KDevelop::IDocumentation::Ptr CMakeDocumentation::documentationForDeclaration(KDevelop::Declaration* decl) const 0094 { 0095 return description(decl->identifier().toString(), decl->url().toUrl()); 0096 } 0097 KDevelop::IDocumentation::Ptr CMakeDocumentation::documentation(const QUrl& /*url*/) const 0098 { 0099 //TODO 0100 return{}; 0101 } 0102 0103 KDevelop::IDocumentation::Ptr CMakeDocumentation::documentationForIndex(const QModelIndex& idx) const 0104 { 0105 return description(idx.data().toString(), QUrl()); 0106 } 0107 0108 QAbstractItemModel* CMakeDocumentation::indexModel() const 0109 { 0110 return m_flatIndex; 0111 } 0112 0113 QIcon CMakeDocumentation::icon() const 0114 { 0115 return QIcon::fromTheme(QStringLiteral("cmake")); 0116 } 0117 0118 QString CMakeDocumentation::name() const 0119 { 0120 return QStringLiteral("CMake"); 0121 } 0122 0123 KDevelop::IDocumentation::Ptr CMakeDocumentation::homePage() const 0124 { 0125 return KDevelop::IDocumentation::Ptr(new CMakeHomeDocumentation); 0126 } 0127 0128 //////////CMakeDoc 0129 0130 QWidget* CMakeDoc::documentationWidget(KDevelop::DocumentationFindWidget* findWidget, QWidget* parent) 0131 { 0132 auto* view = new KDevelop::StandardDocumentationView(findWidget, parent); 0133 view->initZoom(provider()->name()); 0134 view->setHtml(mDesc); 0135 return view; 0136 } 0137 0138 #include "cmakedocumentation.moc" 0139 #include "moc_cmakedoc.cpp" 0140 #include "moc_cmakedocumentation.cpp"