From 729ce253fddd6bc90af3c10ce6636dc1e3f44c0a Mon Sep 17 00:00:00 2001 From: HiPhish Date: Tue, 29 Sep 2020 17:49:12 +0200 Subject: JDT LS: add more root pattern files There are three common build systems for Java: Ant, Maven and Gradle. Each has its own configuration file, and this PR adds those files are root directory markers. --- lua/lspconfig/jdtls.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lspconfig/jdtls.lua b/lua/lspconfig/jdtls.lua index 6b4b909e..a9dd0488 100644 --- a/lua/lspconfig/jdtls.lua +++ b/lua/lspconfig/jdtls.lua @@ -25,6 +25,21 @@ local cmd = { "--add-opens java.base/java.lang=ALL-UNNAMED", } + +--- The presence of one of these files indicates a root directory. +-- +-- We search for configuration files of the most common Java build systems. We +-- could add more build systems, such as Make, but let's keep things simple for +-- now. +local root_files = { + 'build.xml', -- Ant + 'pom.xml', -- Maven + 'build.gradle', -- Gradle + 'build.gradle.kts', -- Gradle + 'settings.gradle', -- Gradle + 'settings.gradle.kts', -- Gradle +} + configs[server_name] = { default_config = { cmd = cmd, @@ -33,7 +48,11 @@ configs[server_name] = { GRADLE_HOME=vim.fn.getenv("GRADLE_HOME"), }, filetypes = { "java" }; - root_dir = util.root_pattern('.git'); + root_dir = function(fname) + return util.find_git_ancestor(fname) + or util.root_pattern(unpack(root_files))(fname) + or vim.call('getcwd') + end; init_options = { workspace = path.join { vim.loop.os_homedir(), "workspace" }; jvm_args = {}; -- cgit v1.2.3-70-g09d2 From 82286d9ddafac612fa4cc2547619cb6996df612b Mon Sep 17 00:00:00 2001 From: HiPhish Date: Tue, 29 Sep 2020 18:16:52 +0200 Subject: JDT LS: Add callback for language/status Added a callback for this custom notification. On large Java projects startup can take several seconds, so having feedback during that time is very useful. --- lua/lspconfig/jdtls.lua | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/jdtls.lua b/lua/lspconfig/jdtls.lua index a9dd0488..67b4de3d 100644 --- a/lua/lspconfig/jdtls.lua +++ b/lua/lspconfig/jdtls.lua @@ -32,14 +32,31 @@ local cmd = { -- could add more build systems, such as Make, but let's keep things simple for -- now. local root_files = { - 'build.xml', -- Ant - 'pom.xml', -- Maven - 'build.gradle', -- Gradle - 'build.gradle.kts', -- Gradle - 'settings.gradle', -- Gradle - 'settings.gradle.kts', -- Gradle + -- Single-module projects + { + 'build.xml', -- Ant + 'pom.xml', -- Maven + 'settings.gradle', -- Gradle + 'settings.gradle.kts', -- Gradle + }, + -- Multi-module projects + {'build.gradle', 'build.gradle.kts'}, } + +--- Callback function for the `language/status` notification. +-- +-- The server sends a non-standard notification when the status of the language +-- server changes. This can be used to display progress as the server is +-- starting up. +local function on_language_status(_, _, result) + local command = vim.api.nvim_command + command('echohl ModeMsg') + command(string.format('echo "%s"', result.message)) + command('echohl None') +end + + configs[server_name] = { default_config = { cmd = cmd, @@ -49,9 +66,11 @@ configs[server_name] = { }, filetypes = { "java" }; root_dir = function(fname) - return util.find_git_ancestor(fname) - or util.root_pattern(unpack(root_files))(fname) - or vim.call('getcwd') + for _, patterns in ipairs(root_files) do + local root = util.root_pattern(unpack(patterns))(fname) + if root then return root end + end + return vim.fn.getcwd() end; init_options = { workspace = path.join { vim.loop.os_homedir(), "workspace" }; @@ -81,7 +100,8 @@ configs[server_name] = { end handlers['textDocument/codeAction'](a, b, actions) - end + end; + ['language/status'] = vim.schedule_wrap(on_language_status) }; }; docs = { -- cgit v1.2.3-70-g09d2