qmljscompletionassist.h 5.12 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Leandro Melo's avatar
Leandro Melo committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
Leandro Melo's avatar
Leandro Melo committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Leandro Melo's avatar
Leandro Melo committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Leandro Melo's avatar
Leandro Melo committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Leandro Melo's avatar
Leandro Melo committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
Leandro Melo's avatar
Leandro Melo committed
30 31 32 33 34 35

#ifndef QMLJSCOMPLETIONASSIST_H
#define QMLJSCOMPLETIONASSIST_H

#include "qmljseditor.h"

36 37
#include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/genericproposalmodel.h>
Leandro Melo's avatar
Leandro Melo committed
38 39 40
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/snippets/snippetassistcollector.h>
41
#include <texteditor/codeassist/assistinterface.h>
Leandro Melo's avatar
Leandro Melo committed
42

43

44 45 46 47
#include <QStringList>
#include <QScopedPointer>
#include <QVariant>
#include <QIcon>
Leandro Melo's avatar
Leandro Melo committed
48

49
namespace QmlJS { class Value; }
Leandro Melo's avatar
Leandro Melo committed
50 51 52 53 54

namespace QmlJSEditor {

class QmlJSCompletionAssistInterface;

55 56
namespace Internal {

57
class QmlJSAssistProposalItem : public TextEditor::AssistProposalItem
Leandro Melo's avatar
Leandro Melo committed
58 59
{
public:
60
    bool prematurelyApplies(const QChar &c) const Q_DECL_OVERRIDE;
61
    void applyContextualContent(TextEditor::TextEditorWidget *editorWidget,
62
                                int basePosition) const Q_DECL_OVERRIDE;
Leandro Melo's avatar
Leandro Melo committed
63 64 65
};


66
class QmlJSAssistProposalModel : public TextEditor::GenericProposalModel
Leandro Melo's avatar
Leandro Melo committed
67 68
{
public:
69
    QmlJSAssistProposalModel(const QList<TextEditor::AssistProposalItem *> &items)
hjk's avatar
hjk committed
70 71 72
    {
        loadContent(items);
    }
Leandro Melo's avatar
Leandro Melo committed
73

74 75 76
    void filter(const QString &prefix) Q_DECL_OVERRIDE;
    void sort(const QString &prefix) Q_DECL_OVERRIDE;
    bool keepPerfectMatch(TextEditor::AssistReason reason) const Q_DECL_OVERRIDE;
Leandro Melo's avatar
Leandro Melo committed
77 78 79 80 81
};


class QmlJSCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
82 83
    Q_OBJECT

Leandro Melo's avatar
Leandro Melo committed
84
public:
85 86
    bool supportsEditor(Core::Id editorId) const Q_DECL_OVERRIDE;
    TextEditor::IAssistProcessor *createProcessor() const Q_DECL_OVERRIDE;
Leandro Melo's avatar
Leandro Melo committed
87

88 89 90
    int activationCharSequenceLength() const Q_DECL_OVERRIDE;
    bool isActivationCharSequence(const QString &sequence) const Q_DECL_OVERRIDE;
    bool isContinuationChar(const QChar &c) const Q_DECL_OVERRIDE;
Leandro Melo's avatar
Leandro Melo committed
91 92 93 94 95 96 97
};


class QmlJSCompletionAssistProcessor : public TextEditor::IAssistProcessor
{
public:
    QmlJSCompletionAssistProcessor();
98
    ~QmlJSCompletionAssistProcessor();
Leandro Melo's avatar
Leandro Melo committed
99

100
    TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) Q_DECL_OVERRIDE;
Leandro Melo's avatar
Leandro Melo committed
101 102 103

private:
    TextEditor::IAssistProposal *createContentProposal() const;
104 105 106
    TextEditor::IAssistProposal *createHintProposal(
            const QString &functionName, const QStringList &namedArguments,
            int optionalNamedArguments, bool isVariadic) const;
Leandro Melo's avatar
Leandro Melo committed
107 108 109 110 111 112 113 114 115 116

    bool acceptsIdleEditor() const;

    bool completeUrl(const QString &relativeBasePath, const QString &urlString);
    bool completeFileName(const QString &relativeBasePath,
                          const QString &fileName,
                          const QStringList &patterns = QStringList());

    int m_startPosition;
    QScopedPointer<const QmlJSCompletionAssistInterface> m_interface;
117
    QList<TextEditor::AssistProposalItem *> m_completions;
Leandro Melo's avatar
Leandro Melo committed
118 119 120
    TextEditor::SnippetAssistCollector m_snippetCollector;
};

121
} // Internal
Leandro Melo's avatar
Leandro Melo committed
122

123
class QMLJSEDITOR_EXPORT QmlJSCompletionAssistInterface : public TextEditor::AssistInterface
Leandro Melo's avatar
Leandro Melo committed
124 125
{
public:
126
    QmlJSCompletionAssistInterface(QTextDocument *textDocument,
Leandro Melo's avatar
Leandro Melo committed
127
                                   int position,
128
                                   const QString &fileName,
Leandro Melo's avatar
Leandro Melo committed
129
                                   TextEditor::AssistReason reason,
130 131
                                   const QmlJSTools::SemanticInfo &info);
    const QmlJSTools::SemanticInfo &semanticInfo() const;
Leandro Melo's avatar
Leandro Melo committed
132 133 134 135 136
    const QIcon &fileNameIcon() const { return m_darkBlueIcon; }
    const QIcon &keywordIcon() const { return m_darkYellowIcon; }
    const QIcon &symbolIcon() const { return m_darkCyanIcon; }

private:
137
    QmlJSTools::SemanticInfo m_semanticInfo;
Leandro Melo's avatar
Leandro Melo committed
138 139 140 141 142 143 144 145
    QIcon m_darkBlueIcon;
    QIcon m_darkYellowIcon;
    QIcon m_darkCyanIcon;
};

} // QmlJSEditor

#endif // QMLJSCOMPLETIONASSIST_H