From ea5371bf0de96dd6856ae623455376d6e2062045 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 14 Jul 2024 01:22:24 +0530 Subject: [PATCH 1/5] feat: add generate constructor code action --- lua/java/api/build.lua | 4 +-- lua/java/api/generate.lua | 55 ++++++++++++++++++++++++++++++++++++++ lua/java/api/refactor.lua | 1 - lua/java/commands/init.lua | 7 +++++ lua/java/utils/ui.lua | 53 +++++++++++++++++++++++++++++++++--- 5 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 lua/java/api/generate.lua diff --git a/lua/java/api/build.lua b/lua/java/api/build.lua index 292a153..73de525 100644 --- a/lua/java/api/build.lua +++ b/lua/java/api/build.lua @@ -7,7 +7,7 @@ local M = {} ---@param is_full_build? boolean ---@return number function M.full_build_workspace(is_full_build) - local JavaCoreJdtlsClient = require('java-core.ls.clients.jdtls-client') + local JdtlsClient = require('java-core.ls.clients.jdtls-client') local jdtls = require('java.utils.jdtls2') local buf_util = require('java.utils.buffer') local notify = require('java-core.utils.notify') @@ -15,7 +15,7 @@ function M.full_build_workspace(is_full_build) is_full_build = type(is_full_build) == 'boolean' and is_full_build or true return async(function() - JavaCoreJdtlsClient(jdtls()):java_build_workspace( + JdtlsClient(jdtls()):java_build_workspace( is_full_build, buf_util.get_curr_buf() ) diff --git a/lua/java/api/generate.lua b/lua/java/api/generate.lua new file mode 100644 index 0000000..244725e --- /dev/null +++ b/lua/java/api/generate.lua @@ -0,0 +1,55 @@ +local M = {} + +---@param params nvim.CodeActionParamsResponse +function M.generate_constructor(params) + local JdtlsClient = require('java-core.ls.clients.jdtls-client') + local async = require('java-core.utils.async').sync + local get_client = require('java.utils.jdtls2') + local get_error_handler = require('java.handlers.error') + local ui = require('java.utils.ui') + + return async(function() + local jdtls = JdtlsClient(get_client()) + local status = jdtls:java_check_constructors_status(params.params) + + if not status or not status.constructors then + return + end + + local selected_constructor = ui.select( + 'Select super class constructor(s).', + status.constructors, + function(constructor) + return string.format( + '%s %s', + constructor.name, + table.concat(constructor.parameters, ', ') + ) + end + ) + + if not selected_constructor then + return + end + + local selected_fields = ui.multi_select( + 'Select Fields:', + status.fields, + function(field) + return field.name + end + ) + + local edit = jdtls:java_generate_constructor({ + context = params.params, + constructors = { selected_constructor }, + fields = selected_fields or {}, + }) + + vim.lsp.util.apply_workspace_edit(edit, 'utf-8') + end) + .catch(get_error_handler('Generating constructor failed')) + .run() +end + +return M diff --git a/lua/java/api/refactor.lua b/lua/java/api/refactor.lua index 35bb211..8ab3b95 100644 --- a/lua/java/api/refactor.lua +++ b/lua/java/api/refactor.lua @@ -29,7 +29,6 @@ function M.convert_variable_to_field() M.extract('convertVariableToField') end ---- ---@param refactor_command jdtls.CodeActionCommand function M.extract(refactor_command) return async(function() diff --git a/lua/java/commands/init.lua b/lua/java/commands/init.lua index f260495..a5ad7fa 100644 --- a/lua/java/commands/init.lua +++ b/lua/java/commands/init.lua @@ -194,6 +194,13 @@ M.commands = { } M.handlers = { + ---@param _ lsp.Command + ---@param params nvim.CodeActionParamsResponse + [M.commands.GENERATE_CONSTRUCTORS_PROMPT] = function(_, params) + require('java.api.generate').generate_constructor(params) + end, + + ---@param is_full_build boolean [M.commands.COMPILE_WORKSPACE] = function(is_full_build) require('java.api.build').full_build_workspace(is_full_build) end, diff --git a/lua/java/utils/ui.lua b/lua/java/utils/ui.lua index cd86123..ece856e 100644 --- a/lua/java/utils/ui.lua +++ b/lua/java/utils/ui.lua @@ -1,6 +1,6 @@ -local async = require('java-core.utils.async') -local await = async.wait +local wait = require('async.waits.wait') local notify = require('java-core.utils.notify') +local List = require('java-core.utils.list') local M = {} @@ -11,7 +11,7 @@ local M = {} ---@param format_item? fun(item: T): string ---@return T function M.select(prompt, values, format_item) - return await(function(callback) + return wait(function(callback) vim.ui.select(values, { prompt = prompt, format_item = format_item, @@ -19,8 +19,53 @@ function M.select(prompt, values, format_item) end) end +function M.multi_select(prompt, values, format_item) + return wait(function(callback) + local wrapped_items = List:new(values):map(function(item, index) + return { + index = index, + is_selected = false, + value = item, + } + end) + + local open_select + + open_select = function() + vim.ui.select(wrapped_items, { + prompt = prompt, + format_item = function(item) + local prefix = item.is_selected and '* ' or '' + return prefix + .. (format_item and format_item(item.value) or item.value) + end, + }, function(selected) + if not selected then + local selected_items = wrapped_items + :filter(function(item) + return item.is_selected + end) + :map(function(item) + return item.value + end) + + callback(#selected_items > 0 and selected_items or nil) + return + end + + wrapped_items[selected.index].is_selected = + not wrapped_items[selected.index].is_selected + + open_select() + end) + end + + open_select() + end) +end + function M.input(prompt) - return await(function(callback) + return wait(function(callback) vim.ui.input({ prompt = prompt, }, callback) From 81f63c99ecd63e3d6cff9e0da6f03259b61c2c3f Mon Sep 17 00:00:00 2001 From: Srinesh Nisala Date: Sun, 14 Jul 2024 01:23:13 +0530 Subject: [PATCH 2/5] chore(doc): update readme (#264) --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b36acb7..f856563 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # :coffee: nvim-java +![Spring](https://img.shields.io/badge/Spring-6DB33F?style=for-the-badge&logo=spring&logoColor=white) ![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![Gradle](https://img.shields.io/badge/Gradle-02303A.svg?style=for-the-badge&logo=Gradle&logoColor=white) ![Apache Maven](https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white) @@ -17,12 +18,14 @@ Just install and start writing `public static void main(String[] args)`. ## :dizzy: Features -- :white_check_mark: Spring boot tools +- :white_check_mark: Spring Boot Tools - :white_check_mark: Diagnostics & Auto Completion - :white_check_mark: Automatic [DAP](https://github.com/mfussenegger/nvim-dap) debug configuration -- :white_check_mark: Running tests +- :white_check_mark: Organize Imports & Code Formatting +- :white_check_mark: Running Tests - :white_check_mark: Run & Debug profiles +- :white_check_mark: Code Actions ## :bulb: Why From 8452a5fca9a0442e8074c7499a02a1a4523df271 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 14 Jul 2024 01:25:46 +0530 Subject: [PATCH 3/5] chore(test): remove tests --- tests/java/api/profile_config_spec.lua | 422 ------------------------- tests/java/ui/profile_spec.lua | 405 ------------------------ 2 files changed, 827 deletions(-) delete mode 100644 tests/java/api/profile_config_spec.lua delete mode 100644 tests/java/ui/profile_spec.lua diff --git a/tests/java/api/profile_config_spec.lua b/tests/java/api/profile_config_spec.lua deleted file mode 100644 index e926651..0000000 --- a/tests/java/api/profile_config_spec.lua +++ /dev/null @@ -1,422 +0,0 @@ -local mock = require('luassert.mock') -local Profile = require('java.api.profile_config').Profile -local spy = require('luassert.spy') - -describe('java.api.profile_config', function() - local project_path = 'project_path' - local mock_fn = {} - local mock_io = {} - local file_mock = { - read = function(_, readmode) - assert(readmode == '*a') - return '{ "test": "test" }' - end, - close = function() end, - write = function() end, - } - - local json_encode = vim.fn.json_encode - local json_decode = vim.fn.json_decode - - before_each(function() - package.loaded['java.api.profile_config'] = nil - mock_io = mock(io, true) - mock_fn = mock(vim.fn, true) - - mock_fn.json_decode = function(data) - return json_decode(data) - end - - mock_fn.json_encode = function(data) - return json_encode(data) - end - - mock_fn.getcwd = function() - return project_path - end - - mock_fn.stdpath = function() - return 'config_path' - end - - mock_fn.expand = function() - return project_path - end - end) - - after_each(function() - mock.revert(mock_fn) - mock.revert(mock_io) - end) - - describe('read_config', function() - it('when no config file', function() - mock_io.open = function() - return nil - end - local profile_config = require('java.api.profile_config') - profile_config.setup() - assert.same(profile_config.get_all_profiles('module1 -> main_class'), {}) - end) - - it('when config cannot be decoded', function() - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{' - end - mock_io.open = function() - return file_mock - end - - local profile_config = require('java.api.profile_config') - profile_config.setup(project_path) - assert.same(profile_config.get_all_profiles('module1 -> main_class'), {}) - end) - - it('successfully', function() - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": \ - { \ - "module1 -> main_class": {\ - "profile_name1":{ \ - "vm_args": "vm_args",\ - "prog_args": "prog_args",\ - "name": "profile_name1",\ - "is_active": true }\ - } \ - }\ - }' - end - - mock_io.open = function(config_path, mode) - assert(config_path == 'config_path/nvim-java-profiles.json') - assert(mode == 'r') - return file_mock - end - - local profile_config = require('java.api.profile_config') - profile_config.setup(project_path) - assert.same(profile_config.get_all_profiles('module1 -> main_class'), { - profile_name1 = Profile('vm_args', 'prog_args', 'profile_name1', true), - }) - end) - end) - - describe('add_or_update_profile', function() - it('when updating profile', function() - local input_profile = - Profile('vm_args_updated', 'prog_args_updated', 'name', true) - - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": {\ - "module1 -> main_class": {\ - "profile_name1":{\ - "vm_args": "vm_args",\ - "prog_args": "prog_args",\ - "name": "name",\ - "is_active": true }\ - }\ - }\ - }' - end - - local spy_close = spy.on(file_mock, 'close') - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - profile_config.add_or_update_profile( - input_profile, - 'name', - 'module1 -> main_class' - ) - --- verify - assert.same( - { name = input_profile }, - profile_config.get_all_profiles('module1 -> main_class') - ) - assert.spy(spy_close).was_called(3) -- init, full_config, save - end) - end) - - it('when add new profile (set activate automatically)', function() - local input_profile = Profile('vm_args2', 'prog_args2', 'name2') - - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": { \ - "module1 -> main_class": [\ - { \ - "vm_args": "vm_args1",\ - "prog_args": "prog_args1",\ - "name": "name1",\ - "is_active": true }\ - ]\ - }\ - }' - end - - mock_fn.json_encode = function(data) - local expected1_id = 1 - local expected2_id = 2 - - if data.project_path['module1 -> main_class'][1].name == 'name2' then - expected1_id = 2 - expected2_id = 1 - end - - assert.same(data.project_path['module1 -> main_class'][expected1_id], { - vm_args = 'vm_args1', - prog_args = 'prog_args1', - name = 'name1', - is_active = false, - }) - assert.same(data.project_path['module1 -> main_class'][expected2_id], { - vm_args = 'vm_args2', - prog_args = 'prog_args2', - name = 'name2', - is_active = true, - }) - return json_encode(data) - end - - local spy_close = spy.on(file_mock, 'close') - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - profile_config.add_or_update_profile( - input_profile, - nil, - 'module1 -> main_class' - ) - - local expected_app_profiles_output = { - name1 = Profile('vm_args1', 'prog_args1', 'name1', false), - name2 = Profile('vm_args2', 'prog_args2', 'name2', true), - } - assert.same( - profile_config.get_all_profiles('module1 -> main_class'), - expected_app_profiles_output - ) - assert.spy(spy_close).was_called(3) -- init, full_config, save - end) - - it('when profile already exists', function() - -- setup - local input_profile = Profile('vm_args1', 'prog_args1', 'name1') - - -- mocks/verify mocks calls with expected values - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": { \ - "module1 -> main_class": {\ - "profile_name1":{\ - "vm_args": "vm_args1",\ - "prog_args": "prog_args1",\ - "name": "name1",\ - "is_active": true }\ - }\ - }\ - }' - end - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - assert.has.error(function() - profile_config.add_or_update_profile( - input_profile, - nil, - 'module1 -> main_class' - ) - end, "Profile with name 'name1' already exists") - end) - - it('when profile name is required', function() - -- setup - local input_profile = Profile('vm_args', 'prog_args', nil) - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - assert.has.error(function() - profile_config.add_or_update_profile( - input_profile, - nil, - 'module1 -> main_class' - ) - end, 'Profile name is required') - end) - - it('set_active_profile', function() - -- mocks/verify mocks calls with expected values - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": \ - { \ - "module1 -> main_class": [{ \ - "vm_args": "vm_args",\ - "prog_args": "prog_args",\ - "name": "name1",\ - "is_active": true \ - },\ - { \ - "vm_args": "vm_args",\ - "prog_args": "prog_args",\ - "name": "name2",\ - "is_active": false \ - }] \ - }\ - }' - end - - local spy_close = spy.on(file_mock, 'close') - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - profile_config.set_active_profile('name2', 'module1 -> main_class') - - --- verify - assert.same( - profile_config.get_active_profile('module1 -> main_class'), - Profile('vm_args', 'prog_args', 'name2', true) - ) - assert.spy(spy_close).was_called(3) -- init, full_config, save - end) - - it('get_profile_by_name', function() - -- setup - - -- mocks/verify mocks calls with expected values - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": \ - { \ - "module1 -> main_class": [{ \ - "vm_args": "vm_args1",\ - "prog_args": "prog_args1",\ - "name": "name1",\ - "is_active": true \ - },\ - { \ - "vm_args": "vm_args2",\ - "prog_args": "prog_args2",\ - "name": "name2",\ - "is_active": false \ - }] \ - }\ - }' - end - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - local profile = profile_config.get_profile('name1', 'module1 -> main_class') - --- verify - assert.same(profile, Profile('vm_args1', 'prog_args1', 'name1', true)) - end) - - describe('get_active_profile', function() - -- mocks/verify mocks calls with expected values - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": \ - { \ - "module1 -> main_class": [{ \ - "vm_args": "vm_args1",\ - "prog_args": "prog_args1",\ - "name": "name1",\ - "is_active": true \ - },\ - { \ - "vm_args": "vm_args2",\ - "prog_args": "prog_args2",\ - "name": "name2",\ - "is_active": false \ - }] \ - }\ - }' - end - - it('succesfully', function() - -- setup - mock_io.open = function() - return file_mock - end - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - local profile = profile_config.get_active_profile('module1 -> main_class') - - --- verify - assert.same(profile, Profile('vm_args1', 'prog_args1', 'name1', true)) - end) - - it('when number_of_profiles == 0', function() - -- setup - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": { "module1 -> main_class": [] } }' - end - - mock_io.open = function() - return file_mock - end - - -- call the function - local profile_config = require('java.api.profile_config') - profile_config.setup() - local profile = profile_config.get_active_profile('module1 -> main_class') - -- verify - assert(profile == nil) - end) - - it('when number_of_profiles > 0', function() - mock_io.open = function() - return file_mock - end - - file_mock.read = function(_, readmode) - assert(readmode == '*a') - return '{ "project_path": { "module1 -> main_class": [{ \ - "vm_args": "vm_args1",\ - "prog_args": "prog_args1",\ - "name": "name1",\ - "is_active": false \ - }] } }' - end - - local profile_config = require('java.api.profile_config') - profile_config.setup() - assert.has.error(function() - profile_config.get_active_profile('module1 -> main_class') - end, 'No active profile') - end) - end) -end) diff --git a/tests/java/ui/profile_spec.lua b/tests/java/ui/profile_spec.lua deleted file mode 100644 index 2c7b700..0000000 --- a/tests/java/ui/profile_spec.lua +++ /dev/null @@ -1,405 +0,0 @@ -local spy = require('luassert.spy') -local Menu = require('nui.menu') -local class = require('java-core.utils.class') - -describe('java.ui.profile', function() - local default_win_options = { - winhighlight = 'Normal:Normal,FloatBorder:Normal', - } - local default_style = 'single' - - -- profile_config mock - local profile_config = { - Profile = function(vm_args, prog_args, name, is_active) - return { - vm_args = vm_args, - prog_args = prog_args, - name = name, - is_active = is_active, - } - end, - get_profile = function() - return {} - end, - get_all_profiles = function() - return {} - end, - } - - -- notify mock - local notify = { - warn = function() end, - error = function() end, - } - - -- dap mock - local dap = { - config_dap = function() end, - } - - -- NuiMenu mock - local MockMenu = class() - function MockMenu:_init(table1, table2) - self.table1 = table1 - self.table2 = table2 - end - function MockMenu.on() end - function MockMenu.unmount() end - function MockMenu.map() end - function MockMenu.mount() end - - before_each(function() - package.loaded['java.api.profile_config'] = nil - package.loaded['java.ui.profile'] = nil - package.loaded['java-core.utils.notify'] = notify - end) - - it('get_tree_node_list_for_menu', function() - local expected_menu_items = { - Menu.item('name2 (active)'), - Menu.item('name'), - Menu.separator(), - Menu.item('New Profile'), - } - - profile_config.get_all_profiles = function() - return { - name = profile_config.Profile('vm_args', 'prog_args', 'name', false), - name2 = profile_config.Profile('vm_args2', 'prog_args2', 'name2', true), - } - end - package.loaded['java.api.profile_config'] = profile_config - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI('main_class') - local items = ui:get_tree_node_list_for_menu() - - for key, value in pairs(items) do - assert.same(expected_menu_items[key].text, value.text) - assert.same(expected_menu_items[key]._type, value._type) - end - end) - - it('get_menu', function() - package.loaded['nui.menu'] = MockMenu - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - ui.get_tree_node_list_for_menu = function() - return { menu_list = 'mock_menu_list' } - end - - local menu = ui:get_menu() - - assert.same(menu.table2.lines, { menu_list = 'mock_menu_list' }) - assert.same(menu.table1.border.text.top, '[Profiles]') - assert.same( - menu.table1.border.text.bottom, - '[a]ctivate [d]elete [b]ack [q]uit' - ) - assert(menu.table2.on_submit ~= nil) - end) - - describe('_get_and_fill_popup', function() - it('successfully', function() - local spy_nvim_api = spy.on(vim.api, 'nvim_buf_set_lines') - - profile_config.get_profile = function(name, main_class) - assert.same(name, 'target_profile') - assert.same(main_class, 'main_class') - return profile_config.Profile('vm_args', 'prog_args', 'name', false) - end - package.loaded['java.api.profile_config'] = profile_config - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI('main_class') - local popup = ui:_get_and_fill_popup('Title', 'name', 'target_profile') - - assert - .spy(spy_nvim_api) - .was_called_with(popup.bufnr, 0, -1, false, { 'name' }) - spy_nvim_api:revert() - - assert.same(popup.border._.text.top._content, '[Title]') - assert.same(popup.border._.text.top_align, 'center') - assert.same(popup.border._.winhighlight, default_win_options.winhighlight) - assert.same(popup.border._.style, default_style) - end) - - it('when target_profile is nil', function() - local spy_nvim_api = spy.on(vim.api, 'nvim_buf_set_lines') - profile_config.get_profile = function(_, _) - return profile_config.Profile('vm_args', 'prog_args', 'name', false) - end - package.loaded['java.api.profile_config'] = profile_config - - local profile_ui = require('java.ui.profile') - profile_ui.ProfileUI() - assert.spy(spy_nvim_api).was_not_called() - spy_nvim_api:revert() - end) - end) - - it('_open_profile_editor', function() - package.loaded['java.api.profile_config'] = profile_config - - -- mock popup - local MockPopup = class() - function MockPopup:_init(options) - self.border = options.border - self.enter = options.enter - self.win_options = options.win_options - self.bufnr = 1 - self.map_list = {} - end - - function MockPopup:map(mode, key, callback) - table.insert( - self.map_list, - { mode = mode, key = key, callback = callback } - ) - end - package.loaded['nui.popup'] = MockPopup - - -- mock layout - local MockLayout = class() - function MockLayout:_init(layout_settings, layout_box_list) - self.layout_settings = layout_settings - self.layout_box_list = layout_box_list - end - - local boxes = {} - function MockLayout.Box(box, options) - table.insert(boxes, { box = box, options = options }) - return {} - end - - function MockLayout.mount() end - local spy_mockLayout_mount = spy.on(MockLayout, 'mount') - - package.loaded['nui.layout'] = MockLayout - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - ui:_open_profile_editor('target_profile') - - -- verify Layout mount call - assert.spy(spy_mockLayout_mount).was_called() - - -- verify Layout.Box calls - assert.same(boxes[1].box.border.text.top, '[Name]') - assert.same(boxes[2].box.border.text.top, '[VM arguments]') - assert.same(boxes[3].box.border.text.top, '[Program arguments]') - assert.same(boxes[3].box.border.text.bottom, '[s]ave [b]ack [q]uit') - assert.same(boxes[3].box.border.text.bottom_align, 'center') - - assert.same(boxes[1].options, { grow = 0.2 }) - assert.same(boxes[2].options, { grow = 0.4 }) - assert.same(boxes[3].options, { grow = 0.4 }) - - -- loop in popup.map calls - for i = 1, 3 do - local list = boxes[i].box.map_list - -- verify keybindings - - -- actions - -- back - assert.same(list[1].mode, 'n') - assert.same(list[1].key, 'b') - assert(list[1].callback ~= nil) - - assert.same(list[2].mode, 'n') - assert.same(list[2].key, 'q') - assert(list[2].callback ~= nil) - - assert.same(list[3].mode, 'n') - assert.same(list[3].key, 's') - assert(list[3].callback ~= nil) - - -- navigation - assert.same(list[4].mode, 'n') - assert.same(list[4].key, '') - assert(list[4].callback ~= nil) - - assert.same(list[5].mode, 'n') - assert.same(list[5].key, 'k') - assert(list[5].callback ~= nil) - - assert.same(list[6].mode, 'n') - assert.same(list[6].key, 'j') - assert(list[6].callback ~= nil) - end - end) - - describe('_set_active_profile', function() - it('successfully', function() - -- mock profile_config - local new_profile = 'mock_new_profile' - profile_config.set_active_profile = function(name) - assert.same(name, new_profile) - end - package.loaded['java.api.profile_config'] = profile_config - package.loaded['java.api.dap'] = dap - - local spy_dap = spy.on(dap, 'config_dap') - local spy_mockMenu = spy.on(MockMenu, 'unmount') - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - -- set up mock in ui - ui.menu = MockMenu() - local openMenu_call = 0 - ui.openMenu = function() - openMenu_call = openMenu_call + 1 - end - ui.focus_item = { text = new_profile } - - -- call function - ui:_set_active_profile() - - --verify - assert.spy(spy_mockMenu).was_called() - assert.spy(spy_dap).was_called() - end) - - it('when selected profile is not modifiable', function() - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - ui._is_selected_profile_modifiable = function() - return false - end - ui:_set_active_profile() - end) - - it('when selected profile active', function() - local spy_notify = spy.on(notify, 'error') - local spy_profile_config = spy.on(profile_config, 'set_active_profile') - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - ui._is_selected_profile_modifiable = function() - return true - end - - ui.focus_item = { text = 'mock (active)' } - ui:_set_active_profile() - assert.spy(spy_notify).was_not_called() - assert.spy(spy_profile_config).was_not_called() - end) - end) - - describe('_delete_profile', function() - it('successfully', function() - -- mock profile_config - local new_profile = 'mock_new_profile' - profile_config.delete_profile = function(name) - assert.same(name, new_profile) - end - package.loaded['java.api.profile_config'] = profile_config - - local spy_mockMenu = spy.on(MockMenu, 'unmount') - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - -- set up mock in ui - ui.menu = MockMenu() - local openMenu_call = 0 - ui.openMenu = function() - openMenu_call = openMenu_call + 1 - end - ui.focus_item = { text = new_profile } - - -- call function - ui:_delete_profile() - - --verify - assert.spy(spy_mockMenu).was_called() - end) - - it('when selected profile is not modifiable', function() - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - ui._is_selected_profile_modifiable = function() - return false - end - ui:_delete_profile() - end) - - it('when selected profile active', function() - local spy_notify = spy.on(notify, 'warn') - local spy_profile_config = spy.on(profile_config, 'delete_profile') - - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - ui.focus_item = { text = 'mock (active)' } - ui:_delete_profile() - assert.spy(spy_notify).was_called_with('Cannot delete active profile') - assert.spy(spy_profile_config).was_not_called() - end) - end) - - describe('_is_selected_profile_modifiable when ', function() - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - - it('focus_item is nil', function() - ui:_is_selected_profile_modifiable() - assert.same(ui:_is_selected_profile_modifiable(), false) - end) - - it('focus_item.text is nil', function() - ui.focus_item = { text = nil } - ui:_is_selected_profile_modifiable() - assert.same(ui:_is_selected_profile_modifiable(), false) - end) - - it('focus_item.text is new_profile', function() - ui.focus_item = { text = 'New Profile' } - ui:_is_selected_profile_modifiable() - assert.same(ui:_is_selected_profile_modifiable(), false) - end) - end) - - it('openMenu', function() - -- mock Menu - local spy_on_mount = spy.on(MockMenu, 'mount') - local spy_on_map = spy.on(MockMenu, 'map') - -- mock profile_ui - local profile_ui = require('java.ui.profile') - local ui = profile_ui.ProfileUI() - ui.get_menu = function() - return MockMenu() - end - - ui:openMenu() - - assert.spy(spy_on_mount).was_called(1) - assert.spy(spy_on_map).was_called(4) - - -- verify keybindings - -- quit - assert.same(spy_on_map.calls[1].refs[2], 'n') - assert.same(spy_on_map.calls[1].refs[3], 'q') - assert(spy_on_map.calls[1].refs[4] ~= nil) - - -- back - assert.same(spy_on_map.calls[2].refs[2], 'n') - assert.same(spy_on_map.calls[2].refs[3], 'b') - assert(spy_on_map.calls[2].refs[4] ~= nil) - - -- set active profile - assert.same(spy_on_map.calls[3].refs[2], 'n') - assert.same(spy_on_map.calls[3].refs[3], 'a') - assert(spy_on_map.calls[3].refs[4] ~= nil) - - -- delete profile - assert.same(spy_on_map.calls[4].refs[2], 'n') - assert.same(spy_on_map.calls[4].refs[3], 'd') - assert(spy_on_map.calls[4].refs[4] ~= nil) - end) -end) From 48240e1c2937ea4e239ce5a88793c9980ec1900c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:27:01 +0530 Subject: [PATCH 4/5] chore(doc): automatic vimdoc update (#266) Co-authored-by: s1n7ax <18459807+s1n7ax@users.noreply.github.com> --- doc/nvim-java.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/nvim-java.txt b/doc/nvim-java.txt index 77231e2..93ea986 100644 --- a/doc/nvim-java.txt +++ b/doc/nvim-java.txt @@ -35,12 +35,14 @@ DEMO *nvim-java-demo* FEATURES *nvim-java-features* -- Spring boot tools +- Spring Boot Tools - Diagnostics & Auto Completion - Automatic DAP debug configuration -- Running tests +- Organize Imports & Code Formatting +- Running Tests - Run & Debug profiles +- Code Actions WHY *nvim-java-why* @@ -496,11 +498,12 @@ PROJECTS ACKNOWLEDGEMENT *nvim-java-projects-acknowledgement* ============================================================================== 2. Links *nvim-java-links* -1. *Java*: https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white -2. *Gradle*: https://img.shields.io/badge/Gradle-02303A.svg?style=for-the-badge&logo=Gradle&logoColor=white -3. *Apache Maven*: https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white -4. *Neovim*: https://img.shields.io/badge/NeoVim-%2357A143.svg?&style=for-the-badge&logo=neovim&logoColor=white -5. *Lua*: https://img.shields.io/badge/lua-%232C2D72.svg?style=for-the-badge&logo=lua&logoColor=white +1. *Spring*: https://img.shields.io/badge/Spring-6DB33F?style=for-the-badge&logo=spring&logoColor=white +2. *Java*: https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white +3. *Gradle*: https://img.shields.io/badge/Gradle-02303A.svg?style=for-the-badge&logo=Gradle&logoColor=white +4. *Apache Maven*: https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white +5. *Neovim*: https://img.shields.io/badge/NeoVim-%2357A143.svg?&style=for-the-badge&logo=neovim&logoColor=white +6. *Lua*: https://img.shields.io/badge/lua-%232C2D72.svg?style=for-the-badge&logo=lua&logoColor=white Generated by panvimdoc From e3ed314ca4076d70c05d996614c0ed243a6c64bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:28:46 +0530 Subject: [PATCH 5/5] chore(main): release 1.17.0 (#265) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e709018..8445c10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.17.0](https://github.com/nvim-java/nvim-java/compare/v1.16.0...v1.17.0) (2024-07-13) + + +### Features + +* add generate constructor code action ([ea5371b](https://github.com/nvim-java/nvim-java/commit/ea5371bf0de96dd6856ae623455376d6e2062045)) + ## [1.16.0](https://github.com/nvim-java/nvim-java/compare/v1.15.0...v1.16.0) (2024-07-13)