Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

Commit 5ef224f

Browse files
authored
feat: add decompile command and enable class file support in jdtls (#10)
1 parent fe84fe5 commit 5ef224f

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

lua/java-core/jdtls-types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
22
---@class InitializationOptions
3-
---@field bundles? string
3+
---@field bundles? string[]
44
---@field workspaceFolders? string
55
---@field settings? JavaConfigurationSettings
66

lua/java-core/ls/clients/jdtls-client.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ local Promise = require('java-core.utils.promise')
55
---@field client LSPClient
66
local M = {}
77

8-
function M:new(o)
9-
o = o or {}
8+
---@param args { client: LSPClient }
9+
---@return JavaCoreJdtlsClient
10+
function M:new(args)
11+
local o = {
12+
client = (args or {}).client,
13+
}
14+
1015
setmetatable(o, self)
1116
self.__index = self
1217
return o
@@ -16,7 +21,7 @@ end
1621
---@param command string
1722
---@param arguments? string | string[]
1823
---@param buffer? integer
19-
---@return Promise
24+
---@return Promise # Promise<any>
2025
function M:execute_command(command, arguments, buffer)
2126
return Promise.new(function(resolve, reject)
2227
local cmd_info = {
@@ -36,6 +41,13 @@ function M:execute_command(command, arguments, buffer)
3641
end)
3742
end
3843

44+
---Returns the decompiled class file content
45+
---@param uri string uri of the class file
46+
---@return Promise # Promise<string> - decompiled file content
47+
function M:java_decompile(uri)
48+
return self:execute_command('java.decompile', { uri })
49+
end
50+
3951
function M:get_capability(...)
4052
local capability = self.client.server_capabilities
4153

lua/java-core/lspconfig-types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
---@field capabilities table<string, string|table|boolean|function> a table which represents the neovim client capabilities. Useful for broadcasting to the server additional functionality (snippets, off-protocol features) provided by plugins.
99
---@field cmd string[] a list where each entry corresponds to the blankspace delimited part of the command that launches the server. The first entry is the binary used to run the language server. Additional entries are passed as arguments.
1010
---@field handlers table<string, function> a list of handlers which override the function used to process a response from a given language server. Applied only to the server referenced by setup. See |lsp-handler|.
11-
---@field init_options table<string, string|table|boolean> a table passed during the initialization notification after launching a language server. Equivalent to the `initializationOptions` field found in `InitializeParams` in the LSP specification.
11+
---@field init_options { bundles?: string[], workspaceFolders?: string, settings?: JavaConfigurationSettings, extendedClientCapabilities: table<string, string|boolean|table> }
1212
---@field on_attach fun(client: object, bufnr: number) Callback invoked by Nvim's built-in client when attaching a buffer to a language server. Often used to set Nvim (buffer or global) options or to override the Nvim client properties (`server_capabilities`) after a language server attaches. Most commonly used for settings buffer local keybindings. See |lspconfig-keybindings| for a usage example.
1313
---@field settings table <string, string|table|boolean> The `settings` table is sent in `on_init` via a `workspace/didChangeConfiguration` notification from the Nvim client to the language server. These settings allow a user to change optional runtime settings of the language server.
1414

lua/java-core/server.lua

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ M.plugins = {
1919
{ name = 'java-debug-adapter', path = '/*.jar' },
2020
}
2121

22-
---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig
23-
--
2422
---@class JavaGetConfigOptions
2523
---@field root_markers string[] list of files to find the root dir of a project
2624
---Ex:- { 'pom.xml', 'build.gradle', '.git' }
27-
---
28-
--
25+
26+
---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig
2927
---@param opts JavaGetConfigOptions
28+
---@return LSPSetupConfig # jdtls setup configuration
3029
function M.get_config(opts)
3130
log.info('generating jdtls config')
3231

@@ -65,9 +64,28 @@ function M.get_config(opts)
6564
init_options = {
6665
bundles = plugins,
6766
workspace = workspace.get_default_workspace(),
67+
extendedClientCapabilities = {
68+
classFileContentsSupport = true,
69+
generateToStringPromptSupport = true,
70+
hashCodeEqualsPromptSupport = true,
71+
advancedExtractRefactoringSupport = true,
72+
advancedOrganizeImportsSupport = true,
73+
generateConstructorsPromptSupport = true,
74+
generateDelegateMethodsPromptSupport = true,
75+
moveRefactoringSupport = true,
76+
overrideMethodsPromptSupport = true,
77+
executeClientCommandSupport = true,
78+
inferSelectionSupport = {
79+
'extractMethod',
80+
'extractVariable',
81+
'extractConstant',
82+
'extractVariableAllOccurrence',
83+
},
84+
},
6885
},
6986

7087
root_dir = M.get_root_finder(opts.root_markers),
88+
capabilities = vim.lsp.protocol.make_client_capabilities(),
7189
}
7290

7391
log.debug('generated config: ', conf)

lua/java-core/utils/log.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local default_config = {
1616
plugin = 'nvim-java-core',
1717

1818
-- Should print the output to neovim while running
19-
use_console = true,
19+
use_console = false,
2020

2121
-- Should highlighting be used in console (using echohl)
2222
highlights = true,

0 commit comments

Comments
 (0)