From efacec1c970c40d069b8fdbe5bd6999e96c1a08a Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Tue, 13 Dec 2022 22:47:16 +0100 Subject: [PATCH] Add context param to dap test methods Allows to set the buffer/window for which to trigger a test --- .luarc.json | 4 ++++ doc/jdtls.txt | 17 +++++++++++++---- lua/jdtls/dap.lua | 14 ++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .luarc.json diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..bc34f3a --- /dev/null +++ b/.luarc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", + "Lua.workspace.checkThirdParty": false +} diff --git a/doc/jdtls.txt b/doc/jdtls.txt index d3ce0a6..4ae9085 100644 --- a/doc/jdtls.txt +++ b/doc/jdtls.txt @@ -183,6 +183,14 @@ JdtSetupDapOpts *JdtSetupDapOpts* {hotcodereplace?} (string) "auto" +JdtDapContext *JdtDapContext* + + Fields: ~ + {bufnr} (number) + {win} (number) + {uri} (string) uri equal to vim.uri_from_bufnr(bufnr) + + JdtDapConfig *JdtDapConfig* Fields: ~ @@ -194,10 +202,11 @@ JdtDapConfig *JdtDapConfig* JdtTestOpts *JdtTestOpts* Fields: ~ - {config} (nil|table) Skeleton used for the |dap-configuration| - {config_overrides} (nil|JdtDapConfig) Overrides for the |dap-configuration|, see |JdtDapConfig| - {until_error} (number|nil) Number of times the test should be repeated if it doesn't fail - {after_test} (nil|function) Callback triggered after test run + {config} (nil|table) Skeleton used for the |dap-configuration| + {config_overrides} (nil|JdtDapConfig) Overrides for the |dap-configuration|, see |JdtDapConfig| + {until_error} (number|nil) Number of times the test should be repeated if it doesn't fail + {after_test} (nil|function) Callback triggered after test run + {context} (JdtDapContext|nil) context with bufnr/win in which the test is triggered vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/lua/jdtls/dap.lua b/lua/jdtls/dap.lua index b2b4051..164ab0f 100644 --- a/lua/jdtls/dap.lua +++ b/lua/jdtls/dap.lua @@ -323,6 +323,7 @@ local function make_config(lens, launch_args, config_overrides) end +---@return JdtDapContext local function make_context() local bufnr = api.nvim_get_current_buf() return { @@ -413,7 +414,7 @@ M.experimental = { --- @param opts JdtTestOpts|nil function M.test_class(opts) opts = opts or {} - local context = make_context() + local context = opts.context or make_context() fetch_candidates(context, function(lenses) local lens = get_first_class_lens(lenses) if not lens then @@ -432,8 +433,8 @@ end --- @param opts nil|JdtTestOpts function M.test_nearest_method(opts) opts = opts or {} - local lnum = api.nvim_win_get_cursor(0)[1] - local context = make_context() + local context = opts.context or make_context() + local lnum = api.nvim_win_get_cursor(context.win)[1] fetch_candidates(context, function(lenses) local lens = get_method_lens_above_cursor(lenses, lnum) if not lens then @@ -452,7 +453,7 @@ end ---@param opts nil|JdtTestOpts function M.pick_test(opts) opts = opts or {} - local context = make_context() + local context = opts.context or make_context() fetch_candidates(context, function(lenses) require('jdtls.ui').pick_one_async( lenses, @@ -611,6 +612,10 @@ end ---@field config_overrides JdtDapConfig These will be used as default overrides for |jdtls.dap.test_class|, |jdtls.dap.test_nearest_method| and discovered main classes ---@field hotcodereplace? string "auto" +---@class JdtDapContext +---@field bufnr number +---@field win number +---@field uri string uri equal to vim.uri_from_bufnr(bufnr) ---@class JdtDapConfig ---@field cwd string|nil working directory for the test @@ -622,5 +627,6 @@ end ---@field config_overrides nil|JdtDapConfig Overrides for the |dap-configuration|, see |JdtDapConfig| ---@field until_error number|nil Number of times the test should be repeated if it doesn't fail ---@field after_test nil|function Callback triggered after test run +---@field context JdtDapContext|nil context with bufnr/win in which the test is triggered return M