diff options
author | Chris <[email protected]> | 2021-07-09 01:37:03 -0400 |
---|---|---|
committer | Chris <[email protected]> | 2021-07-09 01:37:03 -0400 |
commit | d539ec951c1ccfd904afa0a1680d34a46619eea3 (patch) | |
tree | 6e2fa8ab009be2db33c514bc5a15e01b7bca8694 | |
parent | 1154032f64eec889e12d4e39ce141ed1bc8f4f28 (diff) |
java tool working on mac
-rw-r--r-- | ftplugin/java.lua | 54 | ||||
-rw-r--r-- | lua/default-config.lua | 7 | ||||
-rw-r--r-- | lua/plugins.lua | 6 | ||||
-rwxr-xr-x | utils/bin/java-mac-ls | 42 |
4 files changed, 80 insertions, 29 deletions
diff --git a/ftplugin/java.lua b/ftplugin/java.lua index 6feaa31e..a1a84ff4 100644 --- a/ftplugin/java.lua +++ b/ftplugin/java.lua @@ -2,36 +2,42 @@ if require("lv-utils").check_lsp_client_active "jdtls" then return end -local util = require "lspconfig/util" --- In Vimscript --- augroup lsp --- au! --- au FileType java lua require('jdtls').start_or_attach({cmd = {'java-linux-ls'}}) --- 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 O.lang.java.java_tools.active then + print "hi" + -- find_root looks for parent directories relative to the current buffer containing one of the given arguments. + if vim.fn.has "mac" == 1 then + JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/java-mac-ls" + WORKSPACE_PATH = "/Users/" .. USER .. "/workspace/" + elseif vim.fn.has "unix" == 1 then + JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/java-linux-ls" + WORKSPACE_PATH = "/home/" .. USER .. "/workspace/" + else + print "Unsupported system" + end + print(JAVA_LS_EXECUTABLE) + print(WORKSPACE_PATH) + + require("jdtls").start_or_attach { + cmd = { JAVA_LS_EXECUTABLE, WORKSPACE_PATH .. vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") }, + } +else + local util = require "lspconfig/util" + + require("lspconfig").jdtls.setup { + on_attach = require("lsp").common_on_attach, + 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 + } +end -- local bundles = { -- vim.fn.glob( -- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar") -- }; -require("lspconfig").jdtls.setup { - on_attach = require("lsp").common_on_attach, - 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"}, diff --git a/lua/default-config.lua b/lua/default-config.lua index ea2642c2..f9b4ec77 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -2,6 +2,7 @@ CONFIG_PATH = vim.fn.stdpath "config" DATA_PATH = vim.fn.stdpath "data" CACHE_PATH = vim.fn.stdpath "cache" TERMINAL = vim.fn.expand "$TERMINAL" +USER = vim.fn.expand "$USER" O = { format_on_save = true, @@ -125,7 +126,11 @@ O = { graphql = {}, go = {}, html = {}, - java = {}, + java = { + java_tools = { + active = false, + }, + }, json = { diagnostics = { virtual_text = { spacing = 0, prefix = "ï„‘" }, diff --git a/lua/plugins.lua b/lua/plugins.lua index baad82be..54117b71 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -313,6 +313,12 @@ return require("packer").startup(function(use) "typescript.tsx", }, } + + use { + "mfussenegger/nvim-jdtls", + disable = not O.lang.java.java_tools.active, + } + -- use { -- "jose-elias-alvarez/null-ls.nvim", -- ft = { diff --git a/utils/bin/java-mac-ls b/utils/bin/java-mac-ls index b7ad1700..952ddddc 100755 --- a/utils/bin/java-mac-ls +++ b/utils/bin/java-mac-ls @@ -7,18 +7,51 @@ # If you're not using Linux you'll need to adjust the `-configuration` option # to point to the `config_mac' or `config_win` folders depending on your system. -JAR="$HOME/.config/nvim/.language-servers/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar" -GRADLE_HOME=$HOME/gradle $HOME/.sdkman/candidates/java/current/bin/java \ +case Darwin in + Linux) + CONFIG="/Users/chris/.local/share/nvim/lspinstall/java/config_linux" + ;; + Darwin) + CONFIG="/Users/chris/.local/share/nvim/lspinstall/java/config_mac" + ;; +esac + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# JAR="$HOME/.config/nvim/.language-servers/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar" +JAR="/Users/chris/.local/share/nvim/lspinstall/java/plugins/org.eclipse.equinox.launcher_*.jar" +GRADLE_HOME=$HOME/gradle "$JAVACMD" \ -Declipse.application=org.eclipse.jdt.ls.core.id1 \ -Dosgi.bundles.defaultStartLevel=4 \ -Declipse.product=org.eclipse.jdt.ls.core.product \ -Dlog.protocol=true \ -Dlog.level=ALL \ - -javaagent:/usr/local/share/lombok/lombok.jar \ + -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \ -Xms1g \ -Xmx2G \ -jar $(echo "$JAR") \ - -configuration "$HOME/.config/nvim/.language-servers/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_mac" \ + -configuration "$CONFIG" \ -data "${1:-$HOME/workspace}" \ --add-modules=ALL-SYSTEM \ --add-opens java.base/java.util=ALL-UNNAMED \ @@ -27,3 +60,4 @@ GRADLE_HOME=$HOME/gradle $HOME/.sdkman/candidates/java/current/bin/java \ # for older java versions if you wanna use lombok # -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \ + # -javaagent:/usr/local/share/lombok/lombok.jar \ |