File: staticassistant.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 (103 lines) | stat: -rw-r--r-- 3,427 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
/*
 * Copyright 2014 Kevin Funk <kfunk@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef KDEVPLATFORM_STATICASSISTANT_H
#define KDEVPLATFORM_STATICASSISTANT_H

#include <language/languageexport.h>
#include <serialization/indexedstring.h>
#include <language/duchain/topducontext.h>

#include <interfaces/iassistant.h>

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

namespace KDevelop {
class ILanguageSupport;
class StaticAssistantPrivate;

/**
 * @brief This class serves as a base for long-living assistants
 *
 * Normally, an assistant only lives for a short time, and is indirectly owned by a KDevelop::Problem.
 * Static assistants are owned by the language support plugins and exist as long as the language plugin is loaded.
 * They are not created by KDevelop::Problem instances, instead, they check for problematic code for themselves,
 * by tracking document changes via the textChanged() method.
 *
 * Note that static assistants are not bound to a single document/view.
 * Instead the current document/view we're looking at is passed via the textChanged() method.
 *
 * Register instances of this class view StaticAssistantsManager::registerAssistant
 *
 * @sa textChanged()
 * @sa StaticAssistantsManager::registerAssistant
 */
class KDEVPLATFORMLANGUAGE_EXPORT StaticAssistant
    : public IAssistant
{
    Q_OBJECT

public:
    using Ptr = QExplicitlySharedDataPointer<StaticAssistant>;

    explicit StaticAssistant(ILanguageSupport* supportedLanguage);
    ~StaticAssistant() override;

    /**
     * Language this static assistant supports
     *
     * textChanged() will only be called for documents with language equal to this assistant's language
     * @sa textChanged(0)
     */
    ILanguageSupport* supportedLanguage() const;

    /**
     * Invoked whenever text inside a view was changed by the user
     *
     * Reimplement in subclass
     */
    virtual void textChanged(KTextEditor::Document* doc, const KTextEditor::Range& invocationRange,
                             const QString& removedText = QString()) = 0;
    /**
     * Whether it's worth showing this assistant to the user
     *
     * Reimplement in subclass
     */
    virtual bool isUseful() const = 0;

    /**
     * The range the assistant should be displayed in.
     */
    virtual KTextEditor::Range displayRange() const = 0;

    virtual void updateReady(const IndexedString&, const KDevelop::ReferencedTopDUContext&) { }

private:
    const QScopedPointer<class StaticAssistantPrivate> d_ptr;
    Q_DECLARE_PRIVATE(StaticAssistant)
};
}

#endif // KDEVPLATFORM_STATICASSISTANT_H