java.lua 2.2 KB

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