Show error message from launch args response for debug class/method

This commit is contained in:
Mathias Fussenegger 2023-07-25 20:06:38 +02:00 committed by Mathias Fußenegger
parent 00078a1b9d
commit 095dc490f3

View file

@ -8,6 +8,9 @@ local with_java_executable = util.with_java_executable
local M = {}
local default_config_overrides = {}
---@diagnostic disable-next-line: deprecated
local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients
local function fetch_needs_preview(mainclass, project, cb, bufnr)
local params = {
command = 'vscode.java.checkProjectSettings',
@ -79,7 +82,7 @@ local function start_debug_adapter(callback, config)
return client.name == 'jdtls'
and client.config
and client.config.root_dir == config.cwd
end, vim.lsp.get_active_clients())[1]
end, get_clients())[1]
local bufnr = vim.lsp.get_buffers_by_client_id(jdtls and jdtls.id)[1] or vim.api.nvim_get_current_buf()
util.execute_command({command = 'vscode.java.startDebugSession'}, function(err0, port)
assert(not err0, vim.inspect(err0))
@ -173,7 +176,7 @@ local function fetch_candidates(context, on_candidates)
local params = {
arguments = { context.uri };
}
for _, c in pairs(vim.lsp.buf_get_clients()) do
for _, c in ipairs(get_clients({ bufnr = context.bufnr })) do
local command_provider = c.server_capabilities.executeCommandProvider
local commands = type(command_provider) == 'table' and command_provider.commands or {}
if vim.tbl_contains(commands, cmd_codelens) then
@ -236,6 +239,8 @@ local function fetch_launch_args(lens, context, on_launch_args)
error((
'Server must return launch_args as response to "vscode.java.test.junit.argument" command. '
.. 'Check server logs via `:JdtShowlogs`. Sent: ' .. vim.inspect(req_arguments)))
elseif launch_args.errorMessage then
vim.notify(launch_args.errorMessage, vim.log.levels.WARN)
else
-- forward/backward compat with format change in
-- https://github.com/microsoft/vscode-java-test/commit/5a78371ad60e86f858eace7726f0980926b6c31d
@ -274,7 +279,7 @@ local function get_method_lens_above_cursor(lenses_tree, lnum)
local line = range.start.line
local best_match_line
if result.best_match then
local best_match = result.best_match
local best_match = assert(result.best_match)
best_match_line = best_match.location and best_match.location.range.start.line or best_match.range.start.line
end
if is_method and line <= lnum and (best_match_line == nil or line > best_match_line) then
@ -335,10 +340,10 @@ local function make_config(lens, launch_args, config_overrides)
end
---@param bufnr? number
---@param bufnr? integer
---@return JdtDapContext
local function make_context(bufnr)
bufnr = (bufnr == nil or bufnr == 0) and api.nvim_get_current_buf() or bufnr
bufnr = assert((bufnr == nil or bufnr == 0) and api.nvim_get_current_buf() or bufnr)
return {
bufnr = bufnr,
uri = vim.uri_from_bufnr(bufnr)
@ -388,12 +393,12 @@ local function run(lens, config, context, opts)
dap.run(config, {
before = function(conf)
server = uv.new_tcp()
server = assert(uv.new_tcp(), "uv.new_tcp() must return handle")
test_results = junit.mk_test_results(context.bufnr)
server:bind('127.0.0.1', 0)
server:listen(128, function(err2)
assert(not err2, err2)
local sock = vim.loop.new_tcp()
local sock = assert(vim.loop.new_tcp(), "uv.new_tcp must return handle")
server:accept(sock)
sock:read_start(test_results.mk_reader(sock))
end)
@ -474,6 +479,7 @@ end
function M.pick_test(opts)
opts = opts or {}
local context = make_context(opts.bufnr)
fetch_candidates(context, function(lenses)
local candidates = {}
populate_candidates(candidates, lenses)
@ -517,9 +523,7 @@ function M.fetch_main_configs(opts, callback)
end
local configurations = {}
local bufnr = api.nvim_get_current_buf()
local jdtls = vim.tbl_filter(function(client)
return client.name == 'jdtls'
end, vim.lsp.buf_get_clients(bufnr))[1]
local jdtls = get_clients({ bufnr = bufnr, name = "jdtls"})[1]
local root_dir = jdtls and jdtls.config and jdtls.config.root_dir
util.execute_command({command = 'vscode.java.resolveMainClass'}, function(err, mainclasses)
assert(not err, vim.inspect(err))
@ -587,7 +591,7 @@ function M.setup_dap_main_class_configs(opts)
local dap_configurations = dap.configurations.java or {}
for _, config in ipairs(configurations) do
for i, existing_config in pairs(dap_configurations) do
if config.name == existing_config.name and config.cwd == existing_config.cwd then
if config.name == existing_config.name and config.cwd == existing_config["cwd"] then
table.remove(dap_configurations, i)
end
end