فهرست منبع

feat(java): Replace the current custom installation of java, with lspinstall (#517)

Marek Filipowicz 4 سال پیش
والد
کامیت
a9e9047118
5فایلهای تغییر یافته به همراه40 افزوده شده و 27 حذف شده
  1. 2 0
      README.md
  2. 1 0
      init.lua
  3. 27 17
      lua/lsp/java-ls.lua
  4. 1 1
      lua/lv-autocommands/init.lua
  5. 9 9
      lua/lv-lspinstall/init.lua

+ 2 - 0
README.md

@@ -296,6 +296,8 @@ To install a supported language server:
 See [LspInstall](https://github.com/kabouzeid/nvim-lspinstall) for more
 info.
 
+In order for Java LSP to work, edit `~/.local/share/nvim/lspinstall/java/jdtls.sh` and replace `WORKSPACE="$1"` with `WORKSPACE="$HOME/workspace"`
+
 Most common languages should be supported out of the box, if yours is
 not I would welcome a PR
 

+ 1 - 0
init.lua

@@ -40,6 +40,7 @@ vim.cmd('source '..CONFIG_PATH..'/vimscript/functions.vim')
 
 -- LSP
 require('lsp')
+require('lsp.java-ls')
 require('lsp.angular-ls')
 require('lsp.bash-ls')
 require('lsp.clangd')

+ 27 - 17
lua/lsp/java-ls.lua

@@ -1,3 +1,4 @@
+local util = require 'lspconfig/util'
 -- In Vimscript
 -- augroup lsp
 --   au!
@@ -5,27 +6,36 @@
 -- augroup end
 -- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
 -- require'lspconfig'.jdtls.setup {cmd = {'java-linux-ls'}}
-if vim.fn.has("mac") == 1 then
-    JAVA_LS_EXECUTABLE = 'java-mac-ls'
-elseif vim.fn.has("unix") == 1 then
-    JAVA_LS_EXECUTABLE = 'java-linux-ls'
-else
-    print("Unsupported system")
-end
+-- if vim.fn.has("mac") == 1 then
+--     JAVA_LS_EXECUTABLE = 'java-mac-ls'
+-- elseif vim.fn.has("unix") == 1 then
+--     JAVA_LS_EXECUTABLE = 'java-linux-ls'
+-- else
+--     print("Unsupported system")
+-- end
 
-local bundles = {
-    vim.fn.glob(
-        CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
-};
+-- local bundles = {
+--     vim.fn.glob(
+--         CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
+-- };
 
 local on_attach = function(client, bufr)
-    require('jdtls').setup_dap()
+    -- require('jdtls').setup_dap()
     require'lsp'.common_on_attach(client, bufr)
 end
 
-require('jdtls').start_or_attach({
+require'lspconfig'.jdtls.setup {
     on_attach = on_attach,
-    cmd = {JAVA_LS_EXECUTABLE},
-    root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
-    init_options = {bundles = bundles}
-})
+    cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
+    filetypes = { "java" },
+    root_dir = util.root_pattern({'.git', 'build.gradle', 'pom.xml'}),
+    -- init_options = {bundles = bundles}
+    -- on_attach = require'lsp'.common_on_attach
+}
+
+-- require('jdtls').start_or_attach({
+--     on_attach = on_attach,
+--     cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},
+--     root_dir = require('jdtls.setup').find_root({'build.gradle', 'pom.xml', '.git'}),
+--     init_options = {bundles = bundles}
+-- })

+ 1 - 1
lua/lv-autocommands/init.lua

@@ -41,7 +41,7 @@ utils.define_augroups({
         -- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
     },
     _java = {
-        {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
+        -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
         {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'}
     },
     _go = {

+ 9 - 9
lua/lv-lspinstall/init.lua

@@ -5,15 +5,15 @@ require'lspconfig/configs'.jdtls = nil -- important, unset the loaded config aga
 -- config.default_config.cmd[1] = "./node_modules/.bin/bash-language-server"
 
 -- 2. extend the config with an install_script and (optionally) uninstall_script
-require'lspinstall/servers'.jdtls = vim.tbl_extend('error', config, {
-    -- lspinstall will automatically create/delete the install directory for every server
-    install_script = [[
-      git clone https://github.com/eclipse/eclipse.jdt.ls.git
-      cd eclipse.jdt.ls
-      ./mvnw clean verify
-  ]],
-    uninstall_script = nil -- can be omitted
-})
+-- require'lspinstall/servers'.jdtls = vim.tbl_extend('error', config, {
+--     -- lspinstall will automatically create/delete the install directory for every server
+--     install_script = [[
+--       git clone https://github.com/eclipse/eclipse.jdt.ls.git
+--       cd eclipse.jdt.ls
+--       ./mvnw clean verify
+--   ]],
+--     uninstall_script = nil -- can be omitted
+-- })
 
 require'lspinstall/servers'.kotlin = vim.tbl_extend('error', config, {
     install_script = [[