qmljscompletionassist.h 5.1 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 55

namespace QmlJSEditor {
namespace Internal {

class QmlJSCompletionAssistInterface;

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


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

73 74 75
    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
76 77 78 79 80
};


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

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

87 88 89
    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
90 91 92 93 94 95 96
};


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

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

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

    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;
116
    QList<TextEditor::AssistProposalItem *> m_completions;
Leandro Melo's avatar
Leandro Melo committed
117 118 119 120
    TextEditor::SnippetAssistCollector m_snippetCollector;
};


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

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

} // Internal
} // QmlJSEditor

#endif // QMLJSCOMPLETIONASSIST_H