Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lua/java-core/ls/servers/jdtls/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local M = {}

function M.get_config()
return {
init_options = {
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',
},
},
},

handlers = {
--@TODO
--overriding '$/progress' is necessary because by default it's using the
--lspconfig progress handler which prints the wrong value in the latest
--jdtls version (tested on 1.29.0).
--https://github.com/neovim/nvim-lspconfig/issues/2897
['$/progress'] = vim.lsp.handlers['$/progress'],
},
}
end

return M
67 changes: 67 additions & 0 deletions lua/java-core/ls/servers/jdtls/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local util = require('lspconfig.util')
local path = require('java-core.utils.path')
local mason = require('java-core.utils.mason')
local plugins = require('java-core.ls.servers.jdtls.plugins')
local log = require('java-core.utils.log')
local workspace = require('java-core.ls.servers.jdtls.workspace')
local config = require('java-core.ls.servers.jdtls.config')

local M = {}

---@class JavaCoreGetConfigOptions
---@field root_markers string[] list of files to find the root dir of a project
---Ex:- { 'pom.xml', 'build.gradle', '.git' }
---@field jdtls_plugins string[] list of jdtls plugins to load on start up
---Ex:- { 'java-test', 'java-debug-adapter' }

---Returns a configuration for jdtls that you can pass into the setup of nvim-lspconfig
---@param opts JavaCoreGetConfigOptions
---@return LSPSetupConfig # jdtls setup configuration
function M.get_config(opts)
log.debug('generating jdtls config')

local jdtls_path = mason.get_pkg_path('jdtls')
local lombok_path = path.join(jdtls_path, 'lombok.jar')
local jdtls_cache_path = path.join(vim.fn.stdpath('cache'), 'jdtls')
local plugin_paths =
plugins.get_plugin_paths({ 'java-test', 'java-debug-adapter' })

local base_config = config.get_config()

base_config.cmd = {
'jdtls',
'-configuration',
jdtls_cache_path,
'-data',
workspace.get_default_workspace(),
'-javaagent:' .. lombok_path,
}

base_config.root_dir = M.get_root_finder(opts.root_markers)
base_config.init_options.bundles = plugin_paths
base_config.init_options.workspace = workspace.get_default_workspace()

log.debug('generated jdtls setup config: ', base_config)

return base_config
end

---Returns a function that finds the java project root
---@private
---@param root_markers string[] list of files to find the root dir of a project
---@return function
function M.get_root_finder(root_markers)
return function(file_name)
log.info('finding the root_dir')
log.debug('root_markers: ', root_markers)

local root = util.root_pattern(unpack(root_markers))(file_name)

if root then
log.fmt_debug('root of: %s is: %s', file_name, root)
return root
end
end
end

return M
32 changes: 32 additions & 0 deletions lua/java-core/ls/servers/jdtls/plugins.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local mason = require('java-core.utils.mason')
local path = require('java-core.utils.path')
local file = require('java-core.utils.file')

local List = require('java-core.utils.list')

local M = {}

local plugin_to_jar_path_map = {
['java-test'] = '*.jar',
['java-debug-adapter'] = '*.jar',
}

---Returns a list of .jar file paths for given list of jdtls plugins
---@param plugins string[]
---@return string[] # list of .jar file paths
function M.get_plugin_paths(plugins)
local plugin_paths = List:new()

for _, plugin in ipairs(plugins) do
local relative_path = plugin_to_jar_path_map[plugin]
local plugin_shared_path = mason.get_shared_path(plugin)
local full_path = path.join(plugin_shared_path, relative_path)
local resolved_paths = file.get_file_list(full_path)

plugin_paths:push(resolved_paths)
end

return plugin_paths:flatten()
end

return M
123 changes: 0 additions & 123 deletions lua/java-core/server.lua

This file was deleted.

27 changes: 0 additions & 27 deletions lua/java-core/settings.lua

This file was deleted.

10 changes: 10 additions & 0 deletions lua/java-core/utils/path.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local M = {}

---Join a given list of paths to one path
---@param ... string paths to join
---@return string # joined path
function M.join(...)
return table.concat({ ... }, '/')
end

return M
39 changes: 0 additions & 39 deletions lua/java-core/utils/plugin.lua

This file was deleted.

44 changes: 0 additions & 44 deletions lua/java-core/utils/table.lua

This file was deleted.