From 47936f7267f156539a5c6d1ab96229a78fba74d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 4 Oct 2021 08:37:53 +0200 Subject: [PATCH] Add google-java-format for linting java --- symlinks/bin/google-java-format | 18 ++++++++++++++++++ symlinks/bin/javatoolinstall | 14 ++++++++++++++ symlinks/config/nvim/after/ftplugin/java.lua | 5 ----- symlinks/config/nvim/lua/lsp/jdtls_setup.lua | 2 +- 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100755 symlinks/bin/google-java-format create mode 100755 symlinks/bin/javatoolinstall diff --git a/symlinks/bin/google-java-format b/symlinks/bin/google-java-format new file mode 100755 index 0000000..02ccb5b --- /dev/null +++ b/symlinks/bin/google-java-format @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +JAR="$HOME/lsp/java/google-java-format/google-java-format.jar" + +if [[ ! -f $JAR ]]; then + echo "Google Java format is not installed! Install by running:" + echo "" + echo "javatoolinstall google-java-format" + exit 1 +fi + +java \ + --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ + -jar $JAR $@ diff --git a/symlinks/bin/javatoolinstall b/symlinks/bin/javatoolinstall new file mode 100755 index 0000000..407f742 --- /dev/null +++ b/symlinks/bin/javatoolinstall @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +TOOL=$1 +VERSION=$2 + +case $TOOL in + google-java-format) + if [ -z "$VERSION" ]; then + VERSION="v1.11.0" + fi + mkdir -p $HOME/lsp/java/google-java-format + wget -O - https://github.com/google/google-java-format/releases/download/v1.11.0/google-java-format-1.11.0-all-deps.jar > $HOME/lsp/java/google-java-format/google-java-format.jar + ;; +esac diff --git a/symlinks/config/nvim/after/ftplugin/java.lua b/symlinks/config/nvim/after/ftplugin/java.lua index a2032cb..71ecaa3 100644 --- a/symlinks/config/nvim/after/ftplugin/java.lua +++ b/symlinks/config/nvim/after/ftplugin/java.lua @@ -1,6 +1 @@ require('lsp.jdtls_setup').setup() - -vim.opt.shiftwidth = 4 -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.expandtab = true diff --git a/symlinks/config/nvim/lua/lsp/jdtls_setup.lua b/symlinks/config/nvim/lua/lsp/jdtls_setup.lua index 745b680..f4e966e 100644 --- a/symlinks/config/nvim/lua/lsp/jdtls_setup.lua +++ b/symlinks/config/nvim/lua/lsp/jdtls_setup.lua @@ -6,8 +6,8 @@ local common_config = require("lsp.server_config") local M = {} function M.setup() - require'jdtls.setup'.add_commands() require'jdtls'.setup_dap() + require'jdtls.setup'.add_commands() local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end