1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "javaparam.h" |
6 | |
7 | #include <QFileInfo> |
8 | #include <QUrl> |
9 | |
10 | JavaParam::JavaParam(QObject *parent) |
11 | : QObject(parent) |
12 | { |
13 | |
14 | } |
15 | |
16 | JavaParam::~JavaParam() |
17 | { |
18 | |
19 | } |
20 | |
21 | QString JavaParam::getInitBackendParam(const QString &port, |
22 | const QString &javaPath, |
23 | const QString &launcherPath, |
24 | const QString &heapDumpPath, |
25 | const QString &configLinuxPath, |
26 | const QString &dataPath) |
27 | { |
28 | QString param = javaPath + " " + |
29 | "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + port + ",quiet=y " |
30 | "--add-modules=ALL-SYSTEM " |
31 | "--add-opens java.base/java.util=ALL-UNNAMED " |
32 | "--add-opens java.base/java.lang=ALL-UNNAMED " |
33 | "--add-opens java.base/sun.nio.fs=ALL-UNNAMED " |
34 | "-Declipse.application=org.eclipse.jdt.ls.core.id1 " |
35 | "-Dosgi.bundles.defaultStartLevel=4 " |
36 | "-Declipse.product=org.eclipse.jdt.ls.core.product " |
37 | "-Dlog.level=ALL " |
38 | "-Djava.import.generatesMetadataFilesAtProjectRoot=false " |
39 | "-Dfile.encoding=utf8 " |
40 | "-XX:+UseParallelGC " |
41 | "-XX:GCTimeRatio=4 " |
42 | "-XX:AdaptiveSizePolicyWeight=90 " |
43 | "-Dsun.zip.disableMemoryMapping=true " |
44 | "-Xmx1G -Xms100m -Xlog:jni+resolve=off " |
45 | "-XX:+HeapDumpOnOutOfMemoryError " |
46 | "-XX:HeapDumpPath=" + heapDumpPath + " " |
47 | "-jar " + launcherPath + " " |
48 | "-configuration " + configLinuxPath + " " |
49 | "-data " + dataPath; |
50 | return param; |
51 | } |
52 | |
53 | QString JavaParam::getLSPInitParam(const int requestId, |
54 | const int pid, |
55 | const QString &workspace, |
56 | const QString &jdkHome, |
57 | const QString &debugJar) |
58 | { |
59 | QString workspaceUrl = QUrl::fromLocalFile(workspace).toEncoded(); |
60 | QString param = R"({ |
61 | "jsonrpc": "2.0", |
62 | "id": )" + QString::number(requestId) + R"(, |
63 | "method": "initialize", |
64 | "params": { |
65 | "processId": )" + QString::number(pid) + R"(, |
66 | "clientInfo": { |
67 | "name": "Union Code", |
68 | "version": "1.0.0" |
69 | }, |
70 | "locale": "zh-cn", |
71 | "rootPath": ")" + workspaceUrl + R"(", |
72 | "rootUri": ")" + workspaceUrl + R"(", |
73 | "capabilities": { |
74 | |
75 | }, |
76 | "initializationOptions": { |
77 | "bundles": [ |
78 | ")" + debugJar + R"(" |
79 | ], |
80 | "workspaceFolders": [ |
81 | ")" + workspaceUrl + R"(" |
82 | ], |
83 | "settings": { |
84 | "java": { |
85 | "home": ")" + jdkHome + R"(", |
86 | "sources": { |
87 | "organizeImports": { |
88 | "starThreshold": 99, |
89 | "staticStarThreshold": 99 |
90 | } |
91 | }, |
92 | "import": { |
93 | "maven": { |
94 | "enabled": true, |
95 | "offline": { |
96 | "enabled": false |
97 | } |
98 | }, |
99 | "gradle": { |
100 | "enabled": true, |
101 | "wrapper": { |
102 | "enabled": true |
103 | }, |
104 | "version": null, |
105 | "home": null, |
106 | "java": { |
107 | "home": null |
108 | }, |
109 | "offline": { |
110 | "enabled": false |
111 | }, |
112 | "arguments": null, |
113 | "jvmArguments": null, |
114 | "user": { |
115 | "home": null |
116 | } |
117 | }, |
118 | "exclusions": [ |
119 | "**/node_modules/**", |
120 | "**/.metadata/**", |
121 | "**/archetype-resources/**", |
122 | "**/META-INF/maven/**" |
123 | ], |
124 | "generatesMetadataFilesAtProjectRoot": false |
125 | }, |
126 | "debug": { |
127 | "logLevel": "verbose", |
128 | "settings": { |
129 | "showHex": false, |
130 | "showStaticVariables": false, |
131 | "showQualifiedNames": false, |
132 | "showLogicalStructure": true, |
133 | "showToString": true, |
134 | "maxStringLength": 0, |
135 | "numericPrecision": 0, |
136 | "hotCodeReplace": "manual", |
137 | "enableRunDebugCodeLens": true, |
138 | "forceBuildBeforeLaunch": true, |
139 | "onBuildFailureProceed": false, |
140 | "console": "integratedTerminal", |
141 | "exceptionBreakpoint": { |
142 | "skipClasses": [] |
143 | }, |
144 | "stepping": { |
145 | "skipClasses": [], |
146 | "skipSynthetics": false, |
147 | "skipStaticInitializers": false, |
148 | "skipConstructors": false |
149 | }, |
150 | "jdwp": { |
151 | "limitOfVariablesPerJdwpRequest": 100, |
152 | "requestTimeout": 3000, |
153 | "async": "auto" |
154 | }, |
155 | "vmArgs": "" |
156 | } |
157 | }, |
158 | "silentNotification": false |
159 | } |
160 | }, |
161 | "extendedClientCapabilities": { |
162 | "progressReportProvider": true, |
163 | "classFileContentsSupport": true, |
164 | "overrideMethodsPromptSupport": true, |
165 | "hashCodeEqualsPromptSupport": true, |
166 | "advancedOrganizeImportsSupport": true, |
167 | "generateToStringPromptSupport": true, |
168 | "advancedGenerateAccessorsSupport": true, |
169 | "generateConstructorsPromptSupport": true, |
170 | "generateDelegateMethodsPromptSupport": true, |
171 | "advancedExtractRefactoringSupport": true, |
172 | "inferSelectionSupport": [ |
173 | "extractMethod", |
174 | "extractVariable", |
175 | "extractField" |
176 | ], |
177 | "moveRefactoringSupport": true, |
178 | "clientHoverProvider": true, |
179 | "clientDocumentSymbolProvider": true, |
180 | "gradleChecksumWrapperPromptSupport": true, |
181 | "resolveAdditionalTextEditsSupport": true, |
182 | "advancedIntroduceParameterRefactoringSupport": true, |
183 | "actionableRuntimeNotificationSupport": true, |
184 | "shouldLanguageServerExitOnShutdown": true, |
185 | "onCompletionItemSelectedCommand": "editor.action.triggerParameterHints" |
186 | } |
187 | }, |
188 | "trace": "verbose", |
189 | "workspaceFolders": [{ |
190 | "uri": ")" + workspaceUrl + R"(", |
191 | "name": ")" + QFileInfo(workspace).fileName() + R"(" |
192 | }] |
193 | } |
194 | })" ; |
195 | |
196 | return param; |
197 | } |
198 | |
199 | QString JavaParam::getLSPInitilizedParam(const int requestId) |
200 | { |
201 | QString param = R"({ |
202 | "jsonrpc": "2.0", |
203 | "id": )" + QString::number(requestId) + R"(, |
204 | "method": "initialized", |
205 | "params": {} |
206 | })" ; |
207 | |
208 | return param; |
209 | } |
210 | |
211 | QString JavaParam::getLaunchJavaDAPParam(const int requestId) |
212 | { |
213 | QString param = R"({ |
214 | "jsonrpc": "2.0", |
215 | "id": )" + QString::number(requestId) + R"(, |
216 | "method": "workspace/executeCommand", |
217 | "params": { |
218 | "command": "vscode.java.startDebugSession", |
219 | "arguments": [] |
220 | } |
221 | })" ; |
222 | |
223 | return param; |
224 | } |
225 | |
226 | |
227 | QString JavaParam::getResolveMainClassParam(const int requestId, |
228 | const QString &workspace) |
229 | { |
230 | QString workspaceUrl = QUrl::fromLocalFile(workspace).toEncoded(); |
231 | QString param = R"({ |
232 | "jsonrpc": "2.0", |
233 | "id": )" + QString::number(requestId) + R"(, |
234 | "method": "workspace/executeCommand", |
235 | "params": { |
236 | "command": "vscode.java.resolveMainClass", |
237 | "arguments": [")" + workspaceUrl + R"("] |
238 | } |
239 | })" ; |
240 | |
241 | return param; |
242 | } |
243 | |
244 | QString JavaParam::getResolveClassPathParam(const int requestId, |
245 | const QString &mainClass, |
246 | const QString &projectName) |
247 | { |
248 | QString param = R"({ |
249 | "jsonrpc": "2.0", |
250 | "id": )" + QString::number(requestId) + R"(, |
251 | "method": "workspace/executeCommand", |
252 | "params": { |
253 | "command": "vscode.java.resolveClasspath", |
254 | "arguments": [")" + mainClass + R"(", ")" + projectName + R"("] |
255 | } |
256 | })" ; |
257 | |
258 | return param; |
259 | } |
260 | |