Compare commits

17 Commits

Author SHA1 Message Date
afdefb7dc3 fix mellow theming 2025-07-14 19:42:40 -04:00
64afe9c9ee revert treesitter back to master branch 2025-07-14 19:42:16 -04:00
cace587a09 more more more 2025-07-13 18:58:27 -04:00
101bc55f15 quick fix goes to a more sane place now 2025-07-11 14:08:53 -04:00
cd26cbb825 small changes...
if you want more look at the changes, there's not that many
2025-06-21 22:49:37 -04:00
7ef68dea92 gotta use new remote 2025-06-13 19:36:07 -04:00
9ea9d9f516 more!!! add python support and formatters and null ls to manage all...
that automatically also change my stylua.toml to ignore everything
cause I don't like the way it formats stuff
2025-06-11 03:21:25 -04:00
e830931ff4 wozers 2025-05-31 03:32:58 -04:00
ef678f31fd turns out neovim supports lsp line diagnostics natively 2025-05-19 02:22:49 -04:00
f9311db805 try and make everything confined to 80chars 2025-05-18 22:33:36 -04:00
d0155fcc7c make telescope work better in projects 2025-05-18 22:22:39 -04:00
df666dec0f fix dap
add showkeys thingy
remove nyooom
2025-05-18 14:28:57 -04:00
450750835a need I say what type of commit this is?
*kitchen sink*
2025-05-18 13:03:31 -05:00
77130d61af add a lil guy who provides git information on the current buffer 2025-05-09 17:58:06 -05:00
922dfb8c7e opts.lua 2025-05-09 00:17:42 -05:00
f3bd08968a formatting 2025-05-09 00:16:55 -05:00
a6007ff694 this hasn't worked for a long time, I might choose to re-impl if I have time 2025-05-09 00:15:41 -05:00
59 changed files with 1348 additions and 960 deletions

View File

@ -1,3 +1,2 @@
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
# I don't like stylua formatting in my config
ignore = [ "./" ]

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,18 +1,24 @@
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 jdtls = require("jdtls")
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 map, auto = core.misc.map, core.misc.auto
local ok, jdtls = pcall(require, "jdtls")
if not ok then
vim.notify("jdtls not loaded, can't setup jdtls lsp or dap")
return
end
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",
"-jar", -- 💀
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",
@ -23,7 +29,7 @@ local config = {
"-Dlog.level=ALL",
"-Dlog.protocol=true",
"-Dosgi.bundles.defaultStartLevel=4",
"-Xmx1G",
"-Xmx1G"
},
root_dir = vim.fs.dirname(vim.fs.find({
@ -48,6 +54,7 @@ local config = {
map("x", "crc", function() jdtls.extract_constant(true) end, opts)
map("x", "crm", function() jdtls.extract_method(true) end, opts)
-- do some refreshes often because I don't trust jdtls
pcall(vim.lsp.codelens.refresh)
auto("BufWritePost", {
buffer = bufnr,
@ -58,7 +65,13 @@ local config = {
})
-- setup nvim-dap
require("dap").adapters.java = nil -- remove any old java adapters
local ok, dap = pcall(require, "dap")
if not ok then
vim.notify("dap not loaded can't setup dap for jdtls")
return
end
dap.adapters.java = nil -- remove any old java adapters
jdtls.setup_dap({ hotcodereplace = "auto" })
require("jdtls.dap").setup_dap_main_class_configs()
end,
@ -71,7 +84,7 @@ 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)
)
}
@ -79,10 +92,12 @@ local config = {
}
-- generate the path to the java file(s)
---@type string|nil
local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"), "/JavaVersion.class")
---@type string|nil
local src_path = vim.fs.joinpath(vim.fn.stdpath("config"), "/extras/JavaVersion.java")
---@type string?
local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"),
"/JavaVersion.class")
---@type string?
local src_path = vim.fs.joinpath(vim.fn.stdpath("config"),
"/extras/JavaVersion.java")
-- if either path is invalid
if not cache_path or not src_path then
@ -92,19 +107,18 @@ end
--- build a cache of the JavaVersion code
local function build_cache()
-- check if we have javac
vim.system({ "javac" }, {}, function(out)
if out.code == 127 then
cache_path = nil
return
end
if vim.fn.executable("javac") ~= 1 then
cache_path = nil
return
end
-- compile our code
vim.system({ "javac", src_path, "-d", vim.fn.stdpath("cache") }, {}, function(out)
-- compile our code
vim.system({ "javac", src_path, "-d", vim.fn.stdpath("cache"), }, {},
function(out)
if out.code ~= 0 then
cache_path = nil
end
end)
end)
end
-- check if we have a compiled version of JavaVersion
@ -130,20 +144,17 @@ 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)
vim.notify(string.format(
"%s", vim.inspect(out.stdout)),
vim.log.levels.ERROR, { title = misc.appid })
"%s", vim.inspect(out.stdout)), vim.log.levels.ERROR)
return false
elseif not v then
vim.notify("no java version info found", vim.log.levels.ERROR,
{ title = misc.appid })
vim.notify("no java version info found", vim.log.levels.ERROR)
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 })
v[1].."."..v[2].."."..v[3]), vim.log.levels.ERROR)
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
@ -16,5 +15,5 @@ end)
-- change neovim root
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 })
vim.notify("root dir updated: "..vim.b.netrw_curdir)
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)
@ -21,7 +21,7 @@ return {
usePlaceholders = true,
clangdFileStatus = true,
fallback_flags = {
"-xc" -- makes clangd think we"re using c instead of c++
-- "-xc" -- makes clangd think we"re using c instead of c++
}
}
}

View File

@ -1 +1,5 @@
vim.cmd("colorscheme mellow")
if vim.fn.has("termguicolors") and not os.getenv("TERM") ~= "linux" then
vim.cmd("colorscheme mellow")
else
vim.cmd("colorscheme default")
end

3
extras/c.sh Normal file
View File

@ -0,0 +1,3 @@
# TODO:
# add something to check if we need to run bear again to update
# clangd build options

View File

