@@ -3,6 +3,37 @@ local class = require('java-core.utils.class')
33local async = require (' java-core.utils.async' )
44local await = async .wait_handle_error
55
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+
637--- @class java-core.JdtlsClient
738--- @field client LspClient
839local JdtlsClient = class ()
@@ -23,44 +54,82 @@ function JdtlsClient:new(args)
2354 return o
2455end
2556
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 )
3863
3964 return await (function (callback )
4065 local on_response = function (err , result )
4166 if err then
42- log .error (command .. ' failed! arguments: ' , arguments , ' error: ' , err )
67+ log .error (method .. ' failed! arguments: ' , params , ' error: ' , err )
4368 else
44- log .debug (command .. ' success! response: ' , result )
69+ log .debug (method .. ' success! response: ' , result )
4570 end
4671
4772 callback (err , result )
4873 end
4974
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 )
5676 end )
5777end
5878
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+
59127--- Returns the decompiled class file content
60128--- @param uri string uri of the class file
61129--- @return string # decompiled file content
62130function JdtlsClient :java_decompile (uri )
63- return self :execute_command (' java.decompile' , { uri })
131+ --- @type string
132+ return self :workspace_execute_command (' java.decompile' , { uri })
64133end
65134
66135function JdtlsClient :get_capability (...)
0 commit comments