diff --git a/lua/java-core/jdtls-types.lua b/lua/java-core/jdtls-types.lua index 8621241..076f6a3 100644 --- a/lua/java-core/jdtls-types.lua +++ b/lua/java-core/jdtls-types.lua @@ -1,6 +1,6 @@ local M = {} ---@class InitializationOptions ----@field bundles? string +---@field bundles? string[] ---@field workspaceFolders? string ---@field settings? JavaConfigurationSettings diff --git a/lua/java-core/ls/clients/jdtls-client.lua b/lua/java-core/ls/clients/jdtls-client.lua index a8c08c5..27ad80f 100644 --- a/lua/java-core/ls/clients/jdtls-client.lua +++ b/lua/java-core/ls/clients/jdtls-client.lua @@ -5,8 +5,13 @@ local Promise = require('java-core.utils.promise') ---@field client LSPClient local M = {} -function M:new(o) - o = o or {} +---@param args { client: LSPClient } +---@return JavaCoreJdtlsClient +function M:new(args) + local o = { + client = (args or {}).client, + } + setmetatable(o, self) self.__index = self return o @@ -16,7 +21,7 @@ end ---@param command string ---@param arguments? string | string[] ---@param buffer? integer ----@return Promise +---@return Promise # Promise function M:execute_command(command, arguments, buffer) return Promise.new(function(resolve, reject) local cmd_info = { @@ -36,6 +41,13 @@ function M:execute_command(command, arguments, buffer) end) end +---Returns the decompiled class file content +---@param uri string uri of the class file +---@return Promise # Promise - decompiled file content +function M:java_decompile(uri) + return self:execute_command('java.decompile', { uri }) +end + function M:get_capability(...) local capability = self.client.server_capabilities diff --git a/lua/java-core/lspconfig-types.lua b/lua/java-core/lspconfig-types.lua index e06d066..1891e83 100644 --- a/lua/java-core/lspconfig-types.lua +++ b/lua/java-core/lspconfig-types.lua @@ -8,7 +8,7 @@ ---@field capabilities table a table which represents the neovim client capabilities. Useful for broadcasting to the server additional functionality (snippets, off-protocol features) provided by plugins. ---@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. ---@field handlers table 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|. ----@field init_options table a table passed during the initialization notification after launching a language server. Equivalent to the `initializationOptions` field found in `InitializeParams` in the LSP specification. +---@field init_options { bundles?: string[], workspaceFolders?: string, settings?: JavaConfigurationSettings, extendedClientCapabilities: table } ---@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. ---@field settings table 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. diff --git a/lua/java-core/server.lua b/lua/java-core/server.lua index 92cd453..18f2619 100644 --- a/lua/java-core/server.lua +++ b/lua/java-core/server.lua @@ -19,14 +19,13 @@ M.plugins = { { name = 'java-debug-adapter', path = '/*.jar' }, } ----Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig --- ---@class JavaGetConfigOptions ---@field root_markers string[] list of files to find the root dir of a project ---Ex:- { 'pom.xml', 'build.gradle', '.git' } ---- --- + +---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig ---@param opts JavaGetConfigOptions +---@return LSPSetupConfig # jdtls setup configuration function M.get_config(opts) log.info('generating jdtls config') @@ -65,9 +64,28 @@ function M.get_config(opts) init_options = { bundles = plugins, workspace = workspace.get_default_workspace(), + extendedClientCapabilities = { + classFileContentsSupport = true, + generateToStringPromptSupport = true, + hashCodeEqualsPromptSupport = true, + advancedExtractRefactoringSupport = true, + advancedOrganizeImportsSupport = true, + generateConstructorsPromptSupport = true, + generateDelegateMethodsPromptSupport = true, + moveRefactoringSupport = true, + overrideMethodsPromptSupport = true, + executeClientCommandSupport = true, + inferSelectionSupport = { + 'extractMethod', + 'extractVariable', + 'extractConstant', + 'extractVariableAllOccurrence', + }, + }, }, root_dir = M.get_root_finder(opts.root_markers), + capabilities = vim.lsp.protocol.make_client_capabilities(), } log.debug('generated config: ', conf) diff --git a/lua/java-core/utils/log.lua b/lua/java-core/utils/log.lua index e97837e..5f113f9 100644 --- a/lua/java-core/utils/log.lua +++ b/lua/java-core/utils/log.lua @@ -16,7 +16,7 @@ local default_config = { plugin = 'nvim-java-core', -- Should print the output to neovim while running - use_console = true, + use_console = false, -- Should highlighting be used in console (using echohl) highlights = true,