Warning, file /kdevelop/kdev-python/duchain/assistants/missingincludeassistant.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2013 Sven Brauch <svenbrauch@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "missingincludeassistant.h"
0008 #include <docfilekcm/docfilewizard.h>
0009 #include <interfaces/icore.h>
0010 #include <interfaces/idocumentcontroller.h>
0011 #include <interfaces/ilanguagecontroller.h>
0012 #include <language/backgroundparser/backgroundparser.h>
0013 
0014 #include <iostream>
0015 
0016 #include <QDebug>
0017 #include <QStandardPaths>
0018 #include <duchaindebug.h>
0019 
0020 
0021 #include <KLocalizedString>
0022 
0023 using namespace KDevelop;
0024 
0025 namespace Python {
0026 
0027 MissingIncludeProblem::MissingIncludeProblem(const QString &moduleName, IndexedString currentDocument)
0028     : Problem()
0029     , m_moduleName(moduleName)
0030     , m_currentDocument(currentDocument)
0031 {
0032 
0033 }
0034 
0035 QExplicitlySharedDataPointer<IAssistant> MissingIncludeProblem::solutionAssistant() const
0036 {
0037     return QExplicitlySharedDataPointer<IAssistant>(new MissingIncludeAssistant(m_moduleName, m_currentDocument));
0038 }
0039 
0040 DocumentationGeneratorAction::DocumentationGeneratorAction(const QString& module, const IndexedString& document)
0041     : IAssistantAction()
0042     , module(module)
0043     , document(document)
0044 {
0045 
0046 }
0047 
0048 QString DocumentationGeneratorAction::description() const
0049 {
0050     return i18n("Generate documentation for module \"%1\"...", module);
0051 }
0052 
0053 void DocumentationGeneratorAction::execute()
0054 {
0055     // yes, it's duplicate from the doc file widget, but it's too painful to share it
0056     QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/" + "kdevpythonsupport/documentation_files/";
0057     QDir dir(path);
0058     dir.mkpath(path);
0059     auto wizard = new DocfileWizard(path);
0060     wizard->setModuleName(module);
0061     wizard->setModal(true);
0062     wizard->setAttribute(Qt::WA_DeleteOnClose);
0063     wizard->show();
0064     QObject::connect(wizard, &QDialog::accepted,
0065         [wizard, this]() {
0066             if ( ! wizard->wasSavedAs().isNull() ) {
0067                 ICore::self()->documentController()->openDocument(QUrl::fromLocalFile(wizard->wasSavedAs()));
0068                 // force a recursive update of the context, so that all the imports are reparsed too
0069                 // (since they potentially have changed through this action)
0070                 ICore::self()->languageController()->backgroundParser()->addDocument(document, TopDUContext::ForceUpdateRecursive);
0071             }
0072         }
0073     );
0074 
0075     emit executed(this);
0076 }
0077 
0078 void MissingIncludeAssistant::createActions()
0079 {
0080     QExplicitlySharedDataPointer<IAssistantAction> action(new DocumentationGeneratorAction(module, document));
0081     addAction(action);
0082 }
0083 
0084 MissingIncludeAssistant::MissingIncludeAssistant(const QString& module, const IndexedString& document)
0085     : IAssistant()
0086     , module(module)
0087     , document(document)
0088 {
0089 }
0090 
0091 }
0092 
0093 #include "moc_missingincludeassistant.cpp"