restructure of plugin loading

This commit is contained in:
Jannik Donker
2026-03-12 11:24:54 +01:00
parent baa641ad7e
commit ba6246987e
+79 -98
View File
@@ -28,13 +28,13 @@ vim.pack.add({
{ src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/nvim-treesitter/nvim-treesitter" },
{ src = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects" },
{ src = "https://github.com/Saghen/blink.cmp", version = "v1.7.0", },
{ src = "https://github.com/Saghen/blink.cmp", version = "v1.7.0" },
{ src = "https://github.com/mason-org/mason.nvim" },
{ src = "https://github.com/dimitry-ishenko-neovim/lualine-nvim" },
{ src = "https://github.com/nvim-lualine/lualine.nvim.git" },
{ src = "https://github.com/chomosuke/typst-preview.nvim" },
{ src = "https://github.com/numToStr/Comment.nvim" },
{ src = "https://codeberg.org/mfussenegger/nvim-jdtls.git", dependencies = { "https://codeberg.org/mfussenegger/nvim-dap.git" } },
{ src = "https://github.com/m4xshen/autoclose.nvim", },
{ src = "https://github.com/m4xshen/autoclose.nvim" },
{ src = "https://codeberg.org/mfussenegger/nvim-dap.git" },
{ src = "https://github.com/romgrk/barbar.nvim" },
{ src = "https://github.com/nvim-tree/nvim-web-devicons" },
@@ -44,24 +44,29 @@ vim.pack.add({
{ src = "https://github.com/nvim-neotest/nvim-nio" },
})
vim.cmd("colorscheme gruvbox")
-- Safely load colorscheme
pcall(vim.cmd, "colorscheme gruvbox")
require("oil").setup()
require("mini.pick").setup()
require("blink.cmp").setup({
keymap = { preset = "super-tab" },
})
require("nvim-treesitter.configs").setup({
-- Helper function to safely setup plugins only if they are installed
local function setup_plugin(module, opts)
local ok, plugin = pcall(require, module)
if ok and type(plugin.setup) == "function" then
plugin.setup(opts or {})
end
end
setup_plugin("oil")
setup_plugin("mini.pick")
setup_plugin("blink.cmp", { keymap = { preset = "super-tab" } })
setup_plugin("nvim-treesitter.configs", {
auto_install = true,
highlight = { enable = true },
indent = { enable = true },
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
@@ -70,44 +75,64 @@ require("nvim-treesitter.configs").setup({
},
},
})
require("mason").setup()
require("lualine").setup {
options = {
theme = "gruvbox_dark",
}
}
require("typst-preview").setup()
require("autoclose").setup()
require("trouble").setup()
require('Comment').setup()
setup_plugin("mason")
-- Automatically install these tools via Mason
local registry = require("mason-registry")
local ensure_installed = {
"bash-language-server",
"clang-format",
"clangd",
"java-debug-adapter",
"jdtls",
"json-lsp",
"lua-language-server",
"rust-analyzer",
"svelte-language-server",
"tailwindcss-language-server",
"taplo",
"typescript-language-server"
}
-- Refresh the registry and install missing tools
registry.refresh(function()
for _, tool in ipairs(ensure_installed) do
local ok, pkg = pcall(registry.get_package, tool)
if ok and not pkg:is_installed() then
pkg:install()
end
end
end)
setup_plugin("lualine", { options = { theme = "gruvbox_dark" } })
setup_plugin("typst-preview")
setup_plugin("autoclose")
setup_plugin("trouble")
setup_plugin("Comment")
-- PLUGINS END --
-- DAP START --
require("dapui").setup()
local dap, dapui = require("dap"), require("dapui")
dap.listeners.before.attach.dapui_config = function()
dapui.open()
local ok_dap, dap = pcall(require, "dap")
local ok_dapui, dapui = pcall(require, "dapui")
if ok_dap and ok_dapui then
dapui.setup()
dap.listeners.before.attach.dapui_config = function() dapui.open() end
dap.listeners.before.launch.dapui_config = function() dapui.open() end
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
--[[ dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end ]]
-- DAP END --
-- LSP START --
vim.lsp.enable({ "lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls", "rust_analyzer", "clangd", "clang-format",
"taplo",
"sourcekit", "lemminx", "tinymist", "jsonls" })
-- Assuming vim.lsp.enable is native to your specific Neovim version
vim.lsp.enable({
"lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls",
"rust_analyzer", "clangd", "clang-format", "taplo",
"sourcekit", "lemminx", "tinymist", "jsonls"
})
vim.lsp.config["tinymist"] = {
cmd = { "tinymist" },
@@ -120,19 +145,18 @@ vim.lsp.config["tinymist"] = {
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = function(args)
-- Safely require jdtls so it doesn't crash if uninstalled
local ok, jdtls = pcall(require, "jdtls")
if not ok then return end
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = vim.fn.stdpath("data") ..
package.config:sub(1, 1) .. "jdtls-workspace" .. package.config:sub(1, 1) .. project_name
local os_name = vim.loop.os_uname().sysname
local config = {
-- The command that starts the language server
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
cmd = {
-- 💀
"java", -- or '/path/to/java17_or_newer/bin/java'
-- depends on if `java` is in your $PATH env variable and if it points to the right version.
"java",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
@@ -140,12 +164,8 @@ vim.api.nvim_create_autocmd('FileType', {
"-Dlog.level=ALL",
"-Xmx1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
-- 💀
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"-jar",
vim.fn.stdpath("data") ..
package.config:sub(1, 1) ..
@@ -156,10 +176,6 @@ vim.api.nvim_create_autocmd('FileType', {
"jdtls" ..
package.config:sub(1, 1) ..
"plugins" .. package.config:sub(1, 1) .. "org.eclipse.equinox.launcher_1.7.100.v20251111-0406.jar",
-- Must point to the Change this to
-- eclipse.jdt.ls installation the actual version
-- 💀
"-configuration",
vim.fn.stdpath("data") ..
package.config:sub(1, 1) ..
@@ -170,40 +186,15 @@ vim.api.nvim_create_autocmd('FileType', {
"jdtls" ..
package.config:sub(1, 1) ..
"config_" .. (os_name == "Windows_NT" and "win" or os_name == "Linux" and "linux" or "mac"),
-- eclipse.jdt.ls installation Depending on your system.
-- 💀
-- See `data directory configuration` section in the README
"-data",
workspace_dir,
"-data", workspace_dir,
},
-- 💀
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }),
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
settings = {
java = {},
},
-- Language server `initializationOptions`
-- You need to extend the `bundles` with paths to jar files
-- if you want to use additional eclipse.jdt.ls plugins.
--
-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
--
-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
settings = { java = {} },
init_options = {
bundles = { vim.fn.glob("/home/jannikdonker/.local/share/nvim/mason/share/java-debug-adapter/com.microsoft.java.debug.plugin.jar", 1) },
},
}
-- This starts a new client & server,
-- or attaches to an existing client & server depending on the `root_dir`.
require("jdtls").start_or_attach(config)
jdtls.start_or_attach(config)
end
})
@@ -229,23 +220,19 @@ map.set("n", "<C-g>", ":Pick grep_live<CR>")
map.set("n", "<C-h>", ":Pick help<CR>")
map.set("n", "<C-e>", ":Oil<CR>")
map.set("n", "<leader>duo", dapui.open)
map.set("n", "<leader>duc", dapui.close)
map.set("n", "<leader>dbp", dap.toggle_breakpoint)
map.set("n", "<leader>drc", dap.run_to_cursor)
-- Wrapped DAP calls in anonymous functions so they don't evaluate before DAP installs
map.set("n", "<leader>duo", function() require("dapui").open() end)
map.set("n", "<leader>duc", function() require("dapui").close() end)
map.set("n", "<leader>dbp", function() require("dap").toggle_breakpoint() end)
map.set("n", "<leader>drc", function() require("dap").run_to_cursor() end)
local is_mac = vim.fn.has("macunix") == 1
local barbarKey = is_mac and "M" or "A"
-- Move to previous/next
map.set('n', '<' .. barbarKey .. '-,>', '<Cmd>BufferPrevious<CR>', opts)
map.set('n', '<' .. barbarKey .. '-.>', '<Cmd>BufferNext<CR>', opts)
-- Re-order to previous/next
map.set('n', '<' .. barbarKey .. '-<>', '<Cmd>BufferMovePrevious<CR>', opts)
map.set('n', '<' .. barbarKey .. '->>', '<Cmd>BufferMoveNext<CR>', opts)
-- Goto buffer in position...
map.set('n', '<' .. barbarKey .. '-1>', '<Cmd>BufferGoto 1<CR>', opts)
map.set('n', '<' .. barbarKey .. '-2>', '<Cmd>BufferGoto 2<CR>', opts)
map.set('n', '<' .. barbarKey .. '-3>', '<Cmd>BufferGoto 3<CR>', opts)
@@ -256,12 +243,8 @@ map.set('n', '<' .. barbarKey .. '-7>', '<Cmd>BufferGoto 7<CR>', opts)
map.set('n', '<' .. barbarKey .. '-8>', '<Cmd>BufferGoto 8<CR>', opts)
map.set('n', '<' .. barbarKey .. '-9>', '<Cmd>BufferGoto 9<CR>', opts)
map.set('n', '<' .. barbarKey .. '-0>', '<Cmd>BufferLast<CR>', opts)
-- Pin/unpin buffer
map.set('n', '<' .. barbarKey .. '-p>', '<Cmd>BufferPin<CR>', opts)
-- Close buffer
map.set('n', '<' .. barbarKey .. '-w>', '<Cmd>BufferClose<CR>', opts)
-- Magic buffer-picking mode
map.set('n', '<C-p>', '<Cmd>BufferPick<CR>', opts)
map.set('n', '<C-s-p>', '<Cmd>BufferPickDelete<CR>', opts)
@@ -276,13 +259,11 @@ vim.diagnostic.config({
severity_sort = true,
})
-- Toggle spell check with <leader>sc
vim.keymap.set("n", "<leader>sc", function()
vim.wo.spell = not vim.wo.spell
print("Spell checking: " .. (vim.wo.spell and "ON" or "OFF"))
end, { desc = "Toggle spell checking" })
-- Switch between English and German with <leader>sl
vim.keymap.set("n", "<leader>sl", function()
local current = vim.opt.spelllang:get()[1] or ""
local new_lang = current == "en" and "de" or "en"