@ -1,44 +1,33 @@
-- TODO: after switching to dep with lazy loading check out vim-startuptime
-- again
-- load core utilities
_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"
if vim.fn.empty(vim.fn.glob(path)) > 0 then
vim.fn.system({ "git", "clone", "--depth=1", "https://git.squi.bid/dep", path })
if not vim.uv.fs_stat(path) then
vim.fn.system({ "git", "clone", "--depth=1", "https://git.squi.bid/squibid/dep",
"--branch=lazy", path })
end
vim.opt.rtp:prepend(path)
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
_G.dep_short = require("dep.lazy.loader.short")
-- load plugins
require("dep") {
{ "squibid/dep",
url = "https://git.squi.bid/dep",
branch = "dev"
url = "https://git.squi.bid/squibid/dep",
branch = "lazy"
},
load = function()
-- aquire all plugin specs
local plugs = {}
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$", ""))
if type(ret) ~= "boolean" then
plugs[#plugs + 1] = ret
end
end
return plugs
end
modules = {
prefix = "conf.plugins"
}
}

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")
@ -48,3 +47,5 @@ auto("BufWritePre", {
vim.fn.mkdir(dir, "p")
end
})
core.color.setup_termbg_sync()

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
@ -14,8 +13,8 @@ map("v", "<S-j>", ":m '>+1<CR>gv=gv", { desc = "Move selected text down." })
map("n", "<S-j>", "mzJ`z<cmd>delm z<CR>") -- when combining lines
map("n", "n", "nzzzv") -- when searching
map("n", "N", "Nzzzv")
map("n", "<C-d>", "<C-d>zzzv") -- half page jumping
map("n", "<C-u>", "<C-u>zzzv")
map("n", "<C-d>", "<C-d>zz") -- half page jumping
map("n", "<C-u>", "<C-u>zz")
map({ "n", "i" }, "<C-c>", "<Esc>")
@ -24,14 +23,16 @@ map("n", "<leader>x", function() -- execute order 111
if vim.fn.getftype(fn) == "file" then
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 })
vim.fn.setfperm(fn, string.sub(fn, 1, 2).."-"..string.sub(fn, 4, 5).."-"..string.sub(fn, 7, 8).."-")
vim.notify("Removed executable flags")
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 })
vim.fn.setfperm(fn, string.sub(fn, 1, 2).."x"..string.sub(fn, 4, 5).."x"..string.sub(fn, 7, 8).."x")
vim.notify("Add executable flags")
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 })
vim.notify("File doesn't exist")
end
end, { desc = "toggle executable flag of the file" })
@ -50,7 +51,8 @@ vim.keymap.set("n", "z=", function()
end
local cword = vim.fn.expand("<cword>")
local prompt = "Change "..vim.inspect(cword).." to:"
vim.ui.select(vim.fn.spellsuggest(cword, vim.o.lines), { prompt = prompt }, spell_on_choice)
vim.ui.select(vim.fn.spellsuggest(cword, vim.o.lines), { prompt = prompt },
spell_on_choice)
end, { desc = "Shows spelling suggestions" })
-- quickfix

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,12 +1,10 @@
local misc = require("core.misc")
local auto = misc.auto
-- color stuff
if vim.fn.has("termguicolors") then
vim.opt.termguicolors = true
end
vim.opt.laststatus = 3
-- make .h files default to c code
vim.filetype.add({ extension = { h = "c", }, })
-- numbers
vim.opt.number = true
@ -64,95 +62,122 @@ vim.g.netrw_liststyle = 1
vim.g.netrw_sizestyle = "H"
vim.g.netrw_hide = 1
-- border (this doesn"t actually do anything within vim, I"m just setting it
-- here so it"s easy to find)
-- border (this doesn't actually do anything within vim, I'm just setting it
-- here so it's easy to find)
vim.g.border_style = "solid"
-- folding
auto("FileType", {
callback = function()
-- FIXME: it causes errors every once in a while
-- support lsp folding
-- if vim.fn.has("nvim-0.11") then
-- auto("LspAttach", {
-- callback = function(args)
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- if not client then
-- return
-- end
do -- folding
vim.opt.foldmethod = "syntax"
vim.opt.foldlevelstart = 99
vim.opt.foldlevel = 99
vim.opt.foldenable = true
vim.o.fillchars = "fold: ,eob: "
-- if client:supports_method("textDocument/foldingRange") then
-- local win = vim.api.nvim_get_current_win()
-- vim.wo[win][0].foldmethod = "expr"
-- vim.wo[win][0].foldexpr = "v:lua.vim.lsp.foldexpr()"
-- end
-- end,
-- })
-- end
-- or just rely on treesitter
if require("nvim-treesitter.parsers").has_parser() then
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
else
vim.opt.foldmethod = "syntax"
end
end
})
-- lsp folding: vim.o.foldexpr = "v:lua.vim.lsp.foldexpr()"
-- waiting on https://github.com/neovim/neovim/pull/31311 to hit a release
vim.lsp.config['*'] = {
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
}
}
}
vim.opt.foldlevelstart = 99
vim.opt.foldlevel = 99
vim.opt.foldenable = true
vim.o.fillchars = "fold: "
_G.Fold_text = require("core.folding")
vim.opt.foldtext = "v:lua.Fold_text()"
-- statusline
function _G.Status()
local function percentage()
local percent, line, lines
line = vim.api.nvim_win_get_cursor(0)[1]
lines = vim.api.nvim_buf_line_count(0)
percent = math.floor((line / lines) * 100)
if percent == 0 then
return "Top"
elseif percent == 100 then
return "Bot"
end
return percent.."%%"
end
return table.concat {
"%t", -- file name
" %h", -- help buffer tag
"%m", -- modify tag
"%r", -- readonly flag
"%=", -- seperate left and right side
-- print out the number of lsp clients attached
"λ"..#vim.lsp.get_clients({ bufnr = 0 }).." ",
"%<", -- we can start truncating here (I want to keep the file name)
"%l,%c%V", -- line, column-virtual column
"%<", -- we can start truncating here
" "..percentage() -- percentage through the buffer
}
vim.opt.foldtext = "v:lua.core.folding()"
end
do -- statusline
local last_bufnr, i = 1, 1
--- status line
---@return string out formatted status line
function _G.Status()
--- get the percentage through the file
---@return string out the formatted percentage
local function percentage()
local percent, line, lines
-- get the current and total # of lines
line = vim.api.nvim_win_get_cursor(0)[1]
lines = vim.api.nvim_buf_line_count(0)
-- calculate the percentage through the file
percent = math.floor((line / lines) * 100)
if percent == 0 or line == 1 then
return "Top"
elseif percent == 100 or line == lines then
return "Bot"
end
return percent.."%%"
end
--- get the number of lsp servers
---@return string out the formatted number of servers
local function lsp_servers()
local out, nclients, hi
local hi_groups = { "@boolean", "@constant", "@keyword", "@number" }
-- get the number of clients
nclients = #vim.lsp.get_clients({ bufnr = 0 })
-- set the client display
out = "λ"..nclients
if nclients > 0 then
local bufnr = vim.api.nvim_win_get_buf(0)
if bufnr ~= last_bufnr then
last_bufnr = bufnr
i = i + 1
if i > #hi_groups then
i = 1
end
end
hi = "%#"..hi_groups[i].."#"
out = hi..out.."%#StatusLine#"
end
return out
end
--- get git status information
---@return string out git status information or nothing
local function gitsigns()
local reset = "%#StatusLine#"
local hl = reset
local lil_guy = "o/"
---@type table
local status = vim.b.gitsigns_status_dict
if not status then
return ""
end
if status.removed and status.removed > 0 then
hl = "%#GitSignsDelete#"
lil_guy = "<o>"
elseif status.changed and status.changed > 0 then
hl = "%#GitSignsChange#"
lil_guy = "o7"
elseif status.added and status.added > 0 then
hl = "%#GitSignsAdd#"
lil_guy = "\\o/"
end
return hl..lil_guy..reset
end
-- this is my statusline:
--
-- opts.lua [+] o/ λ1 163,61-60 88%
--
return table.concat {
"%t", -- file name
" %h", -- help buffer tag
"%m", -- modify tag
"%r", -- readonly flag
"%=", -- seperate left and right side
-- print out git status information in the form of a lil guy
gitsigns(), " ",
-- print out the number of lsp clients attached with nice colors :)
lsp_servers(), " ",
"%<", -- we can start truncating here (I want to keep the file name)
"%l,%c%V", -- line, column-virtual column
"%<", -- we can start truncating here
" "..percentage() -- percentage through the buffer
}
end
vim.opt.statusline = "%!v:lua.Status()"
vim.opt.laststatus = 3
end
vim.o.statusline="%!v:lua.Status()"

View File

