mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-07-24 04:34:42 +02:00
update LSP get nvim-jdtls working with Java
This commit is contained in:
parent
51aa582272
commit
e26b5c51ed
8 changed files with 66 additions and 0 deletions
4
init.lua
4
init.lua
|
@ -38,4 +38,8 @@ else
|
||||||
require('lsp.lua-ls')
|
require('lsp.lua-ls')
|
||||||
require('lsp.bash-ls')
|
require('lsp.bash-ls')
|
||||||
require('lsp.js-ts-ls')
|
require('lsp.js-ts-ls')
|
||||||
|
-- require('lsp.java-ls')
|
||||||
|
require('lsp.python-ls')
|
||||||
|
require('lsp.json-ls')
|
||||||
|
require('lsp.yaml-ls')
|
||||||
end
|
end
|
||||||
|
|
15
lua/lsp/java-ls.lua
Normal file
15
lua/lsp/java-ls.lua
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-- 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
|
||||||
|
require('jdtls').start_or_attach({cmd = {JAVA_LS_EXECUTABLE}, root_dir = require('jdtls.setup').find_root({'gradle.build', 'pom.xml'})})
|
10
lua/lsp/json-ls.lua
Normal file
10
lua/lsp/json-ls.lua
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
-- npm install -g vscode-json-languageserver
|
||||||
|
require'lspconfig'.jsonls.setup {
|
||||||
|
commands = {
|
||||||
|
Format = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
lua/lsp/python-ls.lua
Normal file
2
lua/lsp/python-ls.lua
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
-- npm i -g pyright
|
||||||
|
require'lspconfig'.pyright.setup{}
|
2
lua/lsp/yaml-ls.lua
Normal file
2
lua/lsp/yaml-ls.lua
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
-- npm install -g yaml-language-server
|
||||||
|
require'lspconfig'.yamlls.setup{}
|
|
@ -103,3 +103,7 @@ xmap gc <Plug>VSCodeCommentary
|
||||||
nmap gc <Plug>VSCodeCommentary
|
nmap gc <Plug>VSCodeCommentary
|
||||||
omap gc <Plug>VSCodeCommentary
|
omap gc <Plug>VSCodeCommentary
|
||||||
nmap gcc <Plug>VSCodeCommentaryLine
|
nmap gcc <Plug>VSCodeCommentaryLine
|
||||||
|
|
||||||
|
" Simulate same TAB behavior in VSCode
|
||||||
|
nmap <Tab> :Tabnext<CR>
|
||||||
|
nmap <S-Tab> :Tabprev<CR>
|
||||||
|
|
|
@ -26,6 +26,7 @@ define_augroups(
|
||||||
{'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
{'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
||||||
{'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
{'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
||||||
{'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
{'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
|
||||||
|
{'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
28
utils/bin/java-linux-ls
Executable file
28
utils/bin/java-linux-ls
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/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/ls/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 \
|
||||||
|
-javaagent:/usr/local/share/lombok/lombok.jar \
|
||||||
|
-Xms1g \
|
||||||
|
-Xmx2G \
|
||||||
|
-jar $(echo "$JAR") \
|
||||||
|
-configuration "$HOME/.config/nvim/ls/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
|
||||||
|
|
||||||
|
# for older java versions if you wanna use lombok
|
||||||
|
# -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \
|
Loading…
Add table
Add a link
Reference in a new issue