This commit is contained in:
2025-05-31 03:32:58 -04:00
parent ef678f31fd
commit e830931ff4
41 changed files with 253 additions and 268 deletions

View File

@ -1,3 +1,4 @@
indent_type = "Spaces" # Use spaces instead of tabs
indent_width = 2 # Number of spaces per indent level
quote_style = "ForceDouble" # Always use double quotes for strings
call_parentheses = "Always"

View File

@ -1,5 +1,4 @@
local misc = require('core.misc')
local map_local = misc.map_local
local map_local = core.misc.map_local
-- sort #includes <> (very jank)
-- TODO: rewrite in a semi-sane way

View File

@ -0,0 +1 @@
core.misc.map("n", "q", "<cmd>q<CR>")

View File

@ -1,5 +1,7 @@
local misc = require("core.misc")
local map, auto = misc.map, misc.auto
-- FIXME: the following error is emmitted when starting up jdtls:
-- ERROR No LSP client found that supports vscode.java.resolveMainClass
local map, auto = core.misc.map, core.misc.auto
local ok, jdtls = pcall(require, "jdtls")
if not ok then
@ -8,20 +10,16 @@ if not ok then
return
end
-- HACK: I don't like using path concatination there *should* be a way to get
-- the path from mason
local jdtls_install = vim.fs.joinpath(vim.fn.stdpath('data'),
"/mason/packages/jdtls")
local java_dap_install = vim.fs.joinpath(vim.fn.stdpath('data'),
"/mason/packages/java-debug-adapter")
local jdtls_install = core.mason.get_pkg_path("jdtls")
local java_dap_install = core.mason.get_pkg_path("java-debug-adapter")
-- make sure to check if things with 💀 need updating
local config = {
cmd = {
"/usr/lib/jvm/openjdk21/bin/java", -- 💀
"-jar", -- 💀
vim.fn.glob(jdtls_install.."/plugins/org.eclipse.equinox.launcher_*.jar"),
"-configuration", jdtls_install.."/config_linux",
vim.fn.glob(vim.fs.joinpath(jdtls_install, "plugins/org.eclipse.equinox.launcher_*.jar")),
"-configuration", jdtls_install.."config_linux",
"-data", vim.fn.stdpath("cache").."/nvim-jdtls",
"--add-modules=ALL-SYSTEM",
@ -88,15 +86,13 @@ local config = {
init_options = {
bundles = {
vim.fs.joinpath(java_dap_install,
vim.fn.glob("/extension/server/com.microsoft.java.debug.plugin-*.jar",
vim.fn.glob("extension/server/com.microsoft.java.debug.plugin-*.jar",
true)
)
}
}
}
-- HACK: same hack as before
-- generate the path to the java file(s)
---@type string?
local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"),
@ -150,20 +146,20 @@ local function version_check()
if out.code ~= 0 then
vim.notify(string.format(
"java version check failed: exit code %s", out.code),
vim.log.levels.ERROR, { title = misc.appid })
vim.log.levels.ERROR, { title = core.misc.appid })
vim.notify(string.format(
"%s", vim.inspect(out.stdout)),
vim.log.levels.ERROR, { title = misc.appid })
vim.log.levels.ERROR, { title = core.misc.appid })
return false
elseif not v then
vim.notify("no java version info found", vim.log.levels.ERROR,
{ title = misc.appid })
{ title = core.misc.appid })
return false
elseif v.major < 21 then
vim.notify(string.format(
"java version %s < 21.0.0 Cannot run jdtls, bailing out",
v[1].."."..v[2].."."..v[3]),
vim.log.levels.ERROR, { title = misc.appid })
vim.log.levels.ERROR, { title = core.misc.appid })
return false
end

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map_local = misc.map_local
local map_local = core.misc.map_local
map_local("n", "h", "-", { noremap = false, remap = true }) -- Go up a directory
map_local("n", "l", "<CR>", { noremap = false, remap = true }) -- Go down a directory / open a file
@ -17,5 +16,5 @@ end)
map_local("n", "rt", function()
vim.api.nvim_set_current_dir(vim.b.netrw_curdir)
vim.notify("root dir updated: "..vim.b.netrw_curdir, vim.log.levels.LOW,
{ title = misc.appid })
{ title = core.misc.appid })
end)

View File

