Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move with_classpaths to util and make it public #318

Merged
merged 1 commit into from
Sep 8, 2022
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
26 changes: 1 addition & 25 deletions lua/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions lua/jdtls/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down