@ -1,10 +1,11 @@
return { "Saghen/blink.cmp",
branch = "v1.2.0",
requires = {
branch = "v1.*",
reqs = {
"xzbdmw/colorful-menu.nvim",
"L3MON4D3/LuaSnip"
},
function()
lazy = dep_short.auto("InsertEnter"),
load = function()
local colormenu = require("colorful-menu")
require("blink.cmp").setup {
keymap = {

View File

@ -1,5 +1,5 @@
return { "numToStr/Comment.nvim",
function()
load = function()
require("Comment").setup {
ignore = "^$"
}

View File

@ -1,27 +0,0 @@
return { "theHamsta/nvim-dap-virtual-text",
requires = {
"nvim-treesitter/nvim-treesitter",
"mfussenegger/nvim-dap"
},
function()
require("nvim-dap-virtual-text").setup {
virt_text_pos = vim.fn.has("nvim-0.10") == 1 and "inline" or "eol",
--- A callback that determines how a variable is displayed or whether it should be omitted
--- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable
--- @param buf number
--- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame
--- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`)
--- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text
--- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed
display_callback = function(variable, buf, stackframe, node, options)
-- by default, strip out new line characters
if options.virt_text_pos == "inline" then
return " = "..variable.value:gsub("%s+", " ")
else
return variable.name.." = "..variable.value:gsub("%s+", " ")
end
end
}
end
}

View File

@ -1,33 +1,22 @@
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
local function set_hover_bind()
for _, buf in pairs(vim.api.nvim_list_bufs()) do
local keymaps = vim.api.nvim_buf_get_keymap(buf, 'n')
local keymaps = vim.api.nvim_buf_get_keymap(buf, "n")
for _, keymap in pairs(keymaps) do
if keymap.lhs == "K" then
table.insert(keymap_restore, keymap)
vim.api.nvim_buf_del_keymap(buf, 'n', 'K')
vim.api.nvim_buf_del_keymap(buf, "n", "K")
end
end
end
vim.keymap.set('n', 'K', require("dap.ui.widgets").hover,
{ silent = true })
map("n", "K", function()
require("dap.ui.widgets").hover(nil, {
border = vim.g.border_style
})
end, { silent = true })
end
--- revert the hover bind back to whatever it was
@ -44,55 +33,110 @@ local function unset_hover_bind()
keymap_restore = {}
end
return { "mfussenegger/nvim-dap",
requires = {
"mason-org/mason.nvim",
"nvim-telescope/telescope.nvim"
},
disable = not vim.fn.has("nvim-0.9.5"),
branch = "0.10.0",
function()
local dap = require("dap")
return {
{ "mfussenegger/nvim-dap",
reqs = {
"mason-org/mason.nvim",
"nvim-telescope/telescope.nvim"
},
deps = "theHamsta/nvim-dap-virtual-text",
disable = not vim.fn.has("nvim-0.9.5"),
branch = "0.10.0",
lazy = function(load)
load:keymap("n", "<leader>ec")
load:keymap("n", "<leader>el")
load:keymap("n", "<leader>et")
load:keymap("n", "<leader>eb")
load:keymap("n", "<leader>e]")
load:keymap("n", "<leader>e[")
load:keymap("n", "<leader>er")
load:keymap("n", "<leader>eR")
end,
load = function()
local dap = require("dap")
-- define codelldb
dap.adapters.codelldb = {
type = "executable",
command = "codelldb",
}
-- define the c configuration for codelldb
dap.configurations.c = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = select_program,
cwd = "${workspaceFolder}",
stopOnEntry = false
-- define codelldb
dap.adapters.codelldb = {
type = "executable",
command = "codelldb"
}
}
-- and define them for cpp, zig, and rust
dap.configurations.cpp = dap.configurations.c
dap.configurations.zig = dap.configurations.c
dap.configurations.rust = dap.configurations.c
-- define the c configuration for codelldb
dap.configurations.c = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd().."/", "file")
end,
-- keybinds
map("n", "<Leader>ec", dap.continue, { desc = "dap continue " })
map("n", "<Leader>el", dap.run_last, { desc = "dap run last" })
map("n", "<Leader>et", function()
dap.terminate()
unset_hover_bind()
end, { desc = "dap terminate " })
map("n", "<Leader>eb", require("dap.breakpoints").toggle, { desc = "dap toggle breakpoint" })
map("n", "<Leader>e]", dap.step_over, { desc = "dap step over" })
map("n", "<Leader>e[", dap.step_back, { desc = "dap step back" })
map("n", "<Leader>er", dap.repl.toggle, { desc = "dap repl toggle" })
map("n", "<Leader>eR", dap.restart, { desc = "dap restart" })
cwd = "${workspaceFolder}",
stopOnEntry = false
}
}
-- events
dap.listeners.after['event_initialized']['me'] = set_hover_bind
dap.listeners.after['event_terminated']['me'] = unset_hover_bind
end
-- and define them for cpp, zig, and rust
dap.configurations.cpp = dap.configurations.c
dap.configurations.zig = dap.configurations.c
dap.configurations.rust = dap.configurations.c
-- keybinds
map("n", "<leader>ec", dap.continue, { desc = "dap continue" })
map("n", "<leader>el", dap.run_last, { desc = "dap run last" })
map("n", "<leader>et", function()
dap.terminate()
unset_hover_bind()
end, { desc = "dap terminate " })
map("n", "<leader>eb", require("dap.breakpoints").toggle, {
desc = "dap toggle breakpoint"
})
map("n", "<leader>e]", dap.step_over, { desc = "dap step over" })
map("n", "<leader>e[", dap.step_back, { desc = "dap step back" })
map("n", "<leader>er", dap.repl.toggle, { desc = "dap repl toggle" })
map("n", "<leader>eR", dap.restart, { desc = "dap restart" })
-- events
dap.listeners.after["event_initialized"]["me"] = set_hover_bind
dap.listeners.after["event_terminated"]["me"] = unset_hover_bind
end
},
{ "theHamsta/nvim-dap-virtual-text",
reqs = {
"nvim-treesitter/nvim-treesitter",
"mfussenegger/nvim-dap"
},
lazy = dep_short.cmd("DapVirtualTextToggle"),
load = function()
require("nvim-dap-virtual-text").setup {
virt_text_pos = vim.fn.has("nvim-0.10") == 1 and "inline" or "eol",
--- A callback that determines how a variable is displayed or whether it should be omitted
--- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable
--- @param buf number
--- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame
--- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`)
--- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text
--- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed
display_callback = function(variable, buf, stackframe, node, options)
-- by default, strip out new line characters
if options.virt_text_pos == "inline" then
return " = "..variable.value:gsub("%s+", " ")
else
return variable.name.." = "..variable.value:gsub("%s+", " ")
end
end
}
end
},
{ "mfussenegger/nvim-dap-python",
reqs = "mfussenegger/nvim-dap",
lazy = dep_short.ft("python"),
load = function()
local debugpy = core.mason.get_pkg_path("debugpy", "/venv/bin/python3")
require("dap-python").setup(debugpy)
end
}
}

View File

@ -1,36 +0,0 @@
return { "j-hui/fidget.nvim",
disable = not vim.fn.has("nvim-0.9.0"),
branch = "v1.5.0",
function()
local notification_defaults = require("fidget.notification").default_config
notification_defaults["icon"] = ""
require("fidget").setup {
progress = {
display = {
progress_icon = {
pattern = "line",
period = 1
},
done_icon = ":)"
}
},
notification = {
filter = vim.log.levels.DEBUG,
override_vim_notify = true,
configs = {
default = notification_defaults
},
view = {
icon_separator = " ",
group_separator = "---",
group_separator_hl = "Comment"
},
window = {
zindex = 44,
relative = "editor"
}
}
}
end
}

View File

@ -1,9 +1,19 @@
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"),
function()
lazy = function(load)
load:auto({ "BufEnter", "BufNew" }, {
callback = function()
local paths = vim.fs.find({ ".git", }, { upward = true })
if #paths > 0 then
load:cleanup()
end
end
})
load:cmd("Gitsigns")
end,
load = function()
local gs = require("gitsigns")
gs.setup {

View File

@ -1,32 +0,0 @@
local misc = require("core.misc")
local map = misc.map
return { "ThePrimeagen/harpoon",
disable = not vim.fn.has("nvim-0.8.0"),
commit = "e76cb03",
branch = "harpoon2",
requires = "nvim-lua/plenary.nvim",
function()
local harpoon = require("harpoon")
harpoon:setup()
map("n", "<leader>a", function()
harpoon:list():add()
vim.notify("added "..vim.fn.expand("%:t").." to quickmarks", vim.log.levels.INFO, {
title = misc.appid
})
end, { desc = "add current file to quickmarks" })
map("n", "<C-e>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
map("n", "<C-h>", function() harpoon:list():select(1) end)
map("n", "<C-t>", function() harpoon:list():select(2) end)
map("n", "<C-n>", function() harpoon:list():select(3) end)
map("n", "<C-c>", function() harpoon:list():select(4) end)
-- Toggle previous & next buffers stored within Harpoon list
map("n", "<C-S-P>", function() harpoon:list():prev() end)
map("n", "<C-S-N>", function() harpoon:list():next() end)
end
}

View File

@ -1 +1,3 @@
return { "tweekmonster/helpful.vim" }
return { "tweekmonster/helpful.vim",
lazy = dep_short.cmd("HelpfulVersion")
}

View File

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

View File

@ -1,5 +0,0 @@
return { "jbyuki/instant.nvim",
function()
vim.g.instant_username = "squibid"
end
}

View File

@ -1,4 +0,0 @@
return { "mfussenegger/nvim-jdtls",
disable = not vim.fn.has("nvim-0.6.0"),
requires = "mfussenegger/nvim-dap"
}

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
}

135
lua/conf/plugins/lsp.lua Normal file
View File

@ -0,0 +1,135 @@
local nonels_augroup = core.misc.augroup("nullls formatting")
return {
{ "neovim/nvim-lspconfig",
disable = not vim.fn.has("nvim-0.10.0"),
reqs = {
"mason-org/mason.nvim",
"mason-org/mason-lspconfig.nvim"
},
load = function()
core.lsp.setup()
require("mason-lspconfig").setup {
ensure_added = {
"clangd",
"mesonlsp",
"bashls",
"jdtls",
"lua_ls",
-- python
"basedpyright",
"mypy",
"black",
"debugpy"
}
}
end
},
{ "mason-org/mason.nvim",
disable = not vim.fn.has("nvim-0.7.0"),
load = function()
local mason = require("mason")
mason.setup {
ui = {
border = vim.g.border_style,
width = 0.8,
height = 0.9,
icons = {
package_installed = "+",
package_pending = "?",
package_uninstalled = "x"
}
},
keymaps = {
toggle_package_expand = "<CR>",
install_package = "i",
update_package = "u",
check_package_version = "c",
update_all_packages = "U",
check_outdated_packages = "C",
uninstall_package = "r",
cancel_installation = "<C-c>",
apply_language_filter = "<C-f>"
}
}
end
},
{ "j-hui/fidget.nvim",
disable = not vim.fn.has("nvim-0.9.0"),
branch = "v1.*",
lazy = dep_short.auto("LspAttach"),
load = function()
local notification_defaults = require("fidget.notification").default_config
notification_defaults["icon"] = ""
require("fidget").setup {
progress = {
display = {
progress_icon = {
pattern = "line",
period = 1
},
done_icon = ":)"
}
},
notification = {
filter = vim.log.levels.DEBUG,
override_vim_notify = true,
configs = {
default = notification_defaults
},
view = {
icon_separator = " ",
group_separator = "---",
group_separator_hl = "Comment"
},
window = {
zindex = 44,
relative = "editor"
}
}
}
end
},
{ "mfussenegger/nvim-jdtls",
disable = not vim.fn.has("nvim-0.6.0"),
reqs = "mfussenegger/nvim-dap",
lazy = dep_short.ft("java")
},
{ "nvimtools/none-ls.nvim",
lazy = dep_short.ft("python"),
load = function()
local null_ls = require("null-ls")
null_ls.setup {
sources = {
null_ls.builtins.formatting.black,
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({
group = nonels_augroup,
buffer = bufnr
})
core.misc.auto("BufWritePre", {
group = nonels_augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end
})
end
end
}
end
}
}

View File

@ -1,4 +0,0 @@
return { "whynothugo/lsp_lines",
url = "https://git.sr.ht/~whynothugo/lsp_lines.nvim",
disable = not vim.fn.has("nvim-0.8.0")
}

View File

@ -1,17 +0,0 @@
return { "neovim/nvim-lspconfig",
disable = not vim.fn.has("nvim-0.10.0"),
requires = {
"mason-org/mason.nvim",
"mason-org/mason-lspconfig.nvim"
},
function()
require("core.lsp.functions").setup()
require("mason-lspconfig").setup {
ensure_added = {
"clangd",
"lua_ls",
"jdtls"
}
}
end
}

View File

@ -1,13 +1,18 @@
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",
branch = "v2.*",
disable = not vim.fn.has("nvim-0.7.0"),
config = function()
vim.cmd("make install_jsregexp")
end,
function()
lazy = function(load)
load:keymap("n", "<c-a>")
load:keymap("n", "<c-e>")
load:keymap("n", "<c-j>")
load:keymap("n", "<c-k>")
end,
load = function()
local luasnip = require("luasnip")
local types = require("luasnip.util.types")
@ -20,12 +25,7 @@ return { "L3MON4D3/LuaSnip",
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = {{ "", "@boolean" }}
}
},
[types.insertNode] = {
active = {
virt_text = {{ "", "@constant" }}
virt_text = {{ "?", "@boolean" }}
}
}
}
@ -55,13 +55,21 @@ return { "L3MON4D3/LuaSnip",
end
end)
-- load all snippets from snippet directory
for _, file in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua", true)) do
-- 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)
if type(ret) ~= "boolean" then
luasnip.add_snippets(fn, ret, { key = fn })
end
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,31 +0,0 @@
return { "mason-org/mason.nvim",
disable = not vim.fn.has("nvim-0.7.0"),
function()
local mason = require("mason")
mason.setup {
ui = {
border = vim.g.border_style,
width = 0.8,
height = 0.9,
icons = {
package_installed = "+",
package_pending = "?",
package_uninstalled = "x"
}
},
keymaps = {
toggle_package_expand = "<CR>",
install_package = "i",
update_package = "u",
check_package_version = "c",
update_all_packages = "U",
check_outdated_packages = "C",
uninstall_package = "r",
cancel_installation = "<C-c>",
apply_language_filter = "<C-f>"
}
}
end
}

View File

@ -1,29 +1,50 @@
return { "mellow-theme/mellow.nvim",
disable = not vim.fn.has("nvim-0.8.0"),
requires = "nvim-treesitter/nvim-treesitter",
function()
reqs = "nvim-treesitter/nvim-treesitter",
load = function()
vim.g.mellow_variant = "dark"
local c = require("mellow.colors")[vim.g.mellow_variant]
vim.g.mellow_highlight_overrides = {
-- stop inactive windows from having a darker bg
["NormalNC"] = { link = "Normal" },
if vim.g.mellow_variant == "dark" then
vim.g.mellow_highlight_overrides = {
-- stop inactive windows from having a darker bg
["NormalNC"] = { link = "Normal" },
-- make floats darker
["NormalFloat"] = { fg = c.fg, bg = "#111111" },
["FloatBorder"] = { link = "NormalFloat" },
-- revert change with statusline coloring
["StatusLine"] = { fg = c.white, bg = c.gray01 },
["StatusLineNC"] = { fg = c.bg_dark },
-- make diagnostics have an undercurl
["DiagnosticUnderlineError"] = { fg = c.red, undercurl = true },
["DiagnosticUnderlineWarn"] = { fg = c.yellow, undercurl = true },
["DiagnosticUnderlineInfo"] = { fg = c.blue, undercurl = true },
["DiagnosticUnderlineHint"] = { fg = c.cyan, undercurl = true },
-- make splits look cleaner
["WinSeparator"] = { fg = c.gray01 },
-- make blink actually look nice
["BlinkCmpMenu"] = { link = "NormalFloat" },
["BlinkCmpMenuBorder"] = { link = "BlinkCmpMenu" },
["BlinkCmpMenuSelection"] = { bg = c.gray01 },
["BlinkCmpLabelDeprecated"] = { link = "CmpItemAbbrDeprecated" }
}
-- make floats darker
["NormalFloat"] = { fg = c.fg, bg = "#111111" },
["FloatBorder"] = { link = "NormalFloat" },
-- make diagnostics have an undercurl
["DiagnosticUnderlineError"] = { fg = c.red, undercurl = true },
["DiagnosticUnderlineWarn"] = { fg = c.yellow, undercurl = true },
["DiagnosticUnderlineInfo"] = { fg = c.blue, undercurl = true },
["DiagnosticUnderlineHint"] = { fg = c.cyan, undercurl = true },
["DiagnosticHint"] = { fg = c.cyan }, -- revert
-- make blink actually look nice
["BlinkCmpMenu"] = { link = "NormalFloat" },
["BlinkCmpMenuBorder"] = { link = "BlinkCmpMenu" },
["BlinkCmpMenuSelection"] = { bg = c.gray01 },
["BlinkCmpLabelDeprecated"] = { link = "CmpItemAbbrDeprecated" },
["BlinkCmpLabelMatch"] = { link = "NormalFloat" }, -- reverted
-- telescope styling so I can see when coding outside (real)
["TelescopeResultsNormal"] = { bg = c.bg_dark },
["TelescopeResultsBorder"] = { link = "TelescopeResultsNormal" },
["TelescopeResultsTitle"] = {
bg = core.color.copyhl("TelescopeResultsNormal").background,
fg = core.color.copyhl("TelescopeResultsNormal").background
},
["TelescopePreviewNormal"] = { link = "NormalFloat" },
["TelescopePreviewBorder"] = { link = "TelescopePreviewNormal" }
}
end
end
}

View File

@ -1,12 +1,12 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "danymat/neogen",
requires = {
reqs = {
"nvim-treesitter/nvim-treesitter",
"L3MON4D3/LuaSnip"
},
function()
lazy = dep_short.keymap("n", "<leader>d"),
load = function()
local neogen = require("neogen")
neogen.setup {
enabled = true,

View File

@ -1,6 +1,6 @@
return { "norcalli/nvim-colorizer.lua",
disable = not vim.fn.has("nvim-0.4.0") and not vim.fn.has("termguicolors"),
function()
load = function()
require("colorizer").setup(nil, {
names = false,
css = true

View File

@ -1,7 +0,0 @@
return { "squibid/nyooom",
url = "https://git.squi.bid/nyooom",
pin = true,
function()
require("nyooom").setup {}
end
}

View File

@ -1,12 +1,12 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
-- helper function to parse output
local function parse_output(proc)
local result = proc:wait()
local ret = {}
if result.code == 0 then
for line in vim.gsplit(result.stdout, "\n", { plain = true, trimempty = true }) do
for line in vim.gsplit(result.stdout, "\n", {
plain = true, trimempty = true }) do
-- Remove trailing slash
line = line:gsub("/$", "")
ret[line] = true
@ -20,16 +20,20 @@ local function new_git_status()
return setmetatable({}, {
__index = function(self, key)
local ignore_proc = vim.system(
{ "git", "ls-files", "--ignored", "--exclude-standard", "--others", "--directory" },
{ "git", "ls-files", "--ignored", "--exclude-standard", "--others",
"--directory" },
{
cwd = key,
text = true,
}
)
local tracked_proc = vim.system({ "git", "ls-tree", "HEAD",
"--name-only" },
{
cwd = key,
text = true,
}
)
local tracked_proc = vim.system({ "git", "ls-tree", "HEAD", "--name-only" }, {
cwd = key,
text = true,
})
local ret = {
ignored = parse_output(ignore_proc),
tracked = parse_output(tracked_proc),
@ -49,186 +53,190 @@ local permission_hlgroups = {
["x"] = "DiagnosticSignOk",
}
return { "stevearc/oil.nvim",
disable = not vim.fn.has("nvim-0.8.0"),
deps = {
{ "refractalize/oil-git-status.nvim",
function()
require("oil-git-status").setup {
symbols = { -- customize the symbols that appear in the git status columns
index = {
["A"] = "+",
["D"] = "-",
["M"] = "~",
},
working_tree = {
["A"] = "+",
["D"] = "-",
["M"] = "~",
}
}
}
return {
{ "stevearc/oil.nvim",
disable = not vim.fn.has("nvim-0.8.0"),
lazy = dep_short.keymap("n", "-"),
load = function()
-- Clear git status cache on refresh
local refresh = require("oil.actions").refresh
local orig_refresh = refresh.callback
refresh.callback = function(...)
git_status = new_git_status()
orig_refresh(...)
end
}
},
function()
-- Clear git status cache on refresh
local refresh = require("oil.actions").refresh
local orig_refresh = refresh.callback
refresh.callback = function(...)
git_status = new_git_status()
orig_refresh(...)
end
require("oil").setup {
-- ID is automatically added at the beginning, and name at the end
-- See :help oil-columns
columns = {
{
"permissions",
highlight = function(permission_str)
local hls = {}
for i = 1, #permission_str do
local char = permission_str:sub(i, i)
table.insert(hls, { permission_hlgroups[char], i - 1, i })
require("oil").setup {
-- ID is automatically added at the beginning, and name at the end
-- See :help oil-columns
columns = {
{
"permissions",
highlight = function(permission_str)
local hls = {}
for i = 1, #permission_str do
local char = permission_str:sub(i, i)
table.insert(hls, { permission_hlgroups[char], i - 1, i })
end
return hls
end,
},
{ "size", highlight = "@number" }
},
-- Window-local options to use for oil buffers
win_options = {
number = false,
relativenumber = false,
wrap = false,
signcolumn = "yes:2",
cursorcolumn = false,
foldcolumn = "0",
spell = false,
list = false,
conceallevel = 3,
concealcursor = "nvic"
},
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
delete_to_trash = false,
-- Skip the confirmation popup for simple operations (:help oil.skip_confirm_for_simple_edits)
skip_confirm_for_simple_edits = false,
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
-- (:help prompt_save_on_select_new_entry)
prompt_save_on_select_new_entry = true,
-- Oil will automatically delete hidden buffers after this delay
-- You can set the delay to false to disable cleanup entirely
-- Note that the cleanup process only starts when none of the oil buffers are currently displayed
cleanup_delay_ms = 2000,
lsp_file_methods = {
-- Enable or disable LSP file operations
enabled = true,
-- Time to wait for LSP file operations to complete before skipping
timeout_ms = 1000,
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
-- Set to "unmodified" to only save unmodified buffers
autosave_changes = "unmodified"
},
-- Constrain the cursor to the editable parts of the oil buffer
-- Set to `false` to disable, or "name" to keep it on the file names
constrain_cursor = "editable",
-- Set to true to watch the filesystem for changes and reload oil
watch_for_changes = false,
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
-- Additionally, if it is a string that matches "actions.<name>",
-- it will use the mapping at require("oil.actions").<name>
-- Set to `false` to remove a keymap
-- See :help oil-actions for a list of all available actions
keymaps = {
["g?"] = { "actions.show_help", mode = "n" },
["<C-l>"] = "actions.refresh",
["<CR>"] = "actions.select",
["-"] = { "actions.parent", mode = "n" },
["_"] = { "actions.open_cwd", mode = "n" },
["`"] = { "actions.cd", mode = "n" },
["~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" },
["gs"] = { "actions.change_sort", mode = "n" },
["gx"] = "actions.open_external",
["g."] = { "actions.toggle_hidden", mode = "n" },
["g\\"] = { "actions.toggle_trash", mode = "n" }
},
view_options = {
-- Show files and directories that start with "."
show_hidden = false,
-- This function defines what is considered a "hidden" file
is_hidden_file = function(name, bufnr)
local dir = require("oil").get_current_dir(bufnr)
local is_dotfile = vim.startswith(name, ".") and name ~= ".."
-- if no local directory (e.g. for ssh connections), just hide dotfiles
if not dir then
return is_dotfile
end
return hls
-- dotfiles are considered hidden unless tracked
if is_dotfile then
return not git_status[dir].tracked[name]
end
end,
-- This function defines what will never be shown, even when `show_hidden` is set
is_always_hidden = function(name, bufnr)
return false
end,
-- Sort file names with numbers in a more intuitive order for humans.
-- Can be "fast", true, or false. "fast" will turn it off for large directories.
natural_order = "fast",
-- Sort file and directory names case insensitive
case_insensitive = false,
sort = {
-- sort order can be "asc" or "desc"
-- see :help oil-columns to see which columns are sortable
{ "type", "asc" },
{ "name", "asc" },
},
-- Customize the highlight group for the file name
highlight_filename = function(entry, is_hidden, is_link_target, is_link_orphan)
return nil
end,
},
{ "size", highlight = "@number" }
},
-- Window-local options to use for oil buffers
win_options = {
number = false,
relativenumber = false,
wrap = false,
signcolumn = "yes:2",
cursorcolumn = false,
foldcolumn = "0",
spell = false,
list = false,
conceallevel = 3,
concealcursor = "nvic"
},
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
delete_to_trash = false,
-- Skip the confirmation popup for simple operations (:help oil.skip_confirm_for_simple_edits)
skip_confirm_for_simple_edits = false,
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
-- (:help prompt_save_on_select_new_entry)
prompt_save_on_select_new_entry = true,
-- Oil will automatically delete hidden buffers after this delay
-- You can set the delay to false to disable cleanup entirely
-- Note that the cleanup process only starts when none of the oil buffers are currently displayed
cleanup_delay_ms = 2000,
lsp_file_methods = {
-- Enable or disable LSP file operations
enabled = true,
-- Time to wait for LSP file operations to complete before skipping
timeout_ms = 1000,
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
-- Set to "unmodified" to only save unmodified buffers
autosave_changes = "unmodified"
},
-- Constrain the cursor to the editable parts of the oil buffer
-- Set to `false` to disable, or "name" to keep it on the file names
constrain_cursor = "editable",
-- Set to true to watch the filesystem for changes and reload oil
watch_for_changes = false,
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
-- Additionally, if it is a string that matches "actions.<name>",
-- it will use the mapping at require("oil.actions").<name>
-- Set to `false` to remove a keymap
-- See :help oil-actions for a list of all available actions
keymaps = {
["g?"] = { "actions.show_help", mode = "n" },
["<C-l>"] = "actions.refresh",
["<CR>"] = "actions.select",
["-"] = { "actions.parent", mode = "n" },
["_"] = { "actions.open_cwd", mode = "n" },
["`"] = { "actions.cd", mode = "n" },
["~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" },
["gs"] = { "actions.change_sort", mode = "n" },
["gx"] = "actions.open_external",
["g."] = { "actions.toggle_hidden", mode = "n" },
["g\\"] = { "actions.toggle_trash", mode = "n" }
},
view_options = {
-- Show files and directories that start with "."
show_hidden = false,
-- This function defines what is considered a "hidden" file
is_hidden_file = function(name, bufnr)
local dir = require("oil").get_current_dir(bufnr)
local is_dotfile = vim.startswith(name, ".") and name ~= ".."
-- if no local directory (e.g. for ssh connections), just hide dotfiles
if not dir then
return is_dotfile
end
-- dotfiles are considered hidden unless tracked
if is_dotfile then
return not git_status[dir].tracked[name]
end
end,
-- This function defines what will never be shown, even when `show_hidden` is set
is_always_hidden = function(name, bufnr)
return false
end,
-- Sort file names with numbers in a more intuitive order for humans.
-- Can be "fast", true, or false. "fast" will turn it off for large directories.
natural_order = "fast",
-- Sort file and directory names case insensitive
case_insensitive = false,
sort = {
-- sort order can be "asc" or "desc"
-- see :help oil-columns to see which columns are sortable
{ "type", "asc" },
{ "name", "asc" },
-- Configuration for the floating window in oil.open_float
float = {
border = vim.g.border_style
},
-- Customize the highlight group for the file name
highlight_filename = function(entry, is_hidden, is_link_target, is_link_orphan)
return nil
end,
},
-- Configuration for the floating window in oil.open_float
float = {
border = vim.g.border_style
},
-- Configuration for the floating action confirmation window
confirmation = {
border = vim.g.border_style
},
-- Configuration for the floating progress window
progress = {
border = vim.g.border_style
},
-- Configuration for the floating SSH window
ssh = {
border = vim.g.border_style
},
-- Configuration for the floating keymaps help window
keymaps_help = {
border = vim.g.border_style
-- Configuration for the floating action confirmation window
confirmation = {
border = vim.g.border_style
},
-- Configuration for the floating progress window
progress = {
border = vim.g.border_style
},
-- Configuration for the floating SSH window
ssh = {
border = vim.g.border_style
},
-- Configuration for the floating keymaps help window
keymaps_help = {
border = vim.g.border_style
}
}
}
map("n", "-", "<cmd>Oil<CR>")
end
map("n", "-", "<cmd>Oil<CR>")
end
},
{ "refractalize/oil-git-status.nvim",
reqs = "stevearc/oil.nvim",
lazy = dep_short.plugin("stevearc/oil.nvim"),
load = function()
require("oil-git-status").setup {
symbols = { -- customize the symbols that appear in the git status columns
index = {
["A"] = "+",
["D"] = "-",
["M"] = "~",
},
working_tree = {
["A"] = "+",
["D"] = "-",
["M"] = "~",
}
}
}
end
}
}

30
lua/conf/plugins/show.lua Normal file
View File

@ -0,0 +1,30 @@
return { "nvzone/showkeys",
lazy = dep_short.cmd("ShowKeysToggle"),
load = function()
require("showkeys").setup {
position = "top-right",
winopts = {
border = vim.g.border_style,
},
-- change the way it looks
winhl = "NormalFloat:Comment,NormalFloat:NormalFloat",
maxkeys = 3,
-- change the way keys are displayed
keyformat = {
["<BS>"] = "<BS>",
["<CR>"] = "<CR>",
["<Space>"] = "<Space>",
["<Up>"] = "<Up>",
["<Down>"] = "<Down>",
["<Left>"] = "<Left>",
["<Right>"] = "<Right>",
["<PageUp>"] = "<PageUp>",
["<PageDown>"] = "<PageDown>",
["<M>"] = "Alt",
["<C>"] = "Ctrl",
}
}
end
}

View File

@ -1,20 +1,55 @@
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
local function root_dir()
local clients = vim.lsp.get_clients({ bufnr = 0 })
if #clients > 0 then
return clients[1].config.root_dir
end
return "."
end
--- wrap a telebuilt picker to make it work for the current project root
---@param fn function telebuilt function
---@return function the new function
local function telebuilt_picker(fn)
return function()
fn { cwd = root_dir() }
end
end
return { "nvim-telescope/telescope.nvim",
disable = not vim.fn.has("nvim-0.9.0"),
requires = {
"nvim-lua/plenary.nvim",
reqs = {
{ "nvim-lua/plenary.nvim",
-- lazy = function(load)
-- load:cmd("PlenaryBustedDirectory")
-- load:cmd("PlenaryBustedFile")
-- end
},
{ "nvim-telescope/telescope-fzf-native.nvim",
config = function()
vim.cmd("make")
end
},
"mollerhoj/telescope-recent-files.nvim",
"nvim-telescope/telescope-ui-select.nvim"
},
function()
lazy = function(load)
load:cmd("Telescope")
load:keymap("n", "<leader>f")
load:keymap("n", "<leader>o")
load:keymap("n", "<leader>s")
load:keymap("n", "<leader>i")
load:keymap("n", "<leader>l")
load:keymap("n", "<leader>;")
load:keymap("n", "<leader>tc")
load:keymap("n", "<leader>tp")
end,
load = function()
local telescope = require("telescope")
local actions = require("telescope.actions")
@ -53,37 +88,40 @@ return { "nvim-telescope/telescope.nvim",
-- load in the fzf extension
telescope.load_extension("fzf")
telescope.load_extension("recent-files")
telescope.load_extension("ui-select")
-- keymaps
local telebuilt = require("telescope.builtin")
map("n", "<leader>f", function()
telescope.extensions["recent-files"].recent_files { follow = true }
end, { desc = "Find files." })
map("n", "<leader>s", telebuilt.live_grep, { desc = "Find string in project." })
map("n", "<leader>b", telebuilt.current_buffer_fuzzy_find, {
desc = "Find string in current buffer.",
map("n", "<leader>f", telebuilt_picker(telebuilt.find_files), {
desc = "Find files."
})
map("n", "<leader>i", telebuilt.help_tags, {
desc = "find help tags.",
map("n", "<leader>o", telebuilt.oldfiles, { desc = "Find old." })
map("n", "<leader>s", telebuilt_picker(telebuilt.live_grep), {
desc = "Find strings."
})
map("n", "<leader>i", telebuilt.help_tags, { desc = "find help tags." })
map("n", "<leader>l", telebuilt.lsp_document_symbols, {
desc = "Find symbols."
})
map("n", "<leader>;", telebuilt.lsp_workspace_symbols, {
desc = "Find Workspace symbols."
})
-- find over specific directories
map("n", "<leader>tc", function()
require("telescope.builtin").find_files {
cwd = vim.fn.stdpath("config")
}
telebuilt.find_files { cwd = vim.fn.stdpath("config") }
end, { desc = "find config files" })
map("n", "<leader>tp", function()
require("telescope.builtin").find_files {
telebuilt.find_files {
cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "site/pack/deps/opt")
}
end, { desc = "find files in plugin directory" })
-- enable previewing in the default colorscheme switcher
telebuilt.colorscheme = function()
require("telescope.builtin.__internal").colorscheme { enable_preview = true }
require("telescope.builtin.__internal").colorscheme {
enable_preview = true
}
end
end
}

View File

@ -1,7 +1,9 @@
-- 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"),
function()
reqs = "nvim-lua/plenary.nvim",
load = function()
require("todo-comments").setup {
keywords = {
FIX = {

View File

@ -1,59 +1,81 @@
table.contains = function(self, string)
for _, v in pairs(self) do
if v == string then
return true
end
end
return false
end
local map, auto = core.misc.map, core.misc.auto
return { "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.10.0"),
config = function()
vim.cmd("TSUpdate")
end,
function()
require("nvim-treesitter.configs").setup {
-- good default parsers
ensure_installed = { "c", "lua", "vim", "vimdoc", "markdown",
"markdown_inline", "java", "bash", "css", "html", "luadoc",
"make"
},
return {
{ "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.10.0"),
config = function()
vim.cmd("TSUpdate")
end,
load = function()
require("nvim-treesitter.configs").setup {
-- good default parsers
ensure_installed = { "c", "lua", "vim", "vimdoc", "markdown",
"markdown_inline", "java", "bash", "css", "html", "luadoc",
"make"
},
-- indentation
indent = {
enable = true,
-- indentation
indent = {
enable = true,
disable = function(lang, _)
-- disable indenting in php (it's more broken with than without)
return table.contains(({
"php"
}), lang)
end
},
-- enable highlighting
highlight = {
enable = true,
-- use vim highlighting in addition to treesitter
additional_vim_regex_highlighting = true,
disable = function(lang, buf)
-- disable in some files where vim's builtin highlighting is better
if table.contains(({
"diff", "tex"
}), lang) then
return true
disable = function(lang, _)
-- disable indenting in php (it's more broken with than without)
return table.contains(({
"php"
}), lang)
end
},
-- disable in big files
-- TODO: update before nvim 1.0 when vim.loop is removed
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > (1024 * 100 * 10) --[[1MB]] then
return true
-- enable highlighting
highlight = {
enable = true,
-- use vim highlighting in addition to treesitter
additional_vim_regex_highlighting = true,
disable = function(lang, buf)
-- disable in some files where vim's builtin highlighting is better
if table.contains(({
"diff", "tex"
}), lang) then
return true
end
-- disable in big files
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
end
end
end
}
}
}
end
end
},
{ "Wansmer/treesj",
disable = not vim.fn.has("nvim-0.9.0"),
reqs = "nvim-treesitter/nvim-treesitter",
lazy = function(load)
load:keymap("n", "<leader>j")
load:cmd("TSJToggle")
load:cmd("TSJSplit")
load:cmd("TSJJoin")
end,
load = function()
require("treesj").setup {
use_default_keymaps = false,
}
map("n", "<leader>j", require("treesj").toggle, { desc = "fold code" })
end
},
{ "windwp/nvim-ts-autotag",
reqs = "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.9.5"),
-- lazy = dep_short.auto({ "BufReadPre", "BufNewFile" }),
load = function()
require("nvim-ts-autotag").setup {}
end
}
}

View File

@ -1,14 +0,0 @@
local misc = require("core.misc")
local map = 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,
}
map("n", "<leader>j", require("treesj").toggle, { desc = "fold code" })
end
}

View File

@ -1,8 +0,0 @@
return { "windwp/nvim-ts-autotag",
requires = "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.9.5"),
function()
require("nvim-ts-autotag").setup {}
end
}

View File

@ -1,8 +1,8 @@
local misc = require("core.misc")
local map = misc.map
local map = core.misc.map
return { "mbbill/undotree",
function()
lazy = dep_short.keymap("n", "<leader>u"),
load = function()
if vim.g.loaded_undotree then
vim.g.undotree_DiffAutoOpen = 0
end

View File

@ -1,4 +1,5 @@
return { "lervag/vimtex",
lazy = dep_short.ft("tex"),
setup = function()
vim.g.vimtex_view_method = "zathura"
end

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

@ -0,0 +1,167 @@
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 res = {}
local ok, hl = pcall(vim.api.nvim_get_hl, namespace, {
name = hlgroup,
create = false
})
if not ok then
-- return default
return {
["foreground"] = "#000000",
["background"] = "#000000",
["special"] = "#000000"
}
end
for _, key in pairs({ "foreground", "background", "special" }) do
if hl[key] then
res[key] = string.format("#%06x", hl[key])
end
end
return res
end
--- Taken from https://github.com/rachartier/tiny-inline-diagnostic.nvim
---@param hex string
---@return table rgb
function M.hex_to_rgb(hex)
if hex == nil or hex == 'None' then
return {0, 0, 0}
end
hex = hex:gsub('#', '')
hex = string.lower(hex)
return {
tonumber(hex:sub(1, 2), 16),
tonumber(hex:sub(3, 4), 16),
tonumber(hex:sub(5, 6), 16)
}
end
-- Source: 'runtime/lua/vim/_defaults.lua' in Neovim source
local function parse_osc11(x)
local r, g, b = x:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$')
if not (r and g and b) then
local a
r, g, b, a = x:match('^\027%]11;rgba:(%x+)/(%x+)/(%x+)/(%x+)$')
if not (a and a:len() <= 4) then
return
end
end
if not (r and g and b) then
return
end
if not (r:len() <= 4 and g:len() <= 4 and b:len() <= 4) then
return
end
local parse_osc_hex = function(c)
return c:len() == 1 and (c..c) or c:sub(1, 2)
end
return '#'..parse_osc_hex(r)..parse_osc_hex(g)..parse_osc_hex(b)
end
local _termbg_init
--- taken from github.com/echasnovski/mini.misc modified to work for me
--- sets up terminal background synchronization which enables neovim to set the
--- background of the terminal it is running in
function M.setup_termbg_sync()
-- Handling `'\027]11;?\007'` response was added in Neovim 0.10
if vim.fn.has('nvim-0.10') == 0 then
vim.notify('`setup_termbg_sync()` requires Neovim>=0.10',
vim.log.levels.WARN)
end
-- Proceed only if there is a valid stdout to use
local has_stdout_tty = false
for _, ui in ipairs(vim.api.nvim_list_uis()) do
has_stdout_tty = has_stdout_tty or ui.stdout_tty
end
if not has_stdout_tty then return end
local augroup = vim.api.nvim_create_augroup('TermbgSync', {
clear = true,
})
local track_au_id, bad_responses, had_proper_response = nil, {}, false
local f = function(args)
-- Process proper response only once
if had_proper_response then
return
end
-- Neovim=0.10 uses string sequence as response, while Neovim>=0.11 sets it
-- in `sequence` table field
local seq = type(args.data) == 'table' and args.data.sequence or args.data
local ok, bg_init = pcall(parse_osc11, seq)
if not (ok and type(bg_init) == 'string') then
return table.insert(bad_responses, seq)
end
had_proper_response = true
pcall(vim.api.nvim_del_autocmd, track_au_id)
-- Set up sync
local sync = function()
local normal = vim.api.nvim_get_hl(0, {
name = "Normal",
create = false
})
if normal.bg == nil then
return
end
-- NOTE: use `io.stdout` instead of `io.write` to ensure correct target
-- Otherwise after `io.output(file); file:close()` there is an error
io.stdout:write(string.format('\027]11;#%06x\007', normal.bg))
end
vim.api.nvim_create_autocmd({ 'VimResume', 'ColorScheme' }, {
group = augroup,
callback = sync,
})
-- Set up reset to the color returned from the very first call
_termbg_init = _termbg_init or bg_init
local reset = function()
io.stdout:write('\027]11;'.._termbg_init..'\007')
end
vim.api.nvim_create_autocmd({ 'VimLeavePre', 'VimSuspend' }, {
group = augroup,
callback = reset,
})
-- Sync immediately
sync()
end
-- Ask about current background color and process the proper response.
-- NOTE: do not use `once = true` as Neovim itself triggers `TermResponse`
-- events during startup, so this should wait until the proper one.
track_au_id = vim.api.nvim_create_autocmd('TermResponse', {
group = augroup,
callback = f,
nested = true
})
io.stdout:write('\027]11;?\007')
vim.defer_fn(function()
if had_proper_response then
return
end
pcall(vim.api.nvim_del_augroup_by_id, augroup)
local bad_suffix = #bad_responses == 0 and '' or
(', only these: '..vim.inspect(bad_responses))
local msg =
"`setup_termbg_sync()` did not get proper response from terminal emulator"
..bad_suffix
vim.notify(msg, vim.log.levels.WARN)
end, 1000)
end
return M

View File

@ -14,16 +14,20 @@ local function parse_line(linenr)
return nil
end
-- get a parser TODO: remove the pcall once nvim 0.12 hits and the function no
-- longer raises an error
local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
if not ok then
if not ok or not parser then
return nil
end
-- get a query from the parser
local query = vim.treesitter.query.get(parser:lang(), "highlights")
if not query then
return nil
end
-- parse the current line
local tree = parser:parse({ linenr - 1, linenr })[1]
local result = {}
local line_pos = 0

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

@ -0,0 +1,55 @@
-- inspired by (and partially yoinked from): github.com/gonstoll/dotfiles
local notify = vim.notify
--- overidden version of vim.notify
---@param msg string message
---@param level vim.log.levels? log level
---@param opts table? options
---@diagnostic disable-next-line: duplicate-set-field
vim.notify = function(msg, level, opts)
notify(msg, level or vim.log.levels.INFO, opts or {
title = require("core.misc").appid
})
end
--- 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
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"),
}
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

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

@ -0,0 +1,99 @@
local misc = require("core.misc")
local map, auto = misc.map, misc.auto
local popup_opts, hover_opts, signature_opts, list_opts, location_opts
local function on_list(opts)
vim.fn.setqflist({}, "r", opts)
if #opts.items > 1 then
vim.cmd.copen()
-- get to the closest reference to the cursor (likely the one gr or gd was
-- called on)
local closest, distance = 1, false
for i, item in ipairs(opts.items) do
if item.filename and vim.fn.expand("%:p") == item.filename then
local lnum = vim.api.nvim_win_get_cursor(0)[1]
if item.lnum then
local new_distance = math.abs(lnum - item.lnum)
if not distance or new_distance < distance then
distance = new_distance
closest = i
end
end
end
vim.cmd(".cc! "..closest)
end
else
vim.cmd(".cc! 1")
end
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,102 +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, {
buffer = bufnr,
desc = "check code actions",
})
-- Diagnostics
map("n", "[d", function()
vim.diagnostic.jump({ count = -1 })
end, opts)
map("n", "]d", function()
vim.diagnostic.jump({ count = 1 })
end, opts)
end
function M.setup()
vim.diagnostic.config {
virtual_text = false,
virtual_lines = {
only_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,31 +87,7 @@ 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
---@param opts table? options
--- example:
--- ```lua
--- {
@ -145,6 +109,7 @@ end
--- ```
--- opts is optional and if empty will simply highlight the current line for
--- 250ms using IncSearch as the highlight group
---@param opts table? options
function M.timeout_highlight(opts)
opts = opts or {}
opts.hl = opts.hl or "IncSearch"

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
file_name = function(_, _, _)
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,46 +1,4 @@
require("core.snippets.shorthands")
--- create a decleration of a function from it's definition using treesitter
---@param func string
---@return string|nil
local function c_func(func)
local tree = vim.treesitter.get_parser():parse()[1]:root()
local q = vim.treesitter.query.parse("c", "(function_definition) @f")
local matches = q:iter_matches(tree, 0)
vim.treesitter.query.parse("c", "(identifier) @i")
local m = q:iter_matches(matches, 0)
print(vim.treesitter.get_node_text(m:child(), 0))
if true then
return
end
for _, match in matches do
for _, node in pairs(match) do
if not node or not node:child(1) or not node:child(1):child() then
-- print(vim.treesitter.get_node_text(node:child(1):child(), 0))
goto continue
end
if vim.treesitter.get_node_text(node:child(1):child(), 0) == func then
local def = ""
for i = 0, node:child_count() - 2 do
def = def..vim.treesitter.get_node_text(node:child(i), 0)
if i < node:child_count() - 2 then
def = def.." "
end
end
-- Print the function name using node text
return def:gsub("\n", "")
end
::continue::
end
end
return nil
end
dofile(core.snippets)
return {
-- function snippet
@ -82,19 +40,4 @@ return {
i(0),
t({ "", "}" })
}),
-- create decleration based on existing c function
postfix(".d", {
f(function(_, parent)
local r = c_func(parent.snippet.env.POSTFIX_MATCH)
if not r then
return parent.snippet.env.POSTFIX_MATCH
end
local bidx, aidx = r:find(parent.snippet.env.POSTFIX_MATCH)
return r:sub(1, bidx - 1)..
parent.snippet.env.POSTFIX_MATCH..
r:sub(aidx + 1)..";"
end, {})
})
}

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", {

108
lua/snippets/python.lua Normal file
View File

@ -0,0 +1,108 @@
dofile(core.snippets)
--- convert snake to pascal case
---@return string classname
local function py_file_name()
local fn = file_name()
local new = ""
-- convert snake to pascal case
for i = 1, #fn do
if i == 1 then
new = fn:sub(1, 1):upper()
elseif fn:sub(i - 1, i - 1) == "_" then
new = new..fn:sub(i, i):upper()
elseif fn:sub(i, i) ~= "_" then
new = new..fn:sub(i, i)
end
end
return new
end
--- find the current class and return its name if not available defaults to
--- the file name
---@return string
local function python_class()
-- set the starting node to the node under the cursor
local node = require("nvim-treesitter.ts_utils").get_node_at_cursor()
while node do
-- check if we're in a class
if node:type() == "class_definition" then
-- find the class name in the class declaration and return it
for i = 0, node:child_count() - 1 do
local child = node:child(i)
if child and child:type() == "identifier" then
return vim.treesitter.get_node_text(child, 0)
end
end
end
node = node:parent()
end
-- if no class can be found default to the current file name
return file_name()
end
return {
s("class", {
t("class "),
c(1, {
f(py_file_name, {}),
i(0, "MyClass")
}),
c(2, {
t(""),
sn(nil, {
t("("),
i(1, "object"),
t(")")
})
}),
t({ ": ", "\t" }),
i(0)
}),
s({ trig = [[fn\|def\|constr\|init]], trigEngine = "vim" }, {
t("def "),
d(1, function(_, snip)
if snip.trigger == "constr" or snip.trigger == "init" then
print(python_class())
return sn(nil, {
t("__init__")
})
else
return sn(nil, {
i(1, "myFunc")
})
end
end, {}),
t("("),
d(2, function(_, snip)
-- if this is a constructor or a function in a class then we need to put
-- self as the first argument
if snip.trigger == "constr" or snip.trigger == "init"
or python_class() ~= file_name() then
return sn(nil, {
t("self")
})
else
return sn(nil, {})
end
end, {}),
i(3),
t(")"),
t(" -> "),
i(4, "None"),
t({ ":", "\t" }),
i(0, "pass")
}),
s("main", {
t({ "def main() -> None:", "\t" }),
i(0, 'print("hello world")'),
t({ "", "", 'if __name__ == "__main__":', "\tmain()" })
})
}

View File

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