repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: next attempt to configure neovim for java...

5d760c08dddcd846e38b4c51a9b843901d3b51e5

Oliver Krylow <o.krylow@isp-insoft.de> ยท

unsigned

Browse filesCompare with HEAD

Changed files (5)

neovim/after/ftplugin/java.lua

Deleted
deleted file mode 100644
1 -local puk = require 'std.puk'
2 -local project = require 'std.project'
4 -puk.defer 'jdtls' (function(jdtls)
5 - local cfg = {
6 - -- The command that starts the language server
7 - -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
8 - cmd = {
9 - -- ๐Ÿ’€
10 - 'java', -- or '/path/to/java17_or_newer/bin/java'
11 - -- depends on if `java` is in your $PATH env variable and if it points to the right version.
13 - '-Declipse.application=org.eclipse.jdt.ls.core.id1',
14 - '-Dosgi.bundles.defaultStartLevel=4',
15 - '-Declipse.product=org.eclipse.jdt.ls.core.product',
16 - '-Dlog.protocol=true',
17 - '-Dlog.level=ALL',
18 - '-Xmx1g',
19 - '--add-modules=ALL-SYSTEM',
20 - '--add-opens', 'java.base/java.util=ALL-UNNAMED',
21 - '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
23 - -- ๐Ÿ’€
24 - '-jar', '/path/to/jdtls_install_location/plugins/org.eclipse.equinox.launcher_VERSION_NUMBER.jar',
25 - -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
26 - -- Must point to the Change this to
27 - -- eclipse.jdt.ls installation the actual version
30 - -- ๐Ÿ’€
31 - '-configuration', '/path/to/jdtls_install_location/config_SYSTEM',
32 - -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
33 - -- Must point to the Change to one of `linux`, `win` or `mac`
34 - -- eclipse.jdt.ls installation Depending on your system.
37 - -- ๐Ÿ’€
38 - -- See `data directory configuration` section in the README
39 - '-data', '/path/to/unique/per/project/workspace/folder'
40 - },
41 - root_dir = project.find_java_project_root(),
42 - -- Here you can configure eclipse.jdt.ls specific settings
43 - -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
44 - -- for a list of options
45 - settings = {
46 - java = {
47 - --TODO: gnerate list of runtimes?
48 - configuration = {
49 - -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
50 - -- And search for `interface RuntimeOption`
51 - -- The `name` is NOT arbitrary, but must match one of the elements from `enum ExecutionEnvironment` in the link above
52 - runtimes = {
53 - {
54 - name = "JavaSE-11",
55 - path = "/usr/lib/jvm/java-11-openjdk/",
56 - },
57 - {
58 - name = "JavaSE-17",
59 - path = "/usr/lib/jvm/java-17-openjdk/",
60 - },
61 - }
62 - }
63 - }
64 - },
65 - -- Language server `initializationOptions`
66 - -- You need to extend the `bundles` with paths to jar files
67 - -- if you want to use additional eclipse.jdt.ls plugins.
68 - --
69 - -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
70 - init_options = {
71 - --TODO: add java-debug and vscode-java-test extensions
72 - bundles = {}
73 - },
74 - }
76 - -- TODO: convert to lua
77 - -- nnoremap <A-o> <Cmd>lua require'jdtls'.organize_imports()<CR>
78 - -- nnoremap crv <Cmd>lua require('jdtls').extract_variable()<CR>
79 - -- vnoremap crv <Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>
80 - -- nnoremap crc <Cmd>lua require('jdtls').extract_constant()<CR>
81 - -- vnoremap crc <Esc><Cmd>lua require('jdtls').extract_constant(true)<CR>
82 - -- vnoremap crm <Esc><Cmd>lua require('jdtls').extract_method(true)<CR>
83 - -- TODO: start using nvim-dap
84 - -- " This requires java-debug and vscode-java-test bundles, see install steps in this README further below.
85 - -- nnoremap <leader>df <Cmd>lua require'jdtls'.test_class()<CR>
86 - -- nnoremap <leader>dn <Cmd>lua require'jdtls'.test_nearest_method()<CR>
88 - --TODO: enable jdtls when config is ready
89 - -- jdtls.start_or_attach(cfg)
90 - vim.notify(vim.inspect(cfg))
91 -end)

