1- require (' java.commands' )
2-
31local decomple_watch = require (' java.startup.decompile-watcher' )
42local mason_dep = require (' java.startup.mason-dep' )
53local setup_wrap = require (' java.startup.lspconfig-setup-wrap' )
64local startup_check = require (' java.startup.startup-check' )
75
8- local test = require (' java.api.test' )
9- local dap = require (' java.api.dap' )
10- local runner = require (' java.api.runner' )
11- local profile_ui = require (' java.ui.profile' )
12- local refactor = require (' java.api.refactor' )
13- local build_api = require (' java.api.build' )
6+ local command_util = require (' java.utils.command' )
7+
8+ local test_api = require (' java.api.test' )
9+ local dap_api = require (' java.api.dap' )
10+ local runner_api = require (' java.api.runner' )
1411local settings_api = require (' java.api.settings' )
12+ local profile_ui = require (' java.ui.profile' )
1513
1614local global_config = require (' java.config' )
1715
@@ -36,70 +34,73 @@ function M.setup(custom_config)
3634
3735local is_installing = mason_dep .install (config )
3836
39- if not is_installing then
40- setup_wrap .setup (config )
41- decomple_watch .setup ()
42- dap .setup_dap_on_lsp_attach ()
37+ if is_installing then
38+ return
4339end
4440
41+ setup_wrap .setup (config )
42+ decomple_watch .setup ()
43+ dap_api .setup_dap_on_lsp_attach ()
44+
4545vim .api .nvim_exec_autocmds (
4646' User' ,
4747{pattern = ' JavaPostSetup' ,data = {config = config } }
4848)
4949end
5050
51- ---- ------------------------------------------------------------------
52- -- Experimental APIs --
53- ---- ------------------------------------------------------------------
54- M .build = {}
55- M .build .build_workspace = build_api .full_build_workspace
51+ --- @param path string[]
52+ --- @param command fun ()
53+ --- @param opts vim.api.keyset.user_command
54+ function M .register_api (path ,command ,opts )
55+ local name = command_util .path_to_command_name (path )
56+
57+ vim .api .nvim_create_user_command (name ,command ,opts or {})
58+
59+ local last_index = # path - 1
60+ local func_name = path [last_index ]
61+
62+ table.remove (path ,last_index )
63+
64+ local node = M
65+
66+ for _ ,v in ipairs (path )do
67+ if not node [v ]then
68+ node [v ]= {}
69+ end
70+
71+ node = node [v ]
72+ end
73+
74+ node [func_name ]= command
75+ end
5676
5777---- ------------------------------------------------------------------
5878-- DAP APIs --
5979---- ------------------------------------------------------------------
6080M .dap = {}
61- M .dap .config_dap = dap .config_dap
81+ M .dap .config_dap = dap_api .config_dap
6282
6383---- ------------------------------------------------------------------
6484-- Test APIs --
6585---- ------------------------------------------------------------------
6686M .test = {}
67- M .test .run_current_class = test .run_current_class
68- M .test .debug_current_class = test .debug_current_class
87+ M .test .run_current_class = test_api .run_current_class
88+ M .test .debug_current_class = test_api .debug_current_class
6989
70- M .test .run_current_method = test .run_current_method
71- M .test .debug_current_method = test .debug_current_method
90+ M .test .run_current_method = test_api .run_current_method
91+ M .test .debug_current_method = test_api .debug_current_method
7292
73- M .test .view_last_report = test .view_last_report
74-
75- ---- ------------------------------------------------------------------
76- -- Manipulate --
77- ---- ------------------------------------------------------------------
78-
79- M .manipulate = {}
80- -- M.manipulate.organize_imports = {}
81-
82- ---- ------------------------------------------------------------------
83- -- Refactor --
84- ---- ------------------------------------------------------------------
85- M .refactor = {}
86- M .refactor .extract_variable = refactor .extract_variable
87- M .refactor .extract_constant = refactor .extract_constant
88- M .refactor .extract_method = refactor .extract_method
89- M .refactor .extract_field = refactor .extract_field
90- M .refactor .convert_variable_to_field = refactor .convert_variable_to_field
91- M .refactor .extract_variable_all_occurrence =
92- refactor .extract_variable_all_occurrence
93+ M .test .view_last_report = test_api .view_last_report
9394
9495---- ------------------------------------------------------------------
9596-- Runner APIs --
9697---- ------------------------------------------------------------------
9798M .runner = {}
9899M .runner .built_in = {}
99- M .runner .built_in .run_app = runner .built_in .run_app
100- M .runner .built_in .toggle_logs = runner .built_in .toggle_logs
101- M .runner .built_in .stop_app = runner .built_in .stop_app
102- M .runner .built_in .switch_app = runner .built_in .switch_app
100+ M .runner .built_in .run_app = runner_api .built_in .run_app
101+ M .runner .built_in .toggle_logs = runner_api .built_in .toggle_logs
102+ M .runner .built_in .stop_app = runner_api .built_in .stop_app
103+ M .runner .built_in .switch_app = runner_api .built_in .switch_app
103104
104105---- ------------------------------------------------------------------
105106-- Profile UI --
@@ -113,8 +114,4 @@ M.profile.ui = profile_ui.ui
113114M .settings = {}
114115M .settings .change_runtime = settings_api .change_runtime
115116
116- function M .__run ()
117- test .debug_current_method ()
118- end
119-
120117return M