Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmlcodemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLCODEMODEL_P_H
5#define QQMLCODEMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qlanguageserver_p.h"
19#include "qtextdocument_p.h"
20
21#include <QObject>
22#include <QHash>
23#include <QtQmlDom/private/qqmldomitem_p.h>
24#include <QtQmlCompiler/private/qqmljsscope_p.h>
25#include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h>
26
27#include <functional>
28#include <memory>
29
32namespace QmlLsp {
33
35{
36public:
37 enum class DumpOption {
38 NoCode = 0,
39 LatestCode = 0x1,
40 ValidCode = 0x2,
42 };
43 Q_DECLARE_FLAGS(DumpOptions, DumpOption)
46 std::optional<int> docVersion;
48 std::optional<int> validDocVersion;
50 std::optional<int> scopeVersion;
53 QQmlJSScope::Ptr scope = {};
54 QDebug dump(QDebug dbg, DumpOptions dump = DumpOption::NoCode);
55};
56
57Q_DECLARE_OPERATORS_FOR_FLAGS(OpenDocumentSnapshot::DumpOptions)
58
60{
61public:
63 std::shared_ptr<Utils::TextDocument> textDocument;
64};
65
66struct ToIndex
67{
70};
71
72class QQmlCodeModel : public QObject
73{
75public:
76 enum class UrlLookup { Caching, ForceLookup };
77 enum class State { Running, Stopping };
78
79 explicit QQmlCodeModel(QObject *parent = nullptr, QQmlToolingSettings *settings = nullptr);
85
86 void openNeedUpdate();
87 void indexNeedsUpdate();
89 void addOpenToUpdate(const QByteArray &);
90 void removeDirectory(const QString &path);
91 // void updateDocument(const OpenDocument &doc);
93 void newOpenFile(const QByteArray &url, int version, const QString &docText);
94 void newDocForOpenFile(const QByteArray &url, int version, const QString &docText);
95 void closeOpenFile(const QByteArray &url);
96 void setRootUrls(const QList<QByteArray> &urls);
98 void addRootUrls(const QList<QByteArray> &urls);
102 void removeRootUrls(const QList<QByteArray> &urls);
106private:
107 void indexDirectory(const QString &path, int depthLeft);
108 int indexEvalProgress() const; // to be called in the mutex
109 void indexStart(); // to be called in the mutex
110 void indexEnd(); // to be called in the mutex
111 void indexSendProgress(int progress);
112 bool indexCancelled();
113 bool indexSome();
114 void addDirectory(const QString &path, int leftDepth);
115 bool openUpdateSome();
116 void openUpdateStart();
117 void openUpdateEnd();
118 void openUpdate(const QByteArray &);
119 mutable QMutex m_mutex;
120 State m_state = State::Running;
121 int m_lastIndexProgress = 0;
122 int m_nIndexInProgress = 0;
123 QList<ToIndex> m_toIndex;
124 int m_indexInProgressCost = 0;
125 int m_indexDoneCost = 0;
126 int m_nUpdateInProgress = 0;
127 QQmlJS::Dom::DomItem m_currentEnv;
128 QQmlJS::Dom::DomItem m_validEnv;
129 QByteArray m_lastOpenDocumentUpdated;
130 QSet<QByteArray> m_openDocumentsToUpdate;
131 QHash<QByteArray, QStringList> m_buildPathsForRootUrl;
132 QList<QByteArray> m_rootUrls;
135 QHash<QByteArray, OpenDocument> m_openDocuments;
136 QQmlToolingSettings *m_settings;
137};
138
139} // namespace QmlLsp
141#endif // QQMLCODEMODEL_P_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:257
\inmodule QtCore
\inmodule QtCore
Definition qhash.h:818
Implements a server for the language server protocol.
Definition qlist.h:74
\inmodule QtCore
Definition qmutex.h:285
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
Tracks the types for the QmlCompiler.
Definition qset.h:18
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
std::optional< int > scopeVersion
std::optional< int > docVersion
std::optional< int > validDocVersion
QDebug dump(QDebug dbg, DumpOptions dump=DumpOption::NoCode)
QQmlJS::Dom::DomItem validDoc
std::shared_ptr< Utils::TextDocument > textDocument
OpenDocumentSnapshot snapshot
QQmlToolingSettings * settings()
void newOpenFile(const QByteArray &url, int version, const QString &docText)
void addRootUrls(const QList< QByteArray > &urls)
QList< QByteArray > rootUrls() const
QQmlJS::Dom::DomItem currentEnv()
void setBuildPathsForRootUrl(QByteArray url, const QStringList &paths)
OpenDocumentSnapshot snapshotByUrl(const QByteArray &url)
QQmlJS::Dom::DomItem validEnv()
void addOpenToUpdate(const QByteArray &)
QString url2Path(const QByteArray &url, UrlLookup options=UrlLookup::Caching)
OpenDocument openDocumentByUrl(const QByteArray &url)
QStringList buildPathsForFileUrl(const QByteArray &url)
void setRootUrls(const QList< QByteArray > &urls)
void removeDirectory(const QString &path)
void removeRootUrls(const QList< QByteArray > &urls)
void addDirectoriesToIndex(const QStringList &paths, QLanguageServer *server)
void newDocForOpenFile(const QByteArray &url, int version, const QString &docText)
void updatedSnapshot(const QByteArray &url)
QStringList buildPathsForRootUrl(const QByteArray &url)
void closeOpenFile(const QByteArray &url)
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLsizei const GLuint * paths
GLsizei const GLchar *const * path
#define Q_OBJECT
#define Q_SIGNALS
QUrl url("example.com")
[constructor-url-reference]