File: codecompletionworker.h

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (116 lines) | stat: -rw-r--r-- 4,956 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * KDevelop Generic Code Completion Support
 *
 * Copyright 2006-2008 Hamish Rodda <rodda@kde.org>
 * Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
 *
 * This program 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 program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef KDEVPLATFORM_CODECOMPLETIONWORKER_H
#define KDEVPLATFORM_CODECOMPLETIONWORKER_H

#include <QList>

#include <language/languageexport.h>
#include "../duchain/duchainpointer.h"
#include "../codecompletion/codecompletioncontext.h"

class QMutex;

namespace KTextEditor {
class Range;
class View;
class Cursor;
}

namespace KDevelop {
class CompletionTreeElement;
class CodeCompletionModel;

class KDEVPLATFORMLANGUAGE_EXPORT CodeCompletionWorker
    : public QObject
{
    Q_OBJECT

public:
    explicit CodeCompletionWorker(CodeCompletionModel* model);
    ~CodeCompletionWorker() override;

    virtual void abortCurrentCompletion();

    void setFullCompletion(bool);
    bool fullCompletion() const;

    KDevelop::CodeCompletionModel* model() const;

    ///When this is called, the result is shown in the completion-list.
    ///Call this from within your code
    void foundDeclarations(const QList<QExplicitlySharedDataPointer<CompletionTreeElement>>&,
                           const CodeCompletionContext::Ptr& completionContext);

Q_SIGNALS:

    ///Internal connections into the foreground completion model
    void foundDeclarationsReal(const QList<QExplicitlySharedDataPointer<CompletionTreeElement>>&,
                               const QExplicitlySharedDataPointer<CodeCompletionContext>& completionContext);

protected:

    virtual void computeCompletions(const DUContextPointer& context, const KTextEditor::Cursor& position,
                                    const QString& followingText, const KTextEditor::Range& contextRange,
                                    const QString& contextText);
    ///This can be overridden to compute an own grouping in the completion-list.
    ///The default implementation groups items in a way that improves the efficiency of the completion-model, thus the default-implementation should be preferred.
    virtual QList<QExplicitlySharedDataPointer<CompletionTreeElement>> computeGroups(
        const QList<CompletionTreeItemPointer>& items,
        const QExplicitlySharedDataPointer<CodeCompletionContext>& completionContext);
    ///If you don't need to reimplement computeCompletions, you can implement only this.
    virtual KDevelop::CodeCompletionContext* createCompletionContext(const KDevelop::DUContextPointer& context,
                                                                     const QString& contextText,
                                                                     const QString& followingText,
                                                                     const CursorInRevision& position) const;

    ///Override this to change the text-range which is used as context-information for the completion context
    ///The foreground-lock and a DUChain read lock are held when this is called
    virtual void updateContextRange(KTextEditor::Range& contextRange, KTextEditor::View* view,
                                    const DUContextPointer& context) const;

    ///Can be used to retrieve and set the aborting flag(Enabling it is equivalent to calling abortCompletion())
    ///Is always reset from within computeCompletions
    bool& aborting();

    ///Emits foundDeclarations() with an empty list. Always call this when you abort the process of computing completions
    void failed();

public Q_SLOTS:
    ///Connection from the foreground thread within CodeCompletionModel
    void computeCompletions(const KDevelop::DUContextPointer& context, const KTextEditor::Cursor& position,
                            KTextEditor::View* view);
    ///This can be used to do special processing within the background, completely bypassing the normal computeCompletions(..) etc. system.
    ///It will be executed within the background when the model emits doSpecialProcessingInBackground
    virtual void doSpecialProcessing(uint data);

private:
    bool m_hasFoundDeclarations;
    QMutex* m_mutex;
    bool m_abort;
    bool m_fullCompletion;
    KDevelop::CodeCompletionModel* m_model;
};
}

#endif // KDEVPLATFORM_CODECOMPLETIONWORKER_H