@@ -2,29 +2,38 @@ local class = require('java-core.utils.class')
22local notify = require (' java-core.utils.notify' )
33local JdtlsClient = require (' java-core.ls.clients.jdtls-client' )
44
5- --- @class java-refactor.ClientCommands
5+ --- @class java-refactor.RefactorCommands
66--- @field client vim.lsp.Client
7+ --- @field jdtls_client java-core.JdtlsClient
78local RefactorCommands = class ()
89
10+ --- @param client vim.lsp.Client
911function RefactorCommands :_init (client )
1012 self .client = client
1113 self .jdtls_client = JdtlsClient (client )
1214end
1315
14- function RefactorCommands :extract_variable ()
16+ --- Run refactor command
17+ --- @param refactor_type jdtls.CodeActionCommand
18+ function RefactorCommands :refactor (refactor_type )
1519 local context = vim .lsp .util .make_range_params (0 )
1620 context .context = {}
1721 context .context .diagnostics = vim .lsp .diagnostic .get_line_diagnostics (0 )
1822
23+ local formatting_options = {
24+ tabSize = vim .bo .tabstop ,
25+ insertSpaces = vim .bo .expandtab ,
26+ }
27+
1928 local buffer = vim .api .nvim_get_current_buf ()
2029
2130 local selection =
22- self .jdtls_client :java_infer_selection (' extractVariable ' , context , buffer )
31+ self .jdtls_client :java_infer_selection (refactor_type , context , buffer )
2332
2433 local edit = self .jdtls_client :java_get_refactor_edit (
25- ' extractVariable ' ,
34+ refactor_type ,
2635 context ,
27- {} ,
36+ formatting_options ,
2837 selection ,
2938 buffer
3039 )
@@ -38,6 +47,7 @@ function RefactorCommands:extract_variable()
3847end
3948
4049function RefactorCommands .run_lsp_client_command (command_name , arguments )
50+ -- vim.print(command_name, arguments)
4151 local command = vim .lsp .commands [command_name ]
4252
4353 if not command then
0 commit comments