diff --git a/README.md b/README.md index 48bf0a5..ffee376 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,10 @@ local config = { -- 💀 -- This is the default if not provided, you can remove it. Or adjust as needed. -- One dedicated LSP server & client will be started per unique root_dir - root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'}), + -- + -- vim.fs.root requires Neovim 0.10. + -- If you're using an earlier version, use: require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'}), + root_dir = vim.fs.root(0, {".git", "mvnw", "gradlew"}) -- Here you can configure eclipse.jdt.ls specific settings -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request diff --git a/lua/jdtls.lua b/lua/jdtls.lua index 6695355..d31e25d 100644 --- a/lua/jdtls.lua +++ b/lua/jdtls.lua @@ -35,7 +35,7 @@ local M = { --- ---@param config table configuration. See |vim.lsp.start_client| ---@param opts? jdtls.start.opts ----@param start_opts? lsp.StartOpts options passed to vim.lsp.start +---@param start_opts? vim.lsp.start.Opts options passed to vim.lsp.start ---@return integer|nil client_id function M.start_or_attach(config, opts, start_opts) return setup.start_or_attach(config, opts, start_opts) @@ -877,7 +877,6 @@ local function on_build_result(err, result, ctx) vim.fn.setqflist({}, 'r', { title = 'jdtls'; items = {} }) print('Compile successful') else - vim.tbl_add_reverse_lookup(CompileWorkspaceStatus) local project_config_errors = {} local compile_errors = {} local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id) @@ -899,7 +898,13 @@ local function on_build_result(err, result, ctx) local items = #project_config_errors > 0 and project_config_errors or compile_errors vim.fn.setqflist({}, 'r', { title = 'jdtls'; items = vim.diagnostic.toqflist(items) }) if #items > 0 then - print(string.format('Compile error. (%s)', CompileWorkspaceStatus[result])) + local reverse_status = { + [0] = "FAILED", + [1] = "SUCCEEDED", + [2] = "WITHERROR", + [3] = "CANCELLED", + } + print(string.format('Compile error. (%s)', reverse_status[result])) vim.cmd('copen') else print("Compile error, but no error diagnostics available." diff --git a/lua/jdtls/path.lua b/lua/jdtls/path.lua index 99c06fa..0352a56 100644 --- a/lua/jdtls/path.lua +++ b/lua/jdtls/path.lua @@ -5,6 +5,9 @@ local is_windows = vim.loop.os_uname().version:match('Windows') M.sep = is_windows and '\\' or '/' function M.join(...) + if vim.fs.joinpath then + return vim.fs.joinpath(...) + end local result = table.concat(vim.tbl_flatten {...}, M.sep):gsub(M.sep .. '+', M.sep) return result end diff --git a/lua/jdtls/setup.lua b/lua/jdtls/setup.lua index 7c78b7f..d954459 100644 --- a/lua/jdtls/setup.lua +++ b/lua/jdtls/setup.lua @@ -74,10 +74,9 @@ local function attach_to_active_buf(bufnr, client_name) return nil end - -function M.find_root(markers, bufname) - bufname = bufname or api.nvim_buf_get_name(api.nvim_get_current_buf()) - local dirname = vim.fn.fnamemodify(bufname, ':p:h') +local function find_root(source, markers) + source = source or api.nvim_buf_get_name(api.nvim_get_current_buf()) + local dirname = vim.fn.fnamemodify(source, ':p:h') local getparent = function(p) return vim.fn.fnamemodify(p, ':h') end @@ -92,6 +91,15 @@ function M.find_root(markers, bufname) end +function M.find_root(markers, bufname) + if vim.fs.root then + return vim.fs.root(bufname or 0, markers) + else + return find_root(bufname, markers) + end +end + + M.extendedClientCapabilities = { classFileContentsSupport = true, generateToStringPromptSupport = true,