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,36 +2,42 @@ if require("lv-utils").check_lsp_client_active "jdtls" then
return return
end end
local util = require "lspconfig/util" if O.lang.java.java_tools.active then
-- In Vimscript print "hi"
-- augroup lsp -- find_root looks for parent directories relative to the current buffer containing one of the given arguments.
-- au! if vim.fn.has "mac" == 1 then
-- au FileType java lua require('jdtls').start_or_attach({cmd = {'java-linux-ls'}}) JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/java-mac-ls"
-- augroup end WORKSPACE_PATH = "/Users/" .. USER .. "/workspace/"
-- find_root looks for parent directories relative to the current buffer containing one of the given arguments. elseif vim.fn.has "unix" == 1 then
-- require'lspconfig'.jdtls.setup {cmd = {'java-linux-ls'}} JAVA_LS_EXECUTABLE = CONFIG_PATH .. "/utils/bin/java-linux-ls"
-- if vim.fn.has("mac") == 1 then WORKSPACE_PATH = "/home/" .. USER .. "/workspace/"
-- JAVA_LS_EXECUTABLE = 'java-mac-ls' else
-- elseif vim.fn.has("unix") == 1 then print "Unsupported system"
-- JAVA_LS_EXECUTABLE = 'java-linux-ls' end
-- else print(JAVA_LS_EXECUTABLE)
-- print("Unsupported system") print(WORKSPACE_PATH)
-- end
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 = { -- local bundles = {
-- vim.fn.glob( -- vim.fn.glob(
-- CONFIG_PATH.."/.debuggers/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar") -- 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({ -- require('jdtls').start_or_attach({
-- on_attach = on_attach, -- on_attach = on_attach,
-- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"}, -- cmd = {DATA_PATH .. "/lspinstall/java/jdtls.sh"},

View file

@ -2,6 +2,7 @@ CONFIG_PATH = vim.fn.stdpath "config"
DATA_PATH = vim.fn.stdpath "data" DATA_PATH = vim.fn.stdpath "data"
CACHE_PATH = vim.fn.stdpath "cache" CACHE_PATH = vim.fn.stdpath "cache"
TERMINAL = vim.fn.expand "$TERMINAL" TERMINAL = vim.fn.expand "$TERMINAL"
USER = vim.fn.expand "$USER"
O = { O = {
format_on_save = true, format_on_save = true,
@ -125,7 +126,11 @@ O = {
graphql = {}, graphql = {},
go = {}, go = {},
html = {}, html = {},
java = {}, java = {
java_tools = {
active = false,
},
},
json = { json = {
diagnostics = { diagnostics = {
virtual_text = { spacing = 0, prefix = "" }, virtual_text = { spacing = 0, prefix = "" },

View file

@ -313,6 +313,12 @@ return require("packer").startup(function(use)
"typescript.tsx", "typescript.tsx",
}, },
} }
use {
"mfussenegger/nvim-jdtls",
disable = not O.lang.java.java_tools.active,
}
-- use { -- use {
-- "jose-elias-alvarez/null-ls.nvim", -- "jose-elias-alvarez/null-ls.nvim",
-- ft = { -- ft = {

View file

@ -7,18 +7,51 @@
# If you're not using Linux you'll need to adjust the `-configuration` option # 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. # 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" case Darwin in
GRADLE_HOME=$HOME/gradle $HOME/.sdkman/candidates/java/current/bin/java \ 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 \ -Declipse.application=org.eclipse.jdt.ls.core.id1 \
-Dosgi.bundles.defaultStartLevel=4 \ -Dosgi.bundles.defaultStartLevel=4 \
-Declipse.product=org.eclipse.jdt.ls.core.product \ -Declipse.product=org.eclipse.jdt.ls.core.product \
-Dlog.protocol=true \ -Dlog.protocol=true \
-Dlog.level=ALL \ -Dlog.level=ALL \
-javaagent:/usr/local/share/lombok/lombok.jar \ -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \
-Xms1g \ -Xms1g \
-Xmx2G \ -Xmx2G \
-jar $(echo "$JAR") \ -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}" \ -data "${1:-$HOME/workspace}" \
--add-modules=ALL-SYSTEM \ --add-modules=ALL-SYSTEM \
--add-opens java.base/java.util=ALL-UNNAMED \ --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 # for older java versions if you wanna use lombok
# -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \ # -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \
# -javaagent:/usr/local/share/lombok/lombok.jar \