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

source code of qtdeclarative/src/qmlls/qqmllintsuggestions_p.h