qmljscompletionassist.h 5.04 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Leandro Melo's avatar
Leandro Melo committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Leandro Melo's avatar
Leandro Melo committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Leandro Melo's avatar
Leandro Melo committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Leandro Melo's avatar
Leandro Melo committed
29 30 31 32 33 34

#ifndef QMLJSCOMPLETIONASSIST_H
#define QMLJSCOMPLETIONASSIST_H

#include "qmljseditor.h"

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

42

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

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

namespace QmlJSEditor {
namespace Internal {

class QmlJSCompletionAssistInterface;

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


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

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


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

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

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


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

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

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

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


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

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

} // Internal
} // QmlJSEditor

#endif // QMLJSCOMPLETIONASSIST_H