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 QMLLINTSUGGESTIONS_P_H |
5 | #define QMLLINTSUGGESTIONS_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 "qqmlcodemodel_p.h" |
20 | |
21 | #include <chrono> |
22 | #include <optional> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | namespace QmlLsp { |
26 | struct LastLintUpdate |
27 | { |
28 | std::optional<int> version; |
29 | std::optional<std::chrono::steady_clock::time_point> invalidUpdatesSince; |
30 | }; |
31 | |
32 | class QmlLintSuggestions : public QLanguageServerModule |
33 | { |
34 | Q_OBJECT |
35 | public: |
36 | QmlLintSuggestions(QLanguageServer *server, QmlLsp::QQmlCodeModel *codeModel); |
37 | |
38 | QString name() const override { return QLatin1StringView("QmlLint Suggestions"); } |
39 | public Q_SLOTS: |
40 | void diagnose(const QByteArray &uri); |
41 | void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override; |
42 | void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, |
43 | QLspSpecification::InitializeResult &) override; |
44 | |
45 | private: |
46 | struct VersionedDocument |
47 | { |
48 | std::optional<int> version; |
49 | QQmlJS::Dom::DomItem item; |
50 | }; |
51 | struct TryAgainLater |
52 | { |
53 | std::chrono::milliseconds time; |
54 | }; |
55 | struct NoDocumentAvailable |
56 | { |
57 | }; |
58 | |
59 | using VersionToDiagnose = std::variant<VersionedDocument, TryAgainLater, NoDocumentAvailable>; |
60 | |
61 | VersionToDiagnose chooseVersionToDiagnose(const QByteArray &url); |
62 | VersionToDiagnose chooseVersionToDiagnoseHelper(const QByteArray &url); |
63 | void diagnoseHelper(const QByteArray &uri, const VersionedDocument &document); |
64 | |
65 | QMutex m_mutex; |
66 | QHash<QByteArray, LastLintUpdate> m_lastUpdate; |
67 | QLanguageServer *m_server; |
68 | QmlLsp::QQmlCodeModel *m_codeModel; |
69 | }; |
70 | } // namespace QmlLsp |
71 | QT_END_NAMESPACE |
72 | #endif // QMLLINTSUGGESTIONS_P_H |
73 |