@ -1,4 +1,4 @@
local map = require("core.misc").map
local map = core.misc.map
return {
on_attach = function(_, bufnr)

View File

@ -1,4 +1,4 @@
local map = require("core.misc").map
local map = core.misc.map
return {
on_attach = function(_, bufnr)

View File

@ -1,10 +1,13 @@
-- TODO: after switching to dep with lazy loading check out vim-startuptime
-- again
_G.core = require("core")
-- enable performance stuff
if vim.fn.has("nvim-0.9") == true then
vim.loader.enable()
end
vim.loader.enable()
-- load user config
require("conf")
-- bootstrap plugin manager
local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep"
@ -14,14 +17,6 @@ if vim.fn.empty(vim.fn.glob(path)) > 0 then
end
vim.cmd("packadd dep")
-- load miscellaneous utilities
local misc = require("core.misc")
-- load user config
misc.include("conf.opts") -- setup options
misc.include("conf.binds") -- setup keybinds
misc.include("conf.autos") -- setup autos
-- load plugins
require("dep") {
{ "squibid/dep",
@ -35,8 +30,9 @@ require("dep") {
for _, file in ipairs(vim.api.nvim_get_runtime_file(
"lua/conf/plugins/*.lua", true)) do
local ret = misc.include("conf.plugins."..file:gsub("^.*/",
""):gsub("%.lua$", ""))
local ret = require("conf.plugins."..file:gsub("^.*/", ""):gsub("%.lua$",
""))
if type(ret) ~= "boolean" then
plugs[#plugs + 1] = ret
end

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local auto, augroup = misc.auto, misc.augroup
local auto, augroup = core.misc.auto, core.misc.augroup
-- auto commands which interact with bufferes without modifying them
local bufcheck = augroup("bufcheck")

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
-- vim binds
vim.g.mapleader = " " -- set leader key
@ -25,20 +24,20 @@ map("n", "<leader>x", function() -- execute order 111
local perm = vim.fn.getfperm(fn)
if string.match(perm, "x", 3) then
vim.notify("Removed executable flags", vim.log.levels.INFO, {
title = misc.appid
title = core.misc.appid
})
vim.fn.setfperm(fn, string.sub(fn, 1, 2).."-"..string.sub(fn, 4, 5).."-"
..string.sub(fn, 7, 8).."-")
else
vim.notify("Add executable flags", vim.log.levels.INFO, {
title = misc.appid
title = core.misc.appid
})
vim.fn.setfperm(fn, string.sub(fn, 1, 2).."x"..string.sub(fn, 4, 5).."x"
..string.sub(fn, 7, 8).."x")
end
else
vim.notify("File doesn't exist", vim.log.levels.INFO, {
title = misc.appid
title = core.misc.appid
})
end
end, { desc = "toggle executable flag of the file" })

3
lua/conf/init.lua Normal file
View File

@ -0,0 +1,3 @@
require("conf.opts") -- setup options
require("conf.binds") -- setup keybinds
require("conf.autos") -- setup autos

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local auto = misc.auto
local auto = core.misc.auto
-- color stuff
if vim.fn.has("termguicolors") then
@ -84,8 +83,7 @@ do -- folding
vim.opt.foldenable = true
vim.o.fillchars = "fold: "
_G.Fold_text = require("core.folding")
vim.opt.foldtext = "v:lua.Fold_text()"
vim.opt.foldtext = "v:lua.core.folding()"
end
do -- statusline

View File

@ -1,18 +1,4 @@
local misc = require("core.misc")
local map = misc.map
--- select a program to execute
---@return thread coroutine containing the picker
local function select_program()
return coroutine.create(function(coro)
---@diagnostic disable-next-line: param-type-mismatch
local entries = vim.fn.readdir(".", [[v:val !~ '^\.']])
vim.ui.select(entries, { prompt = "Select the executable to run:" },
function(choice)
coroutine.resume(coro, choice)
end)
end)
end
local map = core.misc.map
local keymap_restore = {}
--- make the default hover binding work for nvim-dap instead of lsp
@ -66,7 +52,9 @@ return { "mfussenegger/nvim-dap",
name = "Launch file",
type = "codelldb",
request = "launch",
program = select_program,
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd()..'/', 'file')
end,
cwd = "${workspaceFolder}",
stopOnEntry = false

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "lewis6991/gitsigns.nvim",
disable = not vim.fn.has("nvim-0.9.0"),

View File

@ -1,5 +1,7 @@
local misc = require("core.misc")
local map = misc.map
-- TODO: might end up writing my own because I like harpoon, but I hate that it
-- doesn't work properly without being pinned to a specific commit
local map = core.misc.map
return { "ThePrimeagen/harpoon",
disable = not vim.fn.has("nvim-0.8.0"),
@ -14,7 +16,7 @@ return { "ThePrimeagen/harpoon",
map("n", "<leader>a", function()
harpoon:list():add()
vim.notify("added "..vim.fn.expand("%:t").." to quickmarks",
vim.log.levels.INFO, { title = misc.appid })
vim.log.levels.INFO, { title = core.misc.appid })
end, { desc = "add current file to quickmarks" })
map("n", "<C-e>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)

View File

@ -1,5 +0,0 @@
return { "mawkler/hml.nvim",
function()
require("hml").setup {}
end
}

View File

@ -1,17 +0,0 @@
return { "kawre/leetcode.nvim",
requires = {
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
"MunifTanjim/nui.nvim",
"nvim-treesitter/nvim-treesitter"
},
config = function()
-- because we"re using treesitter make sure to install the html parser
vim.cmd("TSUpdate html")
end,
function()
require("leetcode").setup {
lang = "java"
}
end
}

View File

@ -5,7 +5,7 @@ return { "neovim/nvim-lspconfig",
"mason-org/mason-lspconfig.nvim"
},
function()
require("core.lsp.functions").setup()
core.lsp.setup()
require("mason-lspconfig").setup {
ensure_added = {
"clangd",

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map, auto = core.misc.map, core.misc.auto
return { "L3MON4D3/LuaSnip",
branch = "v2.4.0",
@ -55,14 +54,21 @@ return { "L3MON4D3/LuaSnip",
end
end)
-- load all snippets from snippet directory
-- collect all snippets and add them when in the correct file type
for _, file in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua",
true)) do
local fn = file:gsub("^.*/", ""):gsub("%.lua$", "")
local ret = misc.include("snippets."..fn)
auto("FileType", {
pattern = fn,
once = true,
callback = function()
local ret = require("snippets."..fn)
if type(ret) ~= "boolean" then
luasnip.add_snippets(fn, ret, { key = fn })
end
end
})
end
end
}

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "danymat/neogen",
requires = {

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
-- helper function to parse output
local function parse_output(proc)

View File

@ -0,0 +1,9 @@
return { "ThePrimeagen/refactoring.nvim",
requires = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter"
},
function()
require('refactoring').setup {}
end
}

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
--- get the root directory for telescope to search
---@return string the root directory

View File

@ -1,3 +1,6 @@
-- TODO: gotta rewrite this cause it's actual dogshit, and I don't want to deal
-- with nerd fonts or folke anymore also add support for TODO(name):
return { "folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
disable = not vim.fn.has("nvim-0.8.0"),

View File

@ -0,0 +1,10 @@
return { "nvim-treesitter/nvim-treesitter-context",
requires = "nvim-treesitter/nvim-treesitter",
function()
require("treesitter-context").setup {
max_lines = 2,
line_numbers = true,
trim_scope = 'inner'
}
end
}

View File

@ -1,12 +1,3 @@
table.contains = function(self, string)
for _, v in pairs(self) do
if v == string then
return true
end
end
return false
end
return { "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.10.0"),
config = function()
@ -47,8 +38,7 @@ return { "nvim-treesitter/nvim-treesitter",
end
-- disable in big files
-- TODO: update before nvim 1.0 when vim.loop is removed
local ok, stats = pcall(vim.loop.fs_stat,
local ok, stats = pcall(vim.uv.fs_stat,
vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > (1024 * 100 * 10) --[[1MB]] then
return true

View File

@ -1,12 +1,11 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "Wansmer/treesj",
disable = not vim.fn.has("nvim-0.9.0"),
requires = "nvim-treesitter/nvim-treesitter",
function()
require("treesj").setup {
use_default_keymaps = false,
use_default_keymaps = false
}
map("n", "<leader>j", require("treesj").toggle, { desc = "fold code" })

View File

@ -1,5 +1,4 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "mbbill/undotree",
function()

26
lua/core/color.lua Normal file
View File

@ -0,0 +1,26 @@
local M = {}
--- copy highlight group
---@param hlgroup string highlight group to copy
---@param namespace? number highlight space
---@return table
function M.copyhl(hlgroup, namespace)
namespace = namespace or 0
local ok, hl = pcall(vim.api.nvim_get_hl, namespace, {
name = hlgroup,
create = false
})
if not ok then
return {}
end
for _, key in pairs({ "foreground", "background", "special" }) do
if hl[key] then
hl[key] = string.format("#%06x", hl[key])
end
end
return hl
end
return M

41
lua/core/init.lua Normal file
View File

@ -0,0 +1,41 @@
-- inspired by (and partially yoinked from): github.com/gonstoll/dotfiles
local M = {
misc = require("core.misc"),
folding = require("core.folding"),
lsp = require("core.lsp"),
color = require("core.color"),
snippets = vim.fs.joinpath(vim.fn.stdpath("config"), "lua/core/snippets.lua"),
}
--- check if the given table contains an item, and return the key value pair if
--- it does
---@param self table table
---@param item any item to find
---@return boolean, [any, any]? found true if found
table.contains = function(self, item)
for k, v in pairs(self) do
if v == item then
return true, { k, v }
end
end
return false
end
M.mason = {
--- Gets a path to a package in the Mason registry.
--- Prefer this to `get_package`, since the package might not always be
--- available yet and trigger errors.
---@param pkg string
---@param path? string
get_pkg_path = function(pkg, path)
pcall(require, "mason") -- make sure Mason is loaded. Will fail when generating docs
local root = vim.env.MASON or vim.fs.joinpath(vim.fn.stdpath("data"), "mason")
path = path or ""
return vim.fs.joinpath(root, "packages", pkg, path)
end
}
return M

84
lua/core/lsp.lua Normal file
View File

@ -0,0 +1,84 @@
---@diagnostic disable: param-type-mismatch
local misc = require("core.misc")
local map, auto = misc.map, misc.auto
local popup_opts, hover_opts, signature_opts, list_opts, location_opts
-- TODO: find a way to make the qflist current item be the one closest to the
-- cursor whenever we open it
local function on_list(opts)
vim.fn.setqflist({}, "r", opts)
if #opts.items > 1 then
vim.cmd.copen()
end
vim.cmd(".cc! 1")
end
-- disable the default keybinds (they're bad)
for _, bind in ipairs({ "grn", "gra", "gri", "grr" }) do
pcall(vim.keymap.del, "n", bind)
end
local M = {}
--- setup vim lsp options
function M.setup()
-- options for different lsp functions
popup_opts = { border = vim.g.border_style }
hover_opts = vim.tbl_deep_extend("force", popup_opts, {})
signature_opts = vim.tbl_deep_extend("force", popup_opts, {})
list_opts = { on_list = on_list }
location_opts = vim.tbl_deep_extend("force", list_opts, {})
-- confgiure lsp
vim.diagnostic.config {
virtual_text = false,
virtual_lines = {
current_line = true
},
update_in_insert = false,
underline = true,
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "x",
[vim.diagnostic.severity.WARN] = "!",
[vim.diagnostic.severity.INFO] = "i",
[vim.diagnostic.severity.HINT] = "h"
}
}
}
-- set default capabilities and attach function
vim.lsp.config['*'] = {
capabilities = vim.lsp.protocol.make_client_capabilities()
}
-- make my attach function always run
auto("LspAttach", {
callback = function(event)
local opts = { buffer = event.buf, nowait = true }
-- LSP actions
map("n", "K", function() vim.lsp.buf.hover(hover_opts) end, opts)
map("n", "gd", function() vim.lsp.buf.definition(location_opts) end, opts)
map("n", "gD", function() vim.lsp.buf.declaration(location_opts) end, opts)
map("n", "gi", function() vim.lsp.buf.implementation(location_opts) end, opts)
map("n", "gy", function() vim.lsp.buf.type_definition(location_opts) end, opts)
map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
map("n", "<S-Tab>", function() vim.lsp.buf.signature_help(signature_opts) end, opts)
map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts)
map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, opts)
-- Diagnostics
map("n", "[d", function()
vim.diagnostic.jump({ count = -1 })
end, opts)
map("n", "]d", function()
vim.diagnostic.jump({ count = 1 })
end, opts)
end
})
end
return M

View File

@ -1,100 +0,0 @@
local misc = require("core.misc")
local map, auto = misc.map, misc.auto
local M = {}
-- TODO: find a way to make the qflist current item be the one closest to the
-- cursor whenever we open it
local function on_list(opts)
vim.fn.setqflist({}, "r", opts)
if #opts.items > 1 then
vim.cmd.copen()
end
vim.cmd(".cc! 1")
end
---@type vim.lsp.util.open_floating_preview.Opts
local popup_opts = {
border = vim.g.border_style
}
---@type vim.lsp.buf.hover.Opts
---@diagnostic disable-next-line: assign-type-mismatch
local hover_opts = vim.tbl_deep_extend("force", popup_opts, {})
---@type vim.lsp.buf.signature_help.Opts
---@diagnostic disable-next-line: assign-type-mismatch
local signature_opts = vim.tbl_deep_extend("force", popup_opts, {})
---@type vim.lsp.ListOpts
local list_opts = {
on_list = on_list
}
---@type vim.lsp.LocationOpts
---@diagnostic disable-next-line: assign-type-mismatch
local location_opts = vim.tbl_deep_extend("force", list_opts, {})
-- disable the default keybinds (they're bad)
for _, bind in ipairs({ "grn", "gra", "gri", "grr" }) do
pcall(vim.keymap.del, "n", bind)
end
--- setup basic options on lsp attach
---@param bufnr number buffer number
local function attach(bufnr)
local opts = { buffer = bufnr, nowait = true }
-- LSP actions
map("n", "K", function() vim.lsp.buf.hover(hover_opts) end, opts)
map("n", "gd", function() vim.lsp.buf.definition(location_opts) end, opts)
map("n", "gD", function() vim.lsp.buf.declaration(location_opts) end, opts)
map("n", "gi", function() vim.lsp.buf.implementation(location_opts) end, opts)
map("n", "gy", function() vim.lsp.buf.type_definition(location_opts) end, opts)
map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
map("n", "<S-Tab>", function() vim.lsp.buf.signature_help(signature_opts) end, opts)
map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts)
map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, opts)
-- Diagnostics
map("n", "[d", function()
vim.diagnostic.jump({ count = -1 })
end, opts)
map("n", "]d", function()
vim.diagnostic.jump({ count = 1 })
end, opts)
end
--- setup vim lsp options
function M.setup()
vim.diagnostic.config {
virtual_text = false,
virtual_lines = {
current_line = true
},
update_in_insert = false,
underline = true,
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "x",
[vim.diagnostic.severity.WARN] = "!",
[vim.diagnostic.severity.INFO] = "i",
[vim.diagnostic.severity.HINT] = "h"
}
}
}
-- set default capabilities and attach function
vim.lsp.config['*'] = {
capabilities = vim.lsp.protocol.make_client_capabilities()
}
-- make my attach function always run
auto("LspAttach", {
callback = function(event)
attach(event.buf)
end
})
end
return M

View File

@ -3,18 +3,6 @@ local M = {}
--- vim.notify title
M.appid = "Nvim Config"
--- safe version of require
---@param fn string name of file to include
---@return any
function M.include(fn)
local ok, r = pcall(require, fn)
if not ok then
vim.notify("Could not find '"..fn.."': "..r, vim.log.levels.WARN, { title = M.appid })
return ok
end
return r
end
--- loop through files in directory
---@param path string absolute path of directory to be looped through
---@param body function function to use on every recursion of the loop
@ -99,29 +87,6 @@ function M.highlight(group, opts, namespace)
end
end
--- copy highlight group
---@param hlgroup string highlight group to copy
---@param namespace? number highlight space
---@return table
function M.cpyhl(hlgroup, namespace)
namespace = namespace or 0
local ok, hl = pcall(vim.api.nvim_get_hl, namespace, {
name = hlgroup,
create = false
})
if not ok then
return {}
end
for _, key in pairs({ "foreground", "background", "special" }) do
if hl[key] then
hl[key] = string.format("#%06x", hl[key])
end
end
return hl
end
--- highlight something with some highlight group for a certain amount of time
--- example:
--- ```lua

View File

@ -21,3 +21,7 @@ conds_expand = require("luasnip.extras.conditions.expand")
ts_postfix = require("luasnip.extras.treesitter_postfix").treesitter_postfix
postfix = require("luasnip.extras.postfix").postfix
ms = ls.multi_snippet
function file_name(_, _, _)
return vim.fn.expand("%:t:r")
end

View File

@ -1,3 +0,0 @@
function file_name(_, _, _)
return vim.fn.expand("%:t:r")
end

View File

@ -1,4 +1,4 @@
require('core.snippets.shorthands')
dofile(core.snippets)
return {
-- function snippet

View File

@ -1,5 +1,4 @@
require("core.snippets.shorthands")
require("core.snippets.functions")
dofile(core.snippets)
--- shortcut to choose between java access modifiers
---@param idx number index of the node

View File

@ -1,5 +1,4 @@
require("core.snippets.shorthands")
require("core.snippets.functions")
dofile(core.snippets)
return {
-- header level 1, usually this has the same name as the file

View File

@ -1,4 +1,4 @@
require("core.snippets.shorthands")
dofile(core.snippets)
return {
-- translate snippet

View File

@ -1,4 +1,4 @@
require("core.snippets.shorthands")
dofile(core.snippets)
return {
s("php", {

View File

@ -1,5 +1,4 @@
require("core.snippets.shorthands")
require("core.snippets.functions")
dofile(core.snippets)
return {
-- document snippet