java.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. if require("lv-utils").check_lsp_client_active "jdtls" then
  2. return
  3. end
  4. if O.lang.java.java_tools.active then
  5. -- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
  6. if vim.fn.has "mac" == 1 then
  7. WORKSPACE_PATH = "/Users/" .. USER .. "/workspace/"
  8. elseif vim.fn.has "unix" == 1 then
  9. WORKSPACE_PATH = "/home/" .. USER .. "/workspace/"
  10. else
  11. print "Unsupported system"
  12. end
  13. JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/jdtls"
  14. require("jdtls").start_or_attach {
  15. on_attach = require("lsp").common_on_attach,
  16. cmd = { JAVA_LS_EXECUTABLE, WORKSPACE_PATH .. vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") },
  17. }
  18. vim.cmd "command! -buffer JdtCompile lua require('jdtls').compile()"
  19. vim.cmd "command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()"
  20. vim.cmd "command! -buffer JdtJol lua require('jdtls').jol()"
  21. vim.cmd "command! -buffer JdtBytecode lua require('jdtls').javap()"
  22. vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"
  23. else
  24. local util = require "lspconfig/util"
  25. require("lspconfig").jdtls.setup {
  26. on_attach = require("lsp").common_on_attach,
  27. cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" },
  28. filetypes = { "java" },
  29. root_dir = util.root_pattern { ".git", "build.gradle", "pom.xml" },
  30. -- init_options = {bundles = bundles}
  31. -- on_attach = require'lsp'.common_on_attach
  32. }
  33. end
  34. -- local bundles = {
  35. -- vim.fn.glob(
  36. -- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
  37. -- };
  38. -- require('jdtls').start_or_attach({
  39. -- on_attach = on_attach,
  40. -- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
  41. -- root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
  42. -- init_options = {bundles = bundles}
  43. -- })
  44. -- TODO setup autoformat stuff later
  45. -- _java = {
  46. -- -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
  47. -- {
  48. -- 'FileType', 'java',
  49. -- 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'
  50. -- }
  51. -- }