Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lsp/apex_ls.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--- @brief
---
--- https://github.com/forcedotcom/salesforcedx-vscode
---
--- Language server for Apex.
---
--- For manual installation, download the JAR file from the [VSCode
--- extension](https://github.com/forcedotcom/salesforcedx-vscode/tree/develop/packages/salesforcedx-vscode-apex) and adjust the `apex_jar_path` appropriately.
---
--- ```lua
--- vim.lsp.config('apex_ls', {
--- apex_jar_path = '/path/to/apex-jorje-lsp.jar',
--- apex_enable_semantic_errors = false, -- Whether to allow Apex Language Server to surface semantic errors
--- apex_enable_completion_statistics = false, -- Whether to allow Apex Language Server to collect telemetry on code completion usage
--- }
---```
---
--- Example configuration using Mason:
---
---```lua
--- vim.lsp.config('apex_ls', {
--- apex_jar_path = vim.fn.stdpath('data') .. '/mason/share/apex-language-server/apex-jorje-lsp.jar',
--- }
---```
---
--- 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:
---
--- ```lua
--- vim.filetype.add({
--- pattern = {
--- ['.*/*.cls'] = 'apex',
--- },
--- })
--- ```

---@type vim.lsp.Config
return {
cmd = function(dispatchers, config)
local local_cmd = {
vim.env.JAVA_HOME and (vim.env.JAVA_HOME .. '/bin/java') or 'java',
'-cp',
config.apex_jar_path,
Comment on lines +38 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach. And since cmd() gained the config arg, this is much more ergonomic. We should keep this is mind for other configs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't take any credit for that I'm afraid - the approach was shamefully pillaged from the biome config.

'-Ddebug.internal.errors=true',
'-Ddebug.semantic.errors=' .. tostring(config.apex_enable_semantic_errors or false),
'-Ddebug.completion.statistics=' .. tostring(config.apex_enable_completion_statistics or false),
'-Dlwc.typegeneration.disabled=true',
}
if config.apex_jvm_max_heap then
table.insert(local_cmd, '-Xmx' .. config.apex_jvm_max_heap)
end
table.insert(local_cmd, 'apex.jorje.lsp.ApexLanguageServerLauncher')

return vim.lsp.rpc.start(local_cmd, dispatchers)
end,
filetypes = { 'apex', 'apexcode' },
root_markers = {
'sfdx-project.json',
},
}