diff --git a/documentation/manpage/manpageplugin.cpp b/documentation/manpage/manpageplugin.cpp index e8d886808c..aa1efdb9cc 100644 --- a/documentation/manpage/manpageplugin.cpp +++ b/documentation/manpage/manpageplugin.cpp @@ -1,135 +1,158 @@ /* This file is part of KDevelop Copyright 2010 Yannick Motta Copyright 2010 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "manpageplugin.h" #include "manpagedocumentation.h" #include "manpagemodel.h" using namespace KDevelop; K_PLUGIN_FACTORY_WITH_JSON(ManPageFactory, "kdevmanpage.json", registerPlugin(); ) ManPagePlugin::ManPagePlugin(QObject* parent, const QVariantList& args) : IPlugin("kdevmanpage", parent) { KDEV_USE_EXTENSION_INTERFACE( IDocumentationProvider ) Q_UNUSED(args); ManPageDocumentation::s_provider = this; m_model = new ManPageModel(this); } ManPagePlugin::~ManPagePlugin() { delete m_model; } QString ManPagePlugin::name() const { return QString(i18n("Man Page")); } QIcon ManPagePlugin::icon() const { static QIcon icon = QIcon::fromTheme("x-office-address-book"); return icon; } ManPageModel* ManPagePlugin::model() const{ return m_model; } IDocumentation::Ptr ManPagePlugin::documentationForDeclaration( Declaration* dec ) const { Q_ASSERT(dec); Q_ASSERT(dec->topContext()); Q_ASSERT(dec->topContext()->parsingEnvironmentFile()); static const IndexedString cppLanguage("C++"); // TODO remove because of new clang parser? static const IndexedString clangLanguage("Clang"); const IndexedString declarationLanguage(dec->topContext()->parsingEnvironmentFile()->language()); if (declarationLanguage != cppLanguage && declarationLanguage != clangLanguage) return {}; // Don't show man-page documentation for files that are part of our project - if(core()->projectController()->findProjectForUrl(dec->topContext()->url().toUrl())) + if (core()->projectController()->findProjectForUrl(dec->topContext()->url().toUrl())) return {}; // Don't show man-page documentation for files that are not in /usr/include, because then we // most probably will be confusing the global function-name with a local one - if(!dec->topContext()->url().str().startsWith("/usr/")) + if (!dec->topContext()->url().str().startsWith("/usr/")) return {}; - + ///@todo Do more verification to make sure that we're showing the correct documentation for the declaration - QString identifier = dec->identifier().toString(); - if(m_model->containsIdentifier(identifier)){ + QString identifier; + IDocumentation::Ptr result; + + // First, try to find help for qualified identifier like 'std::vector' + { DUChainReadLocker lock; - QualifiedIdentifier qid = dec->qualifiedIdentifier(); - if(qid.count() == 1){ - if(m_model->identifierInSection(identifier, "3")){ - return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:(3)/"+identifier))); - } else if(m_model->identifierInSection(identifier, "2")){ - return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:(2)/"+identifier))); - } else { - return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:"+identifier))); - } - } + identifier = dec->qualifiedIdentifier().toString(RemoveTemplateInformation); } - return {}; + + result = documentationForIdentifier(identifier); + if (result.data()) + return result; + + // Second, try to find help for simple identifier like 'sin' + { + DUChainReadLocker lock; + identifier = dec->identifier().toString(RemoveTemplateInformation); + } + + result = documentationForIdentifier(identifier); + if (result.data()) + return result; + + return {}; +} + +KDevelop::IDocumentation::Ptr ManPagePlugin::documentationForIdentifier(const QString& identifier) const +{ + if (!m_model->containsIdentifier(identifier)) + return KDevelop::IDocumentation::Ptr(nullptr); + + if (m_model->identifierInSection(identifier, "3")) + return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:(3)/" + identifier))); + + if (m_model->identifierInSection(identifier, "2")) + return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:(2)/" + identifier))); + + return IDocumentation::Ptr(new ManPageDocumentation(identifier, QUrl("man:/" + identifier))); } QAbstractListModel* ManPagePlugin::indexModel() const { return m_model->indexList(); } IDocumentation::Ptr ManPagePlugin::documentationForIndex(const QModelIndex& index) const { QString name = index.data().toString(); return IDocumentation::Ptr(new ManPageDocumentation(name, QUrl("man:"+name))); } IDocumentation::Ptr ManPagePlugin::homePage() const { return IDocumentation::Ptr(new ManPageHomeDocumentation); } #include "manpageplugin.moc" diff --git a/documentation/manpage/manpageplugin.h b/documentation/manpage/manpageplugin.h index b97cab272d..f7fae41490 100644 --- a/documentation/manpage/manpageplugin.h +++ b/documentation/manpage/manpageplugin.h @@ -1,59 +1,61 @@ /* This file is part of KDevelop Copyright 2010 Yannick Motta Copyright 2010 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MANPAGEPLUGIN_H #define MANPAGEPLUGIN_H #include "manpagemodel.h" #include #include #include #include class ManPageDocumentation; class ManPagePlugin : public KDevelop::IPlugin, public KDevelop::IDocumentationProvider { Q_OBJECT Q_INTERFACES( KDevelop::IDocumentationProvider ) public: ManPagePlugin(QObject *parent, const QVariantList & args= QVariantList()); ~ManPagePlugin() override; KDevelop::IDocumentation::Ptr documentationForDeclaration (KDevelop::Declaration* dec) const override; QAbstractListModel* indexModel() const override; KDevelop::IDocumentation::Ptr documentationForIndex(const QModelIndex& index) const override; QIcon icon() const override; QString name() const override; KDevelop::IDocumentation::Ptr homePage() const override; void deleteProgressBar(); ManPageModel* model() const; QProgressBar* progressBar() const; signals: void addHistory(const KDevelop::IDocumentation::Ptr& doc ) const override; private: + KDevelop::IDocumentation::Ptr documentationForIdentifier(const QString& identifier) const; + ManPageModel *m_model; }; #endif // MANPAGEPLUGIN_H diff --git a/documentation/qthelp/qthelpproviderabstract.cpp b/documentation/qthelp/qthelpproviderabstract.cpp index 7f67fa47d7..2d42cb99d3 100644 --- a/documentation/qthelp/qthelpproviderabstract.cpp +++ b/documentation/qthelp/qthelpproviderabstract.cpp @@ -1,117 +1,111 @@ /* This file is part of KDevelop Copyright 2009 Aleix Pol Copyright 2009 David Nolden Copyright 2010 Benjamin Port This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "qthelpprovider.h" #include #include #include #include #include #include #include #include #include "qthelpdocumentation.h" #include "debug.h" using namespace KDevelop; QtHelpProviderAbstract::QtHelpProviderAbstract(QObject *parent, const QString &collectionFileName, const QVariantList &args) : QObject(parent) , m_engine(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+'/'+collectionFileName) { Q_UNUSED(args); if( !m_engine.setupData() ) { qWarning() << "Couldn't setup QtHelp Collection file"; } } QtHelpProviderAbstract::~QtHelpProviderAbstract() { } IDocumentation::Ptr QtHelpProviderAbstract::documentationForDeclaration(Declaration* dec) const { QtHelpDocumentation::s_provider = const_cast(this); - if(dec) { + if (dec) { static const IndexedString qmlJs("QML/JS"); - bool isQML; - QStringList idParts; + QString id; { DUChainReadLocker lock; - isQML = dec->topContext()->parsingEnvironmentFile()->language() == qmlJs; - idParts = dec->qualifiedIdentifier().toStringList(); - } - - QString id; - if(isQML && !idParts.isEmpty()) { - id = QLatin1String("QML."); + id = dec->qualifiedIdentifier().toString(RemoveTemplateInformation); + if (dec->topContext()->parsingEnvironmentFile()->language() == qmlJs && !id.isEmpty()) + id = QLatin1String("QML.") + id; } - if(!idParts.isEmpty()) { - id += idParts.join(QLatin1String("::")); - QMap links=m_engine.linksForIdentifier(id); + if (!id.isEmpty()) { + QMap links = m_engine.linksForIdentifier(id); if(!links.isEmpty()) return IDocumentation::Ptr(new QtHelpDocumentation(id, links)); } } return {}; } QAbstractListModel* QtHelpProviderAbstract::indexModel() const { QtHelpDocumentation::s_provider = const_cast(this); return m_engine.indexModel(); } IDocumentation::Ptr QtHelpProviderAbstract::documentationForIndex(const QModelIndex& idx) const { QtHelpDocumentation::s_provider = const_cast(this); QString name=idx.data(Qt::DisplayRole).toString(); return IDocumentation::Ptr(new QtHelpDocumentation(name, m_engine.indexModel()->linksForKeyword(name))); } void QtHelpProviderAbstract::jumpedTo(const QUrl& newUrl) const { QtHelpDocumentation::s_provider = const_cast(this); QMap info; info.insert(newUrl.toString(), newUrl); IDocumentation::Ptr doc(new QtHelpDocumentation(newUrl.toString(), info)); emit addHistory(doc); } IDocumentation::Ptr QtHelpProviderAbstract::homePage() const { QtHelpDocumentation::s_provider = const_cast(this); return IDocumentation::Ptr(new HomeDocumentation); } bool QtHelpProviderAbstract::isValid() const { return !m_engine.registeredDocumentations().isEmpty(); }