202 lines
6.4 KiB
Nix
202 lines
6.4 KiB
Nix
{ config, pkgs, ... }:
|
|
|
|
{
|
|
programs.neovim = {
|
|
enable = true;
|
|
viAlias = true;
|
|
vimAlias = true;
|
|
defaultEditor = true;
|
|
|
|
initLua = ''
|
|
vim.opt.number = true
|
|
vim.opt.relativenumber = true
|
|
vim.opt.tabstop = 2
|
|
vim.opt.softtabstop = 2
|
|
vim.opt.expandtab = true
|
|
vim.opt.shiftwidth = 2
|
|
vim.opt.smartindent = true
|
|
vim.opt.wrap = false
|
|
vim.opt.swapfile = false
|
|
vim.opt.backup = false
|
|
vim.opt.undofile = false
|
|
vim.opt.hlsearch = false
|
|
vim.opt.incsearch = true
|
|
vim.opt.termguicolors = true
|
|
vim.opt.clipboard = "unnamedplus"
|
|
vim.opt.scrolloff = 999
|
|
vim.opt.updatetime = 50
|
|
vim.opt.foldmethod = "indent"
|
|
vim.opt.foldlevel = 99
|
|
|
|
vim.g.mapleader = " "
|
|
vim.keymap.set("n", "<leader>", ":")
|
|
vim.keymap.set("n", "<leader>w", "<cmd>w<CR>", { silent = true })
|
|
vim.keymap.set("n", "<leader>q", "<cmd>q<CR>", { silent = true })
|
|
vim.keymap.set("n", "<leader>wq", "<cmd>wq<CR>", { silent = true })
|
|
vim.keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true })
|
|
vim.keymap.set("n", "Q", "<nop>")
|
|
vim.keymap.set("n", "o", "o<esc>")
|
|
vim.keymap.set("n", "O", "O<esc>")
|
|
vim.keymap.set("i", "jj", "<esc>")
|
|
|
|
local is_dark = vim.o.background ~= "light"
|
|
require("cyberdream").setup({
|
|
transparent = is_dark,
|
|
variant = is_dark and "dark" or "light",
|
|
terminal_colors = true,
|
|
})
|
|
vim.cmd.colorscheme("cyberdream")
|
|
|
|
require("nvim-tree").setup({
|
|
view = { width = 30 },
|
|
renderer = { group_empty = true },
|
|
filters = { dotfiles = false },
|
|
})
|
|
|
|
require("bufferline").setup({
|
|
options = {
|
|
offsets = {
|
|
{
|
|
filetype = "NvimTree",
|
|
text = "Files",
|
|
highlight = "Directory",
|
|
separator = true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
require("lualine").setup({
|
|
ons = { theme = "auto" },
|
|
})
|
|
|
|
require("neocord").setup({
|
|
logo = "auto",
|
|
logo_tooltip = "Neovim",
|
|
main_image = "language",
|
|
show_time = true,
|
|
global_timer = true,
|
|
})
|
|
|
|
require("gitsigns").setup({
|
|
signs = {
|
|
add = { text = "+" },
|
|
change = { text = "~" },
|
|
delete = { text = "_" },
|
|
},
|
|
})
|
|
|
|
-- 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,
|
|
})
|
|
|
|
local cmp = require("cmp")
|
|
local luasnip = require("luasnip")
|
|
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" },
|
|
},
|
|
})
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
-- .project and .classpath come first so a repo containing several
|
|
-- assignments resolves to the assignment, not the repo root.
|
|
local root_markers = { ".project", ".classpath", "pom.xml", "build.gradle", ".git" }
|
|
|
|
local function start_jdtls()
|
|
local jdtls = require("jdtls")
|
|
local root_dir = require("jdtls.setup").find_root(root_markers)
|
|
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
|
|
|
|
jdtls.start_or_attach({
|
|
cmd = { "jdtls", "-data", workspace },
|
|
root_dir = root_dir,
|
|
capabilities = capabilities,
|
|
settings = { java = java_settings },
|
|
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,
|
|
})
|
|
'';
|
|
|
|
plugins = with pkgs.vimPlugins; [
|
|
{ plugin = cyberdream-nvim; }
|
|
{ plugin = nvim-web-devicons; }
|
|
{ plugin = nvim-tree-lua; }
|
|
{ plugin = bufferline-nvim; }
|
|
{ plugin = lualine-nvim; }
|
|
{ plugin = neocord; }
|
|
{ plugin = gitsigns-nvim; }
|
|
|
|
{ plugin = nvim-jdtls; }
|
|
{ plugin = neotest; }
|
|
{ plugin = neotest-java; }
|
|
{ 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 ])); }
|
|
];
|
|
};
|
|
}
|