@@ -3,6 +3,37 @@ local class = require('java-core.utils.class')
3
3
local async = require (' java-core.utils.async' )
4
4
local await = async .wait_handle_error
5
5
6
+ --- @alias jdtls.RequestMethod
7
+ --- | ' workspace/executeCommand'
8
+ --- | ' java/inferSelection'
9
+ --- | ' java/getRefactorEdit'
10
+
11
+ --- @alias jdtls.CodeActionCommand
12
+ --- | ' extractVariable'
13
+ --- | ' assignVariable'
14
+ --- | ' extractVariableAllOccurrence'
15
+ --- | ' extractConstant'
16
+ --- | ' extractMethod'
17
+ --- | ' extractField'
18
+ --- | ' extractInterface'
19
+ --- | ' changeSignature'
20
+ --- | ' assignField'
21
+ --- | ' convertVariableToField'
22
+ --- | ' invertVariable'
23
+ --- | ' introduceParameter'
24
+ --- | ' convertAnonymousClassToNestedCommand' ) {
25
+
26
+ --- @class jdtls.RefactorWorkspaceEdit
27
+ --- @field edit lsp.WorkspaceEdit
28
+ --- @field command ? lsp.Command
29
+ --- @field errorMessage ? string
30
+
31
+ --- @class jdtls.SelectionInfo
32
+ --- @field name string
33
+ --- @field length number
34
+ --- @field offset number
35
+ --- @field params ? string[]
36
+
6
37
--- @class java-core.JdtlsClient
7
38
--- @field client LspClient
8
39
local JdtlsClient = class ()
@@ -23,44 +54,82 @@ function JdtlsClient:new(args)
23
54
return o
24
55
end
25
56
26
- --- Executes a workspace/executeCommand and returns the result
27
- --- @param command string
28
- --- @param arguments ? string | string[]
29
- --- @param buffer ? integer
30
- --- @return any
31
- function JdtlsClient :execute_command (command , arguments , buffer )
32
- log .debug (' executing: workspace/executeCommand - ' .. command )
33
-
34
- local cmd_info = {
35
- command = command ,
36
- arguments = arguments ,
37
- }
57
+ --- Sends a LSP request
58
+ --- @param method jdtls.RequestMethod
59
+ --- @param params lsp.ExecuteCommandParams
60
+ --- @param buffer ? number
61
+ function JdtlsClient :request (method , params , buffer )
62
+ log .debug (' sending LSP request: ' .. method )
38
63
39
64
return await (function (callback )
40
65
local on_response = function (err , result )
41
66
if err then
42
- log .error (command .. ' failed! arguments: ' , arguments , ' error: ' , err )
67
+ log .error (method .. ' failed! arguments: ' , params , ' error: ' , err )
43
68
else
44
- log .debug (command .. ' success! response: ' , result )
69
+ log .debug (method .. ' success! response: ' , result )
45
70
end
46
71
47
72
callback (err , result )
48
73
end
49
74
50
- return self .client .request (
51
- ' workspace/executeCommand' ,
52
- cmd_info ,
53
- on_response ,
54
- buffer
55
- )
75
+ return self .client .request (method , params , on_response , buffer )
56
76
end )
57
77
end
58
78
79
+ --- Executes a workspace/executeCommand and returns the result
80
+ --- @param command string workspace command to execute
81
+ --- @param params ? lsp.LSPAny[]
82
+ --- @param buffer ? integer
83
+ --- @return lsp.LSPAny
84
+ function JdtlsClient :workspace_execute_command (command , params , buffer )
85
+ return self :request (' workspace/executeCommand' , {
86
+ command = command ,
87
+ arguments = params ,
88
+ }, buffer )
89
+ end
90
+
91
+ --- Returns more information about the object the cursor is on
92
+ --- @param command jdtls.RequestMethod
93
+ --- @param params lsp.CodeActionParams
94
+ --- @param buffer ? number
95
+ --- @return jdtls.SelectionInfo[]
96
+ function JdtlsClient :java_infer_selection (command , params , buffer )
97
+ return self :request (' java/inferSelection' , {
98
+ command = command ,
99
+ context = params ,
100
+ }, buffer )
101
+ end
102
+
103
+ --- Returns refactor details
104
+ --- @param command jdtls.CodeActionCommand
105
+ --- @param context lsp.CodeActionParams
106
+ --- @param options lsp.FormattingOptions
107
+ --- @param command_arguments jdtls.SelectionInfo[] ;
108
+ --- @param buffer ? number
109
+ --- @return jdtls.RefactorWorkspaceEdit
110
+ function JdtlsClient :java_get_refactor_edit (
111
+ command ,
112
+ context ,
113
+ options ,
114
+ command_arguments ,
115
+ buffer
116
+ )
117
+ local params = {
118
+ command = command ,
119
+ context = context ,
120
+ options = options ,
121
+ commandArguments = command_arguments ,
122
+ }
123
+
124
+ return self :request (' java/getRefactorEdit' , params , buffer )
125
+ end
126
+
59
127
--- Returns the decompiled class file content
60
128
--- @param uri string uri of the class file
61
129
--- @return string # decompiled file content
62
130
function JdtlsClient :java_decompile (uri )
63
- return self :execute_command (' java.decompile' , { uri })
131
+ --- @type string
132
+ return self :workspace_execute_command (' java.decompile' , { uri })
64
133
end
65
134
66
135
function JdtlsClient :get_capability (...)
0 commit comments