eclipse.jdt.ls
eclipse.jdt.ls copied to clipboard
JSONUtility.toModel(): add support for parsing maps
Since https://github.com/eclipse/eclipse.jdt.ls/pull/1312 was merged, I wanted to try using it as part of my project to get Java debugging working with vim-lsp and java-debug. Unfortunately, my first attempt at using the API failed because the language server doesn't know how to handle map-type arguments natively.
For context, here is how I'm invoking the new API:
call lsp#send_request('java-language-server', {
\ 'method': 'workspace/executeCommand',
\ 'params': {
\ 'command': 'java.project.getClasspaths',
\ 'arguments': [
\ 'file://'.expand('%:p'),
\ {'scope': 'runtime'},
\ ],
\ },
\ 'sync': v:true,
\ })
Initially, this resulted in a NullPointerException being raised here because options is null.
I tracked the error down to JSONUtility.toModel() returning null for the classpathOptions argument, and from there determined that it was actually an instance of com.google.gson.internal.LinkedTreeMap, causing toModel() to return null because it didn't match any of the expected types.
For simple cases such as this one, I think it would make sense for JSONUtility.toModel() to be smart enough to map the fields of a map into a model object, so that users of the API don't have to manually encode dictionaries into a JSON object.
Can one of the admins verify this patch?
I would invite @jdneo to take a look since he is the author of #1312
This is related with the JDT.LS's fundamental JSON transformations.
BTW, how did you calling the API? I can call it as below:
await extensionApi.getClasspaths(uri, {scope: 'runtime'});