java.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.api.nvim_set_keymap(
  19. "n",
  20. "<leader>la",
  21. ":lua require('jdtls').code_action()<CR>",
  22. { noremap = true, silent = true }
  23. )
  24. vim.api.nvim_set_keymap(
  25. "n",
  26. "<leader>lR",
  27. ":lua require('jdtls').code_action(false, 'refactor')<CR>",
  28. { noremap = true, silent = true }
  29. )
  30. vim.cmd "command! -buffer JdtCompile lua require('jdtls').compile()"
  31. vim.cmd "command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()"
  32. -- vim.cmd "command! -buffer JdtJol lua require('jdtls').jol()"
  33. vim.cmd "command! -buffer JdtBytecode lua require('jdtls').javap()"
  34. -- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"
  35. else
  36. local util = require "lspconfig/util"
  37. require("lspconfig").jdtls.setup {
  38. on_attach = require("lsp").common_on_attach,
  39. cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" },
  40. filetypes = { "java" },
  41. root_dir = util.root_pattern { ".git", "build.gradle", "pom.xml" },
  42. -- init_options = {bundles = bundles}
  43. -- on_attach = require'lsp'.common_on_attach
  44. }
  45. end
  46. -- local bundles = {
  47. -- vim.fn.glob(
  48. -- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
  49. -- };
  50. -- require('jdtls').start_or_attach({
  51. -- on_attach = on_attach,
  52. -- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
  53. -- root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
  54. -- init_options = {bundles = bundles}
  55. -- })
  56. -- TODO: setup autoformat stuff later
  57. -- _java = {
  58. -- -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
  59. -- {
  60. -- 'FileType', 'java',
  61. -- 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'
  62. -- }
  63. -- }