Skip to content

Commit 982af13

Browse files
committed
feat: add build workspace API
1 parent 657e1c4 commit 982af13

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

doc/ts-to-lua-guide.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Personal Notes
2+
3+
## Communication
4+
5+
We are using `request` function of `vim.lsp.Client` function to communicate with
6+
the `jdtls`.
7+
8+
```lua
9+
fun(method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?`)
10+
```
11+
12+
This has almost 1 to 1 mapping with `vscode` APIs most of the time.
13+
14+
```typescript
15+
await this.languageClient.sendRequest(
16+
method: string,
17+
params: any,
18+
// handler is not passed since there is async / await
19+
// buffer I'm guessing is set to current buffer by default???
20+
);
21+
```
22+
23+
However, some APIs sends more arguments, to which we don't have a Neovim lua
24+
equivalent I'm guessing. Following is an example.
25+
26+
```typescript
27+
await this.languageClient.sendRequest(
28+
CompileWorkspaceRequest.type,
29+
isFullCompile,
30+
token,
31+
);
32+
```
33+
34+
To make this request, probably `client.rpc.request` should be used without
35+
`request()` wrapper.

lua/java-core/ls/clients/java-debug-client.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,12 @@ function DebugClient:start_debug_session()
7171
return self:workspace_execute_command('vscode.java.startDebugSession')
7272
end
7373

74-
---@enum CompileWorkspaceStatus
75-
DebugClient.CompileWorkspaceStatus = {
76-
FAILED = 0,
77-
SUCCEED = 1,
78-
WITHERROR = 2,
79-
CANCELLED = 3,
80-
}
81-
8274
---Build the workspace
8375
---@param main_class string
8476
---@param project_name? string
8577
---@param file_path? string
8678
---@param is_full_build boolean
87-
---@return CompileWorkspaceStatus # compiled status
79+
---@return java-core.CompileWorkspaceStatus # compiled status
8880
function DebugClient:build_workspace(
8981
main_class,
9082
project_name,

lua/java-core/ls/clients/jdtls-client.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ local class = require('java-core.utils.class')
33
local async = require('java-core.utils.async')
44
local await = async.wait_handle_error
55

6-
---@alias jdtls.RequestMethod
6+
---@alias java-core.JdtlsRequestMethod
77
---| 'workspace/executeCommand'
88
---| 'java/inferSelection'
99
---| 'java/getRefactorEdit'
10+
---| 'java/buildWorkspace'
1011

1112
---@alias jdtls.CodeActionCommand
1213
---| 'extractVariable'
@@ -55,7 +56,7 @@ function JdtlsClient:new(args)
5556
end
5657

5758
---Sends a LSP request
58-
---@param method jdtls.RequestMethod
59+
---@param method java-core.JdtlsRequestMethod
5960
---@param params lsp.ExecuteCommandParams
6061
---@param buffer? number
6162
function JdtlsClient:request(method, params, buffer)
@@ -124,6 +125,16 @@ function JdtlsClient:java_get_refactor_edit(
124125
return self:request('java/getRefactorEdit', params, buffer)
125126
end
126127

128+
---Compile the workspace
129+
---@param is_full_compile boolean if true, a complete full compile of the
130+
---workspace will be executed
131+
---@param buffer number
132+
---@return java-core.CompileWorkspaceStatus
133+
function JdtlsClient:java_build_workspace(is_full_compile, buffer)
134+
---@diagnostic disable-next-line: param-type-mismatch
135+
return self:request('java/buildWorkspace', is_full_compile, buffer)
136+
end
137+
127138
---Returns the decompiled class file content
128139
---@param uri string uri of the class file
129140
---@return string # decompiled file content

lua/java-core/types/jdtls-types.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
---@alias jdtls.RequestMethod
2-
---| 'workspace/executeCommand'
3-
---| 'java/inferSelection'
1+
local M = {}
2+
3+
---@enum java-core.CompileWorkspaceStatus
4+
M.CompileWorkspaceStatus = {
5+
FAILED = 0,
6+
SUCCEED = 1,
7+
WITHERROR = 2,
8+
CANCELLED = 3,
9+
}
10+
11+
return M

0 commit comments

Comments
 (0)