|
18 | 18 | *******************************************************************************/ |
19 | 19 | package org.eclipse.lsp4e; |
20 | 20 |
|
21 | | -import static org.eclipse.lsp4e.internal.NullSafetyHelper.*; |
| 21 | +import static org.eclipse.lsp4e.internal.NullSafetyHelper.castNonNull; |
22 | 22 |
|
23 | 23 | import java.io.BufferedReader; |
24 | 24 | import java.io.File; |
|
119 | 119 | import org.eclipse.lsp4j.jsonrpc.Launcher; |
120 | 120 | import org.eclipse.lsp4j.jsonrpc.MessageConsumer; |
121 | 121 | import org.eclipse.lsp4j.jsonrpc.ResponseErrorException; |
| 122 | +import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter; |
122 | 123 | import org.eclipse.lsp4j.jsonrpc.messages.Either; |
123 | 124 | import org.eclipse.lsp4j.jsonrpc.messages.Message; |
124 | 125 | import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode; |
|
130 | 131 | import com.google.common.base.Functions; |
131 | 132 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
132 | 133 | import com.google.gson.Gson; |
| 134 | +import com.google.gson.GsonBuilder; |
133 | 135 | import com.google.gson.JsonObject; |
134 | 136 |
|
135 | 137 | public class LanguageServerWrapper { |
@@ -251,6 +253,10 @@ synchronized void close() { |
251 | 253 | } |
252 | 254 | } |
253 | 255 |
|
| 256 | + private static final Gson GSON = new GsonBuilder() |
| 257 | + .registerTypeAdapterFactory(new EitherTypeAdapter.Factory()) |
| 258 | + .create(); |
| 259 | + |
254 | 260 | public final LanguageServerDefinition serverDefinition; |
255 | 261 | public final @Nullable IProject initialProject; |
256 | 262 | protected Map<URI, DocumentContentSynchronizer> connectedDocuments; |
@@ -1173,7 +1179,7 @@ public void registerCapability(RegistrationParams params) { |
1173 | 1179 | break; |
1174 | 1180 | case "workspace/executeCommand": //$NON-NLS-1$ |
1175 | 1181 | try { |
1176 | | - ExecuteCommandOptions executeCommandOptions = castNonNull(new Gson().fromJson((JsonObject) reg.getRegisterOptions(), |
| 1182 | + ExecuteCommandOptions executeCommandOptions = castNonNull(GSON.fromJson((JsonObject) reg.getRegisterOptions(), |
1177 | 1183 | ExecuteCommandOptions.class)); |
1178 | 1184 | List<String> newCommands = executeCommandOptions.getCommands(); |
1179 | 1185 | if (!newCommands.isEmpty()) { |
@@ -1212,7 +1218,7 @@ public void registerCapability(RegistrationParams params) { |
1212 | 1218 | case "textDocument/completion": { //$NON-NLS-1$ |
1213 | 1219 | CompletionOptions previous = serverCapabilities.getCompletionProvider(); |
1214 | 1220 | try { |
1215 | | - final var completionOpts = new Gson().fromJson((JsonObject) reg.getRegisterOptions(), |
| 1221 | + final var completionOpts = GSON.fromJson((JsonObject) reg.getRegisterOptions(), |
1216 | 1222 | CompletionOptions.class); |
1217 | 1223 | serverCapabilities.setCompletionProvider(completionOpts); |
1218 | 1224 | addRegistration(reg, () -> serverCapabilities.setCompletionProvider(previous)); |
@@ -1255,8 +1261,9 @@ public void registerCapability(RegistrationParams params) { |
1255 | 1261 | return null; |
1256 | 1262 | if (registerOptions instanceof DidChangeWatchedFilesRegistrationOptions direct) |
1257 | 1263 | return direct; |
1258 | | - if (registerOptions instanceof JsonObject jsonObject) |
1259 | | - return new Gson().fromJson(jsonObject, DidChangeWatchedFilesRegistrationOptions.class); |
| 1264 | + if (registerOptions instanceof JsonObject jsonObject) { |
| 1265 | + return GSON.fromJson(jsonObject, DidChangeWatchedFilesRegistrationOptions.class); |
| 1266 | + } |
1260 | 1267 | return null; |
1261 | 1268 | } |
1262 | 1269 |
|
|
0 commit comments