1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef QMLJSCODECOMPLETION_H
34 #define QMLJSCODECOMPLETION_H
36 #include <qmljs/qmljsdocument.h>
37 #include <texteditor/icompletioncollector.h>
38 #include <texteditor/snippets/snippetcollector.h>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QPointer>
42 namespace TextEditor {
47 class ModelManagerInterface;
49 namespace Interpreter {
54 namespace QmlJSEditor {
58 class FunctionArgumentWidget;
60 class CodeCompletion: public TextEditor::ICompletionCollector
65 explicit CodeCompletion(QmlJS::ModelManagerInterface *modelManager, QObject *parent = 0);
66 virtual ~CodeCompletion();
68 virtual TextEditor::ITextEditor *editor() const;
69 virtual int startPosition() const;
70 virtual bool shouldRestartCompletion();
71 virtual bool supportsEditor(TextEditor::ITextEditor *editor) const;
72 virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
73 virtual bool triggersCompletion(TextEditor::ITextEditor *editor);
74 virtual int startCompletion(TextEditor::ITextEditor *editor);
75 virtual void completions(QList<TextEditor::CompletionItem> *completions);
76 virtual bool typedCharCompletes(const TextEditor::CompletionItem &item, QChar typedChar);
77 virtual void complete(const TextEditor::CompletionItem &item, QChar typedChar);
78 virtual bool partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems);
79 virtual QList<TextEditor::CompletionItem> getCompletions();
80 virtual void sortCompletion(QList<TextEditor::CompletionItem> &completionItems);
82 virtual void cleanup();
86 bool maybeTriggersCompletion(TextEditor::ITextEditor *editor);
87 bool isDelimiter(QChar ch) const;
89 bool completeUrl(const QString &relativeBasePath, const QString &urlString);
90 bool completeFileName(const QString &relativeBasePath, const QString &fileName,
91 const QStringList &patterns = QStringList());
93 void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
94 const QIcon &icon, int relevance);
95 void addCompletions(const QStringList &newCompletions,
96 const QIcon &icon, int relevance);
97 void addCompletionsPropertyLhs(
98 const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
99 const QIcon &icon, int relevance, bool afterOn);
101 QmlJS::ModelManagerInterface *m_modelManager;
102 TextEditor::ITextEditor *m_editor;
104 bool m_restartCompletion;
105 TextEditor::SnippetCollector m_snippetProvider;
106 QList<TextEditor::CompletionItem> m_completions;
107 QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
111 } // namespace Internal
112 } // namespace QmlJSEditor
114 #endif // QMLJSCODECOMPLETION_H