Skip to content

Commit 8a1171c

Browse files
committed
feat: add clean workspace command
1 parent 3282cd8 commit 8a1171c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lua/java/api/build.lua

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
local async = require('java-core.utils.async').sync
1+
local runner = require('async.runner')
22
local get_error_handler = require('java.handlers.error')
3+
local ui = require('java.utils.ui')
4+
local jdtls = require('java.utils.jdtls2')
35

46
local M = {}
57

@@ -14,7 +16,7 @@ function M.full_build_workspace(is_full_build)
1416

1517
is_full_build = type(is_full_build) == 'boolean' and is_full_build or true
1618

17-
return async(function()
19+
return runner(function()
1820
JdtlsClient(jdtls()):java_build_workspace(
1921
is_full_build,
2022
buf_util.get_curr_buf()
@@ -26,4 +28,25 @@ function M.full_build_workspace(is_full_build)
2628
.run()
2729
end
2830

31+
function M.clean_workspace()
32+
runner(function()
33+
local client = jdtls()
34+
35+
local workpace_path =
36+
vim.tbl_get(client, 'config', 'init_options', 'workspace')
37+
38+
local prompt = string.format('Do you want to delete "%s"', workpace_path)
39+
40+
local choice = ui.select(prompt, { 'Yes', 'No' })
41+
42+
if choice ~= 'Yes' then
43+
return
44+
end
45+
46+
vim.fn.delete(workpace_path, 'rf')
47+
end)
48+
.catch(get_error_handler('Failed to clean up the workspace'))
49+
.run()
50+
end
51+
2952
return M

lua/java/commands/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
local log = require('java.utils.log')
22
local notify = require('java-core.utils.notify')
3+
local ui = require('java.utils.ui')
4+
local get_error_handler = require('java.handlers.error')
5+
local runner = require('async.runner')
36

47
local M = {}
58

@@ -125,6 +128,10 @@ M.handlers = {
125128
[M.commands.COMPILE_WORKSPACE] = function(is_full_build)
126129
require('java.api.build').full_build_workspace(is_full_build)
127130
end,
131+
132+
[M.commands.CLEAN_WORKSPACE] = function()
133+
require('java.api.build').clean_workspace()
134+
end,
128135
}
129136

130137
local ignored_commands = { M.commands.REFRESH_BUNDLES_COMMAND }

0 commit comments

Comments
 (0)