File indexing completed on 2024-05-12 04:37:44

0001 /*
0002     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_CODECOMPLETION_H
0008 #define KDEVPLATFORM_CODECOMPLETION_H
0009 
0010 #include <QObject>
0011 #include <language/languageexport.h>
0012 
0013 namespace KTextEditor {
0014 class Document; class View; class CodeCompletionModel;
0015 }
0016 
0017 namespace KDevelop {
0018 class IDocument;
0019 class ILanguage;
0020 
0021 // TODO: cleanup this class for 5.1
0022 class KDEVPLATFORMLANGUAGE_EXPORT CodeCompletion
0023     : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     /** CodeCompletion will be the @p aModel parent.
0029      *  If @p language is empty, the completion model will work for all files,
0030      *  otherwise only for ones that contain the selected language.
0031      */
0032     CodeCompletion(QObject* parent, KTextEditor::CodeCompletionModel* aModel, const QString& language);
0033     ~CodeCompletion() override;
0034 
0035 private Q_SLOTS:
0036     void textDocumentCreated(KDevelop::IDocument*);
0037     void viewCreated(KTextEditor::Document* document, KTextEditor::View* view);
0038     void documentUrlChanged(KDevelop::IDocument*);
0039 
0040     /**
0041      * check already opened documents,
0042      * needs to be done via delayed call to prevent infinite loop in
0043      * checkDocument() -> load lang plugin -> register CodeCompletion -> checkDocument() -> ...
0044      */
0045     void checkDocuments();
0046 
0047 Q_SIGNALS:
0048     void registeredToView(KTextEditor::View* view);
0049     void unregisteredFromView(KTextEditor::View* view);
0050 
0051 private:
0052 
0053     void unregisterDocument(KTextEditor::Document*);
0054     void checkDocument(KTextEditor::Document*);
0055 
0056     KTextEditor::CodeCompletionModel* m_model;
0057     QString m_language;
0058 };
0059 }
0060 
0061 #endif