neovim/init.lua

Modified
43 43 require 'bugabinga.save_actions'
44 44 -- i tried scheduling this, but it leads to no lsp being initially loaded, until i resource the file
45 45 require 'bugabinga.lsp'
46 +require 'bugabinga.java'
46 47 vim.schedule( function ()
47 48 require 'bugabinga.in_and_out'
48 49 require 'bugabinga.mkdir'

neovim/lua/bugabinga/java.lua

Added
new file mode 100644
1 +local puk = require 'std.puk'
2 +local project = require 'std.project'
3 +local auto = require 'std.auto'
5 +local function parse_toolchains( toolchains_path )
6 + local runtimes = {}
7 + local file = io.open( toolchains_path, 'r' )
8 + if not file then
9 + print( 'Could not open toolchains.xml at ' .. toolchains_path )
10 + return runtimes
11 + end
13 + local content = file:read '*all'
14 + file:close()
16 + for toolchain in content:gmatch '<toolchain>(.-)</toolchain>' do
17 + local type = toolchain:match '<type>(.-)</type>'
18 + if type == 'jdk' then
19 + local version = toolchain:match '<version>(.-)</version>'
20 + local jdk_path = toolchain:match '<home>(.-)</home>'
21 + if version and jdk_path then
22 + table.insert( runtimes, {
23 + name = 'JavaSE-' .. version,
24 + path = jdk_path,
25 + } )
26 + end
27 + end
28 + end
30 + return runtimes
31 +end
33 +local data_path = vim.fn.stdpath 'data'
34 +if type( data_path ) == 'table' then
35 + data_path = data_path[1]
36 +end
37 +local home = vim.fs.abspath '~'
38 +local jdtls_install_path = vim.fs.joinpath( home, 'Tools', 'jdt-language-server-1.47.0-202504100338' )
39 +local toolchain_path = vim.fs.joinpath( home, '.m2', 'toolchains.xml' )
40 +local jdtls_path = vim.fs.joinpath( jdtls_install_path, 'plugins',
41 + 'org.eclipse.equinox.launcher_1.7.0.v20250404-1055.jar' )
43 +local create_config = function ( syntax_server_mode, path )
44 + local root_dir = project.find_java_project_root( path )
45 + local jdlts_config_dir
46 + if syntax_server_mode then
47 + jdlts_config_dir = vim.fn.has 'win32' and 'config_ss_win' or 'config_ss_linux'
48 + else
49 + jdlts_config_dir = vim.fn.has 'win32' and 'config_win' or 'config_linux'
50 + end
51 + local config_dir = vim.fs.joinpath( jdtls_install_path, jdlts_config_dir )
52 + local workspace_dir = vim.fs.joinpath( data_path, 'jdtls-workspace', vim.fs.basename( root_dir ) )
54 + local cmd = {
55 + 'java',
56 + '-Declipse.application=org.eclipse.jdt.ls.core.id1',
57 + '-Dosgi.bundles.defaultStartLevel=4',
58 + '-Declipse.product=org.eclipse.jdt.ls.core.product',
59 + '-Dlog.level=ERROR',
60 + '-Xmx8G',
61 + '-XX:+UseG1GC',
62 + '--add-modules=ALL-SYSTEM',
63 + '--add-opens', 'java.base/java.util=ALL-UNNAMED',
64 + '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
65 + '-jar', jdtls_path,
66 + '-configuration', config_dir,
67 + '-data', workspace_dir,
68 + }
70 + if syntax_server_mode then
71 + table.insert( cmd, 2, '-Dsyntaxserver=true' )
72 + end
74 + local runtimes = parse_toolchains( toolchain_path )
75 + local config = {
76 + name = syntax_server_mode and 'jdtlsss' or 'jdtls',
77 + cmd = cmd,
78 + root_dir = root_dir,
79 + settings = {
80 + java = {
81 + signatureHelp = { enabled = true },
82 + sources = {
83 + autobuild = { enabled = true },
84 + signatureHelp = { enabled = true },
85 + saveActions = { origanizeImports = true },
86 + organizeImports = {
87 + starThreshold = 9999,
88 + staticStarThreshold = 9999,
89 + },
90 + codeGeneration = {
91 + toString = {
92 + template = '${object.className}{${member.name()}=${member.value()}, ${otherMembers}}',
93 + },
94 + hashCodeEquals = { useJava7Objects = true },
95 + useBlocks = true,
96 + },
97 + eclipse = { downloadSources = true },
98 + },
99 + configuration = {
100 + updateBuildConfiguration = 'interactive',
101 + runtimes = runtimes,
102 + },
103 + maven = { downloadSources = true },
104 + implementationsCodeLens = { enabled = true },
105 + referencesCodeLens = { enabled = true },
106 + references = { includeDecompiledSources = true },
107 + inlayHints = { parameterNames = { enabled = 'all' } },
108 + format = { enabled = true },
109 + },
110 + },
111 + handlers = {
112 + ['language/status'] = function ( _, status )
113 + if status.message == 'ServiceReady' and not syntax_server_mode then
114 + -- TODO stop syntax server
115 + end
116 + end,
117 + },
119 + return config
120 +end
122 +auto 'start_jdtls' {
123 + pattern = 'java',
124 + events = 'FileType',
125 + description = 'Starts jdlts (with syntax mode initially)',
126 + command = function ()
127 + local path = vim.api.nvim_buf_get_name( 0 )
128 + puk 'jdtls'.start_or_attach( create_config( true, path ) )
129 + puk 'jdtls'.start_or_attach( create_config( false, path ) )
130 + end,

neovim/lua/bugabinga/lsp.lua

Modified
24 - jdtls = {
25 - root_dir = project.find_java_project_root,
26 - settings = {
27 - java = {
28 - signatureHelp = { enabled = true },
29 - sources = {
30 - autobuild = { enabled = true },
31 - signatureHelp = { enabled = true },
32 - saveActions = { origanizeImports = true },
33 - organizeImports = {
34 - starThreshold = 9999,
35 - staticStarThreshold = 9999,
36 - },
37 - codeGeneration = {
38 - toString = {
39 - template = '${object.className}{${member.name()}=${member.value()}, ${otherMembers}}',
40 - },
41 - hashCodeEquals = { useJava7Objects = true },
42 - useBlocks = true,
43 - },
44 - eclipse = { downloadSources = true },
45 - },
46 - configuration = {
47 - updateBuildConfiguration = 'interactive',
48 - },
49 - maven = { downloadSources = true },
50 - implementationsCodeLens = { enabled = true },
51 - referencesCodeLens = { enabled = true },
52 - references = { includeDecompiledSources = true },
53 - inlayHints = { parameterNames = { enabled = 'all' } },
54 - format = { enabled = true },
55 - },
56 - },
57 - },
58 24 zls = { root_dir = project.find_zig_project_root },
59 25 ziggy = { root_dir = project.find_zig_project_root },
60 26 ziggy_schema = { root_dir = project.find_zig_project_root },

neovim/lua/bugabinga/statusbar.lua

Modified
284 284 local svn_get_relative_url = function ()
285 285 local result = vim.system { 'svn', 'info', '--show-item', 'relative-url', '--no-newline' }:wait()
286 286 if result.code == 0 then
287 - vim.print( result )
288 287 return result.stdout
290 289 return result.stderr