nixos: gen 21 @ lilac — 2026-09-01 11:37 26.05.20260814.02e0898 (Yarara) -----
This commit is contained in:
+93
-26
@@ -7,11 +7,6 @@
|
|||||||
vimAlias = true;
|
vimAlias = true;
|
||||||
defaultEditor = true;
|
defaultEditor = true;
|
||||||
|
|
||||||
extraPackages = with pkgs; [
|
|
||||||
jdtls
|
|
||||||
jdk
|
|
||||||
];
|
|
||||||
|
|
||||||
initLua = ''
|
initLua = ''
|
||||||
vim.opt.number = true
|
vim.opt.number = true
|
||||||
vim.opt.relativenumber = true
|
vim.opt.relativenumber = true
|
||||||
@@ -91,30 +86,94 @@
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local lspconfig = require('lspconfig')
|
-- Java indentation must match Eclipse's formatter, not your 2-space default.
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "java",
|
||||||
|
callback = function()
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
vim.bo.tabstop = 4
|
||||||
|
vim.bo.shiftwidth = 4
|
||||||
|
vim.bo.softtabstop = 4
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- Common keymaps to run when the Eclipse LSP attaches to a Java buffer
|
local cmp = require("cmp")
|
||||||
local on_attach = function(client, bufnr)
|
local luasnip = require("luasnip")
|
||||||
local opts = { buffer = bufnr, silent = true }
|
cmp.setup({
|
||||||
|
snippet = { expand = function(a) luasnip.lsp_expand(a.body) end },
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
|
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
||||||
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
||||||
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
||||||
|
}),
|
||||||
|
sources = {
|
||||||
|
{ name = "nvim_lsp" },
|
||||||
|
{ name = "luasnip" },
|
||||||
|
{ name = "buffer" },
|
||||||
|
{ name = "path" },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
-- Eclipse IDE core features mapped to Neovim actions
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
||||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
-- .project and .classpath come first so a repo containing several
|
||||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
-- assignments resolves to the assignment, not the repo root.
|
||||||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
local root_markers = { ".project", ".classpath", "pom.xml", "build.gradle", ".git" }
|
||||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
|
||||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
local function start_jdtls()
|
||||||
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
local jdtls = require("jdtls")
|
||||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
local root_dir = require("jdtls.setup").find_root(root_markers)
|
||||||
vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, opts)
|
if not root_dir or root_dir == "" then return end
|
||||||
|
|
||||||
|
local project_name = vim.fn.fnamemodify(root_dir, ":p:h:t")
|
||||||
|
local workspace = vim.fn.stdpath("cache") .. "/jdtls-workspaces/" .. project_name
|
||||||
|
|
||||||
|
local java_settings = {
|
||||||
|
configuration = {
|
||||||
|
updateBuildConfiguration = "interactive",
|
||||||
|
runtimes = {
|
||||||
|
{ name = "JavaSE-21", path = os.getenv("JAVA_HOME"), default = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
-- Keep a stray pom.xml from overriding the Eclipse project model.
|
||||||
|
-- Flip these on if a course actually requires Maven or Gradle.
|
||||||
|
import = {
|
||||||
|
maven = { enabled = false },
|
||||||
|
gradle = { enabled = false },
|
||||||
|
},
|
||||||
|
signatureHelp = { enabled = true },
|
||||||
|
eclipse = { downloadSources = true },
|
||||||
|
}
|
||||||
|
|
||||||
|
-- If the repo carries an exported Eclipse formatter profile, use it verbatim.
|
||||||
|
local formatter = root_dir .. "/.settings/eclipse-formatter.xml"
|
||||||
|
if vim.uv.fs_stat(formatter) then
|
||||||
|
java_settings.format = { settings = { url = formatter } }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initialize the Eclipse JDTLS Server configuration
|
jdtls.start_or_attach({
|
||||||
-- NixOS patches 'jdtls' wrapper script automatically to point to the correct binary paths
|
cmd = { "jdtls", "-data", workspace },
|
||||||
lspconfig.jdtls.setup({
|
root_dir = root_dir,
|
||||||
on_attach = on_attach,
|
capabilities = capabilities,
|
||||||
cmd = { "jdtls" },
|
settings = { java = java_settings },
|
||||||
root_dir = lspconfig.util.root_pattern(".git", "pom.xml", "build.gradle"),
|
init_options = { bundles = {} },
|
||||||
|
on_attach = function(_, bufnr)
|
||||||
|
local map = function(k, f) vim.keymap.set("n", k, f, { buffer = bufnr, silent = true }) end
|
||||||
|
map("gd", vim.lsp.buf.definition)
|
||||||
|
map("gr", vim.lsp.buf.references)
|
||||||
|
map("K", vim.lsp.buf.hover)
|
||||||
|
map("<leader>rn", vim.lsp.buf.rename)
|
||||||
|
map("<leader>ca", vim.lsp.buf.code_action)
|
||||||
|
map("<leader>f", function() vim.lsp.buf.format({ async = true }) end)
|
||||||
|
map("<leader>oi", require("jdtls").organize_imports)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "java",
|
||||||
|
callback = start_jdtls,
|
||||||
})
|
})
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@@ -126,7 +185,15 @@
|
|||||||
{ plugin = lualine-nvim; }
|
{ plugin = lualine-nvim; }
|
||||||
{ plugin = neocord; }
|
{ plugin = neocord; }
|
||||||
{ plugin = gitsigns-nvim; }
|
{ plugin = gitsigns-nvim; }
|
||||||
{ plugin = nvim-lspconfig; }
|
|
||||||
|
{ plugin = nvim-jdtls; }
|
||||||
|
{ plugin = nvim-cmp; }
|
||||||
|
{ plugin = cmp-nvim-lsp; }
|
||||||
|
{ plugin = cmp-buffer; }
|
||||||
|
{ plugin = cmp-path; }
|
||||||
|
{ plugin = luasnip; }
|
||||||
|
{ plugin = cmp_luasnip; }
|
||||||
|
{ plugin = (nvim-treesitter.withPlugins (p: [ p.java p.xml p.nix p.lua ])); }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,10 @@
|
|||||||
];
|
];
|
||||||
})
|
})
|
||||||
google-chrome
|
google-chrome
|
||||||
|
google-java-format
|
||||||
gnupg
|
gnupg
|
||||||
|
jdk
|
||||||
|
jdt-language-server
|
||||||
jq
|
jq
|
||||||
keepassxc
|
keepassxc
|
||||||
lan-mouse
|
lan-mouse
|
||||||
|
|||||||
Reference in New Issue
Block a user