From 94e2840e9274832fb2693d60a911d0e21b1baae8 Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 7 Sep 2022 10:25:37 -0400 Subject: [PATCH] Move with_classpaths to util and make it public --- lua/jdtls.lua | 26 +------------------------- lua/jdtls/util.lua | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lua/jdtls.lua b/lua/jdtls.lua index 8452658..5d35d06 100644 --- a/lua/jdtls.lua +++ b/lua/jdtls.lua @@ -6,6 +6,7 @@ local ui = require('jdtls.ui') local util = require('jdtls.util') local with_java_executable = util.with_java_executable +local with_classpaths = util.with_classpaths local resolve_classname = util.resolve_classname local execute_command = util.execute_command @@ -792,31 +793,6 @@ M.extract_variable = mk_extract('extractVariable') M.extract_method = mk_extract('extractMethod') -local function with_classpaths(fn) - local is_test_file_cmd = { - command = 'java.project.isTestFile', - arguments = { vim.uri_from_bufnr(0) } - }; - execute_command(is_test_file_cmd, function(err, is_test_file) - assert(not err, vim.inspect(err)) - local options = vim.fn.json_encode({ - scope = is_test_file and 'test' or 'runtime'; - }) - local cmd = { - command = 'java.project.getClasspaths'; - arguments = { vim.uri_from_bufnr(0), options }; - } - execute_command(cmd, function(err1, resp) - if err1 then - print('Error executing java.project.getClasspaths: ' .. err1.message) - else - fn(resp) - end - end) - end) -end - - --- Run the `javap` tool in a terminal buffer. --- Sets the classpath based on the current project. function M.javap() diff --git a/lua/jdtls/util.lua b/lua/jdtls/util.lua index 9cf9304..ed073dc 100644 --- a/lua/jdtls/util.lua +++ b/lua/jdtls/util.lua @@ -56,6 +56,31 @@ function M.with_java_executable(mainclass, project, fn, bufnr) end +function M.with_classpaths(fn) + local is_test_file_cmd = { + command = 'java.project.isTestFile', + arguments = { vim.uri_from_bufnr(0) } + }; + M.execute_command(is_test_file_cmd, function(err, is_test_file) + assert(not err, vim.inspect(err)) + local options = vim.fn.json_encode({ + scope = is_test_file and 'test' or 'runtime'; + }) + local cmd = { + command = 'java.project.getClasspaths'; + arguments = { vim.uri_from_bufnr(0), options }; + } + M.execute_command(cmd, function(err1, resp) + if err1 then + print('Error executing java.project.getClasspaths: ' .. err1.message) + else + fn(resp) + end + end) + end) +end + + function M.resolve_classname() local lines = api.nvim_buf_get_lines(0, 0, -1, true) local pkgname