Skip to content

Commit d51b2c9

Browse files
feat(apex_ls): add vim.lsp.config support #4081
1 parent 1f7fbc3 commit d51b2c9

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

lsp/apex_ls.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--- @brief
2+
---
3+
--- https://github.com/forcedotcom/salesforcedx-vscode
4+
---
5+
--- Language server for Apex.
6+
---
7+
--- For manual installation, download the JAR file from the [VSCode
8+
--- extension](https://github.com/forcedotcom/salesforcedx-vscode/tree/develop/packages/salesforcedx-vscode-apex) and adjust the `apex_jar_path` appropriately.
9+
---
10+
--- ```lua
11+
--- vim.lsp.config('apex_ls', {
12+
--- apex_jar_path = '/path/to/apex-jorje-lsp.jar',
13+
--- apex_enable_semantic_errors = false, -- Whether to allow Apex Language Server to surface semantic errors
14+
--- apex_enable_completion_statistics = false, -- Whether to allow Apex Language Server to collect telemetry on code completion usage
15+
--- }
16+
---```
17+
---
18+
--- Example configuration using Mason:
19+
---
20+
---```lua
21+
--- vim.lsp.config('apex_ls', {
22+
--- apex_jar_path = vim.fn.stdpath('data') .. '/mason/share/apex-language-server/apex-jorje-lsp.jar',
23+
--- }
24+
---```
25+
---
26+
--- For a complete experience, you may need to ensure the treesitter parsers for 'apex' are installed (:TSInstall apex) as well as configure the filetype for apex (*.cls) files:
27+
---
28+
--- ```lua
29+
--- vim.filetype.add({
30+
--- pattern = {
31+
--- ['.*/*.cls'] = 'apex',
32+
--- },
33+
--- })
34+
--- ```
35+
36+
---@type vim.lsp.Config
37+
return {
38+
cmd = function(dispatchers, config)
39+
local local_cmd = {
40+
vim.env.JAVA_HOME and (vim.env.JAVA_HOME .. '/bin/java') or 'java',
41+
'-cp',
42+
config.apex_jar_path,
43+
'-Ddebug.internal.errors=true',
44+
'-Ddebug.semantic.errors=' .. tostring(config.apex_enable_semantic_errors or false),
45+
'-Ddebug.completion.statistics=' .. tostring(config.apex_enable_completion_statistics or false),
46+
'-Dlwc.typegeneration.disabled=true',
47+
}
48+
if config.apex_jvm_max_heap then
49+
table.insert(local_cmd, '-Xmx' .. config.apex_jvm_max_heap)
50+
end
51+
table.insert(local_cmd, 'apex.jorje.lsp.ApexLanguageServerLauncher')
52+
53+
return vim.lsp.rpc.start(local_cmd, dispatchers)
54+
end,
55+
filetypes = { 'apex', 'apexcode' },
56+
root_markers = {
57+
'sfdx-project.json',
58+
},
59+
}

0 commit comments

Comments
 (0)