java tool working on mac

This commit is contained in:
Chris 2021-07-09 01:37:03 -04:00
parent 1154032f64
commit d539ec951c
4 changed files with 80 additions and 29 deletions

View file

@ -2,26 +2,26 @@ 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
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.
-- 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 = 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)
-- local bundles = {
-- vim.fn.glob(
-- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar")
-- };
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,
@ -31,6 +31,12 @@ require("lspconfig").jdtls.setup {
-- 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('jdtls').start_or_attach({
-- on_attach = on_attach,

View file

@ -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 = "" },

View file

@ -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 = {

View file

@ -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 \