Debian Codegraph @

LspCpp/include/LibLsp/lsp/extention/sonarlint/protocol.h

raw
1 #pragma once
2 #include <string>
3 #include <optional>
4 #include "LibLsp/JsonRpc/RequestInMessage.h"
5 #include "LibLsp/lsp/lsDocumentUri.h"
6 #include "LibLsp/lsp/lsAny.h"
7 #include "LibLsp/JsonRpc/NotificationInMessage.h"
8 #include "LibLsp/lsp/general/InitializeParams.h"
9
10 struct LintRule
11 {
12 std::string key;
13 std::string name;
14
15 std::string Display() const
16 {
17 return name + " (" + key + ")";
18 }
19 bool activeByDefault = true;
20 optional<std::string> severity;
21 optional<std::string> type;
22 int icon_index = -1;
23 MAKE_SWAP_METHOD(LintRule, key, name, activeByDefault, severity, type);
24 };
25 MAKE_REFLECT_STRUCT(LintRule, key, name, activeByDefault, severity, type);
26
27 struct RuleParameter
28 {
29 std::string name;
30 optional<std::string> description;
31 optional<std::string> defaultValue;
32 };
33 MAKE_REFLECT_STRUCT(RuleParameter, name, description, defaultValue);
34
35 struct ShowRuleDescriptionParams
36 {
37
38 optional<std::string> key;
39
40 optional<std::string> name;
41
42 optional<std::string> htmlDescription;
43
44 optional<std::string> type;
45
46 optional<std::string> severity;
47
48 optional<std::vector<RuleParameter>> parameters;
49 MAKE_SWAP_METHOD(ShowRuleDescriptionParams, key, name, htmlDescription, type, severity, parameters)
50 };
51 MAKE_REFLECT_STRUCT(ShowRuleDescriptionParams, key, name, htmlDescription, type, severity, parameters);
52
53 struct GetJavaConfigResponse
54 {
55 std::string projectRoot;
56 std::string sourceLevel;
57 std::vector<std::string> classpath;
58 bool isTest;
59 std::string vmLocation;
60 MAKE_SWAP_METHOD(GetJavaConfigResponse, projectRoot, sourceLevel, classpath, isTest, vmLocation);
61 };
62 MAKE_REFLECT_STRUCT(GetJavaConfigResponse, projectRoot, sourceLevel, classpath, isTest, vmLocation);
63
64 struct SetTraceNotificationParams
65 {
66 lsInitializeParams::lsTrace value;
67 };
68 MAKE_REFLECT_STRUCT(SetTraceNotificationParams, value);
69
70 struct ServerConnectionSettings
71 {
72
73 std::string SONARCLOUD_URL = "https://sonarcloud.io";
74 std::vector<std::string> SONARCLOUD_ALIAS = {
75 "https://sonarqube.com", "https://www.sonarqube.com", "https://www.sonarcloud.io", "https://sonarcloud.io"
76 };
77
78 std::string connectionId;
79 std::string serverUrl;
80 std::string token;
81 optional<std::string> organizationKey;
82 MAKE_SWAP_METHOD(ServerConnectionSettings, connectionId, serverUrl, token, organizationKey)
83 };
84 MAKE_REFLECT_STRUCT(ServerConnectionSettings, connectionId, serverUrl, token, organizationKey)
85
86 struct RuleSetting
87 {
88 bool IsOn();
89 std::string level = "on";
90 RuleSetting(bool activate);
91 RuleSetting() = default;
92 void toggle();
93 void on()
94 {
95 level = "on";
96 }
97 void off()
98 {
99 level = "off";
100 }
101 void turn(bool activate)
102 {
103 if (activate)
104 {
105 on();
106 }
107 else
108 {
109 off();
110 }
111 }
112 optional<std::map<std::string, std::string>> parameters;
113 };
114 MAKE_REFLECT_STRUCT(RuleSetting, level, parameters)
115
116 struct ConsoleParams
117 {
118 optional<bool> showAnalyzerLogs;
119 optional<bool> showVerboseLogs;
120 MAKE_SWAP_METHOD(ConsoleParams, showAnalyzerLogs, showVerboseLogs)
121 };
122 MAKE_REFLECT_STRUCT(ConsoleParams, showAnalyzerLogs, showVerboseLogs)
123
124 struct SonarLintWorkspaceSettings
125 {
126 optional<bool> disableTelemetry;
127 optional<std::map<std::string, ServerConnectionSettings>> connectedMode;
128 optional<std::map<std::string, RuleSetting>> rules;
129 optional<ConsoleParams> output;
130
131 optional<std::string> pathToNodeExecutable;
132
133 optional<std::map<std::string, std::string>> getConfigurationParameters(std::string const& ruleKey);
134 };
135
136 MAKE_REFLECT_STRUCT(SonarLintWorkspaceSettings, disableTelemetry, connectedMode, rules, output, pathToNodeExecutable)
137
138 DEFINE_REQUEST_RESPONSE_TYPE(slls_listAllRules, JsonNull, lsp::Any, "sonarlint/listAllRules");
139
140 DEFINE_NOTIFICATION_TYPE(Notify_didClasspathUpdate, lsDocumentUri, "sonarlint/didClasspathUpdate")
141
142 DEFINE_NOTIFICATION_TYPE(Notify_didJavaServerModeChange, std::string, "sonarlint/didJavaServerModeChange")
143
144 DEFINE_REQUEST_RESPONSE_TYPE(slls_showSonarLintOutput, JsonNull, JsonNull, "sonarlint/showSonarLintOutput");
145
146 DEFINE_REQUEST_RESPONSE_TYPE(slls_openJavaHomeSettings, JsonNull, JsonNull, "sonarlint/openJavaHomeSettings");
147
148 DEFINE_REQUEST_RESPONSE_TYPE(slls_openPathToNodeSettings, JsonNull, JsonNull, "sonarlint/openPathToNodeSettings");
149
150 DEFINE_REQUEST_RESPONSE_TYPE(
151 slls_showRuleDescription, ShowRuleDescriptionParams, JsonNull, "sonarlint/showRuleDescription"
152 );
153
154 DEFINE_REQUEST_RESPONSE_TYPE(slls_getJavaConfig, lsDocumentUri, GetJavaConfigResponse, "sonarlint/getJavaConfig");
155
156 DEFINE_NOTIFICATION_TYPE(slls_setTraceNotification, SetTraceNotificationParams, "$/setTraceNotification")