File indexing completed on 2024-05-12 04:37:45
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Hamish Rodda <rodda@kde.org> 0003 SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_CODECOMPLETIONWORKER_H 0009 #define KDEVPLATFORM_CODECOMPLETIONWORKER_H 0010 0011 #include <QList> 0012 0013 #include <language/languageexport.h> 0014 #include "../duchain/duchainpointer.h" 0015 #include "../codecompletion/codecompletioncontext.h" 0016 0017 class QMutex; 0018 0019 namespace KTextEditor { 0020 class Range; 0021 class View; 0022 class Cursor; 0023 } 0024 0025 namespace KDevelop { 0026 class CompletionTreeElement; 0027 class CodeCompletionModel; 0028 0029 class KDEVPLATFORMLANGUAGE_EXPORT CodeCompletionWorker 0030 : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit CodeCompletionWorker(CodeCompletionModel* model); 0036 ~CodeCompletionWorker() override; 0037 0038 virtual void abortCurrentCompletion(); 0039 0040 void setFullCompletion(bool); 0041 bool fullCompletion() const; 0042 0043 KDevelop::CodeCompletionModel* model() const; 0044 0045 ///When this is called, the result is shown in the completion-list. 0046 ///Call this from within your code 0047 void foundDeclarations(const QList<QExplicitlySharedDataPointer<CompletionTreeElement>>&, 0048 const CodeCompletionContext::Ptr& completionContext); 0049 0050 Q_SIGNALS: 0051 0052 ///Internal connections into the foreground completion model 0053 void foundDeclarationsReal(const QList<QExplicitlySharedDataPointer<CompletionTreeElement>>&, 0054 const QExplicitlySharedDataPointer<CodeCompletionContext>& completionContext); 0055 0056 protected: 0057 0058 virtual void computeCompletions(const DUContextPointer& context, const KTextEditor::Cursor& position, 0059 const QString& followingText, const KTextEditor::Range& contextRange, 0060 const QString& contextText); 0061 ///This can be overridden to compute an own grouping in the completion-list. 0062 ///The default implementation groups items in a way that improves the efficiency of the completion-model, thus the default-implementation should be preferred. 0063 virtual QList<QExplicitlySharedDataPointer<CompletionTreeElement>> computeGroups( 0064 const QList<CompletionTreeItemPointer>& items, 0065 const QExplicitlySharedDataPointer<CodeCompletionContext>& completionContext); 0066 ///If you don't need to reimplement computeCompletions, you can implement only this. 0067 virtual KDevelop::CodeCompletionContext* createCompletionContext(const KDevelop::DUContextPointer& context, 0068 const QString& contextText, 0069 const QString& followingText, 0070 const CursorInRevision& position) const; 0071 0072 ///Override this to change the text-range which is used as context-information for the completion context 0073 ///The foreground-lock and a DUChain read lock are held when this is called 0074 virtual void updateContextRange(KTextEditor::Range& contextRange, KTextEditor::View* view, 0075 const DUContextPointer& context) const; 0076 0077 ///Can be used to retrieve and set the aborting flag(Enabling it is equivalent to calling abortCompletion()) 0078 ///Is always reset from within computeCompletions 0079 bool& aborting(); 0080 0081 ///Emits foundDeclarations() with an empty list. Always call this when you abort the process of computing completions 0082 void failed(); 0083 0084 public Q_SLOTS: 0085 ///Connection from the foreground thread within CodeCompletionModel 0086 void computeCompletions(const KDevelop::DUContextPointer& context, const KTextEditor::Cursor& position, 0087 KTextEditor::View* view); 0088 ///This can be used to do special processing within the background, completely bypassing the normal computeCompletions(..) etc. system. 0089 ///It will be executed within the background when the model emits doSpecialProcessingInBackground 0090 virtual void doSpecialProcessing(uint data); 0091 0092 private: 0093 bool m_hasFoundDeclarations; 0094 QMutex* m_mutex; 0095 bool m_abort; 0096 bool m_fullCompletion; 0097 KDevelop::CodeCompletionModel* m_model; 0098 }; 0099 } 0100 0101 #endif // KDEVPLATFORM_CODECOMPLETIONWORKER_H