summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris <[email protected]>2021-03-13 00:39:49 -0500
committerChris <[email protected]>2021-03-13 00:39:49 -0500
commitd16093b4225477ef5d043b2722aa59318193efbf (patch)
tree894a4c53ec954d9abd31fad3ba44edbf230078e3
parentb68ac7c7b12559533801a4c4634d223eb3ece489 (diff)
beiginning java support
-rw-r--r--init.vim5
-rw-r--r--keys/which-key.vim24
-rw-r--r--lua/lsp-wrapper.vim10
-rw-r--r--lua/lsp/java-ls.lua8
-rw-r--r--plug-config/lsp-config.vim17
-rw-r--r--spell/en.utf-8.add11
-rw-r--r--spell/en.utf-8.add.splbin463 -> 564 bytes
-rwxr-xr-xutils/bin/java-linux-ls24
8 files changed, 98 insertions, 1 deletions
diff --git a/init.vim b/init.vim
index a12adaa2..836381f2 100644
--- a/init.vim
+++ b/init.vim
@@ -61,6 +61,7 @@ else
luafile ~/.config/nvim/lua/lsp/lua-ls.lua
luafile ~/.config/nvim/lua/lsp/python-ls.lua
luafile ~/.config/nvim/lua/lsp/bash-ls.lua
+ autocmd FileType java luafile ~/.config/nvim/lua/lsp/java-ls.lua
luafile ~/.config/nvim/lua/lsp/css-ls.lua
luafile ~/.config/nvim/lua/lsp/docker-ls.lua
luafile ~/.config/nvim/lua/lsp/graphql-ls.lua
@@ -84,3 +85,7 @@ endif
" fix space and tab triggering completion all the time
" Provide diagnostics for nvim tree
" port everything possible to lua
+ " augroup lsp
+ " au!
+ " au FileType java lua require('jdtls').start_or_attach({cmd = {'java-linux-ls'}})
+ " augroup end
diff --git a/keys/which-key.vim b/keys/which-key.vim
index 77c222a0..40f1b48e 100644
--- a/keys/which-key.vim
+++ b/keys/which-key.vim
@@ -138,6 +138,29 @@ let g:which_key_map.f = {
\ 'p' : [':Farr --source=rgnvim' , 'project'],
\ }
+" command! -buffer JdtCompile lua require('jdtls').compile()
+" command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()
+" command! -buffer JdtJol lua require('jdtls').jol()
+" command! -buffer JdtBytecode lua require('jdtls').javap()
+" command! -buffer JdtJshell lua require('jdtls').jshell()
+
+" j is for java
+let g:which_key_map.j = {
+ \ 'name' : '+java' ,
+ \ 'c' : [':AsyncTask file-compile' , 'compile file'],
+ \ 'b' : [':AsyncTask project-build' , 'build project'],
+ \ 'e' : [':AsyncTaskEdit' , 'edit local tasks'],
+ \ 'f' : [':AsyncTaskFzf' , 'find task'],
+ \ 'g' : [':AsyncTaskEdit!' , 'edit global tasks'],
+ \ 'h' : [':AsyncTaskList!' , 'list hidden tasks'],
+ \ 'l' : [':CocList tasks' , 'list tasks'],
+ \ 'm' : [':AsyncTaskMacro' , 'macro help'],
+ \ 'o' : [':copen' , 'open task view'],
+ \ 'r' : [':AsyncTask file-run' , 'run file'],
+ \ 'p' : [':AsyncTask project-run' , 'run project'],
+ \ 'x' : [':cclose' , 'close task view'],
+ \ }
+
" k is for task
let g:which_key_map.k = {
\ 'name' : '+task' ,
@@ -147,7 +170,6 @@ let g:which_key_map.k = {
\ 'f' : [':AsyncTaskFzf' , 'find task'],
\ 'g' : [':AsyncTaskEdit!' , 'edit global tasks'],
\ 'h' : [':AsyncTaskList!' , 'list hidden tasks'],
- \ 'l' : [':CocList tasks' , 'list tasks'],
\ 'm' : [':AsyncTaskMacro' , 'macro help'],
\ 'o' : [':copen' , 'open task view'],
\ 'r' : [':AsyncTask file-run' , 'run file'],
diff --git a/lua/lsp-wrapper.vim b/lua/lsp-wrapper.vim
index cd3dc165..ca400bb6 100644
--- a/lua/lsp-wrapper.vim
+++ b/lua/lsp-wrapper.vim
@@ -25,3 +25,13 @@ command! LspShowLineDiagnostics lua require 'lsp-wrapper'.show_line_diagnostics(
" command! LspIncomingCalls lua require 'lsp-wrapper'.incoming_calls()
" command! LspOutGoingCalls lua require 'lsp-wrapper'.outgoing_calls()
" command! LspDocumentHighlight lua require 'lsp-wrapper'.document_highlight()
+
+" Java
+
+" command! FileType java LspCodeAction <Esc><Cmd>lua require('jdtls').code_action(true)<CR>
+" command! FileType java LspCodeAction <Esc><Cmd>lua require('jdtls').code_action(false, 'refactor')<CR>
+
+" nnoremap <A-o> <Cmd>lua require'jdtls'.organize_imports()<CR>
+" nnoremap crv <Cmd>lua require('jdtls').extract_variable()<CR>
+" vnoremap crv <Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>
+" vnoremap crm <Esc><Cmd>lua require('jdtls').extract_method(true)<CR>
diff --git a/lua/lsp/java-ls.lua b/lua/lsp/java-ls.lua
new file mode 100644
index 00000000..689b71eb
--- /dev/null
+++ b/lua/lsp/java-ls.lua
@@ -0,0 +1,8 @@
+-- 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'}}
+require('jdtls').start_or_attach({cmd = {'java-linux-ls'}, root_dir = require('jdtls.setup').find_root({'gradle.build', 'pom.xml'})})
diff --git a/plug-config/lsp-config.vim b/plug-config/lsp-config.vim
index 82916f79..6c6d7cf3 100644
--- a/plug-config/lsp-config.vim
+++ b/plug-config/lsp-config.vim
@@ -17,3 +17,20 @@ autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100)
" autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
+" -- `code_action` is a superset of vim.lsp.buf.code_action and you'll be able to
+" -- use this mapping also with other language servers
+
+autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
+
+
+
+" -- If using nvim-dap
+" -- This requires java-debug and vscode-java-test bundles, see install steps in this README further below.
+" nnoremap <leader>df <Cmd>lua require'jdtls'.test_class()<CR>
+" nnoremap <leader>dn <Cmd>lua require'jdtls'.test_nearest_method()<CR>
+
+command! -buffer JdtCompile lua require('jdtls').compile()
+command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()
+command! -buffer JdtJol lua require('jdtls').jol()
+command! -buffer JdtBytecode lua require('jdtls').javap()
+command! -buffer JdtJshell lua require('jdtls').jshell()
diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add
index a6c6d7bc..c9f388b9 100644
--- a/spell/en.utf-8.add
+++ b/spell/en.utf-8.add
@@ -30,3 +30,14 @@ dir
efm
LuaRocks
LuaFormatter
+SDKMAN
+sdkman
+Gradle
+JVM
+java
+gradle
+kotlin
+springboot
+jdtls
+plugin
+linux
diff --git a/spell/en.utf-8.add.spl b/spell/en.utf-8.add.spl
index 82dc49e4..1b852204 100644
--- a/spell/en.utf-8.add.spl
+++ b/spell/en.utf-8.add.spl
Binary files differ
diff --git a/utils/bin/java-linux-ls b/utils/bin/java-linux-ls
new file mode 100755
index 00000000..a3a7d6ba
--- /dev/null
+++ b/utils/bin/java-linux-ls
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+# NOTE:
+# This doesn't work as is on Windows. You'll need to create an equivalent `.bat` file instead
+#
+# NOTE:
+# 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/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 \
+ -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 \
+ -Xms1g \
+ -Xmx2G \
+ -jar $(echo "$JAR") \
+ -configuration "$HOME/.config/nvim/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux" \
+ -data "${1:-$HOME/workspace}" \
+ --add-modules=ALL-SYSTEM \
+ --add-opens java.base/java.util=ALL-UNNAMED \
+ --add-opens java.base/java.lang=ALL-UNNAMED