1 | // Copyright (C) 2024 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 QQMLHIGHLIGHTSUPPORT_P_H |
5 | #define QQMLHIGHLIGHTSUPPORT_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 "qqmlbasemodule_p.h" |
20 | #include "qqmlcodemodel_p.h" |
21 | #include "qqmlsemantictokens_p.h" |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | // We don't need these overrides as we register the request handlers in a single |
26 | // module QQmlHighlightSupport. This is an unusual pattern because QQmlBaseModule |
27 | // and QLanguageServerModule abstractions are designed to handle a single module |
28 | // which has a single request handlers. That is not the case for the semanticTokens |
29 | // module which has a one server module but also has three different handlers. |
30 | #define HIDE_UNUSED_OVERRIDES \ |
31 | private: \ |
32 | QString name() const override \ |
33 | { \ |
34 | return {}; \ |
35 | } \ |
36 | void setupCapabilities(const QLspSpecification::InitializeParams &, \ |
37 | QLspSpecification::InitializeResult &) override \ |
38 | { \ |
39 | } |
40 | |
41 | using SemanticTokensRequest = BaseRequest<QLspSpecification::SemanticTokensParams, |
42 | QLspSpecification::Responses::SemanticTokensResponseType>; |
43 | |
44 | using SemanticTokensDeltaRequest = |
45 | BaseRequest<QLspSpecification::SemanticTokensDeltaParams, |
46 | QLspSpecification::Responses::SemanticTokensDeltaResponseType>; |
47 | |
48 | using SemanticTokensRangeRequest = |
49 | BaseRequest<QLspSpecification::SemanticTokensRangeParams, |
50 | QLspSpecification::Responses::SemanticTokensRangeResponseType>; |
51 | |
52 | class SemanticTokenFullHandler : public QQmlBaseModule<SemanticTokensRequest> |
53 | { |
54 | public: |
55 | SemanticTokenFullHandler(QmlLsp::QQmlCodeModel *codeModel); |
56 | void process(QQmlBaseModule<SemanticTokensRequest>::RequestPointerArgument req) override; |
57 | void registerHandlers(QLanguageServer *, QLanguageServerProtocol *) override; |
58 | void setHighlightingMode(HighlightingUtils::HighlightingMode mode) { m_mode = mode; } |
59 | HIDE_UNUSED_OVERRIDES |
60 | HighlightingUtils::HighlightingMode m_mode; |
61 | }; |
62 | |
63 | class SemanticTokenDeltaHandler : public QQmlBaseModule<SemanticTokensDeltaRequest> |
64 | { |
65 | public: |
66 | SemanticTokenDeltaHandler(QmlLsp::QQmlCodeModel *codeModel); |
67 | void process(QQmlBaseModule<SemanticTokensDeltaRequest>::RequestPointerArgument req) override; |
68 | void registerHandlers(QLanguageServer *, QLanguageServerProtocol *) override; |
69 | void setHighlightingMode(HighlightingUtils::HighlightingMode mode) { m_mode = mode; } |
70 | HIDE_UNUSED_OVERRIDES |
71 | HighlightingUtils::HighlightingMode m_mode; |
72 | }; |
73 | |
74 | class SemanticTokenRangeHandler : public QQmlBaseModule<SemanticTokensRangeRequest> |
75 | { |
76 | public: |
77 | SemanticTokenRangeHandler(QmlLsp::QQmlCodeModel *codeModel); |
78 | void process(QQmlBaseModule<SemanticTokensRangeRequest>::RequestPointerArgument req) override; |
79 | void registerHandlers(QLanguageServer *, QLanguageServerProtocol *) override; |
80 | void setHighlightingMode(HighlightingUtils::HighlightingMode mode) { m_mode = mode; } |
81 | HIDE_UNUSED_OVERRIDES |
82 | HighlightingUtils::HighlightingMode m_mode;; |
83 | }; |
84 | |
85 | class QQmlHighlightSupport : public QLanguageServerModule |
86 | { |
87 | public: |
88 | QQmlHighlightSupport(QmlLsp::QQmlCodeModel *codeModel); |
89 | QString name() const override; |
90 | void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override; |
91 | void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, |
92 | QLspSpecification::InitializeResult &) override; |
93 | private: |
94 | SemanticTokenFullHandler m_full; |
95 | SemanticTokenDeltaHandler m_delta; |
96 | SemanticTokenRangeHandler m_range; |
97 | }; |
98 | |
99 | #undef HIDE_UNUSED_OVERRIDES |
100 | |
101 | QT_END_NAMESPACE |
102 | |
103 | #endif // QQMLHIGHLIGHTSUPPORT_P_H |
104 | |