Compare commits
6 Commits
cace587a09
...
master
Author | SHA1 | Date | |
---|---|---|---|
62945314e2
|
|||
d320577772
|
|||
7c96b43098
|
|||
27f55ed03c
|
|||
afdefb7dc3
|
|||
64afe9c9ee
|
@ -1,5 +1,5 @@
|
||||
local map_local = core.misc.map_local
|
||||
local map_local, lz = core.misc.map_local, core.misc.lz
|
||||
|
||||
-- sort #includes <> (very jank)
|
||||
-- TODO: rewrite in a semi-sane way
|
||||
map_local("n", "cri", "mz/^#include.*<.*>$<CR>ggVGN:sort<CR>`z<cmd>delm z<CR>:nohlsearch<Bar>:echo<CR>")
|
||||
map_local("n", "cri", lz "mz/^#include.*<.*>$<CR>ggVGN:sort<CR>`z<cmd>delm z<CR>:nohlsearch<Bar>:echo<CR>")
|
||||
|
@ -1 +1 @@
|
||||
core.misc.map("n", "q", "<cmd>q<CR>")
|
||||
core.misc.map_local("n", "q", "<cmd>q<CR>")
|
||||
|
@ -1,6 +1,3 @@
|
||||
-- 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")
|
||||
@ -15,8 +12,8 @@ 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", -- 💀
|
||||
"java", -- 💀
|
||||
"-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",
|
||||
@ -73,14 +70,7 @@ local config = {
|
||||
|
||||
dap.adapters.java = nil -- remove any old java adapters
|
||||
jdtls.setup_dap({ hotcodereplace = "auto" })
|
||||
require("jdtls.dap").setup_dap_main_class_configs()
|
||||
end,
|
||||
|
||||
-- don"t print out status messages
|
||||
handlers = {
|
||||
["language/status"] = function() end
|
||||
},
|
||||
|
||||
init_options = {
|
||||
bundles = {
|
||||
vim.fs.joinpath(java_dap_install,
|
||||
@ -88,6 +78,10 @@ local config = {
|
||||
true)
|
||||
)
|
||||
}
|
||||
},
|
||||
-- don't print out status messages
|
||||
handlers = {
|
||||
["language/status"] = function() end
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +155,6 @@ local function version_check()
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- start the jdtls with dap!
|
||||
if not version_check() then
|
||||
return
|
||||
|
@ -2,7 +2,7 @@ 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
|
||||
map_local("n", ".", "gh", { noremap = false, remap = true }) -- Toggle hidden files
|
||||
map_local("n", "g.", "gh", { noremap = false, remap = true }) -- Toggle hidden files
|
||||
map_local("n", "P", "<C-w>z", { noremap = false, remap = true }) -- Close preview window
|
||||
|
||||
-- Close netrw only if it isn't the last window
|
||||
|
@ -1,9 +0,0 @@
|
||||
local map = core.misc.map
|
||||
|
||||
return {
|
||||
on_attach = function(_, bufnr)
|
||||
-- add some basedpyright specific mappings
|
||||
local opts = { buffer = bufnr }
|
||||
map("n", "cri", "<cmd>PyrightOrganizeImports<CR>", opts)
|
||||
end,
|
||||
}
|
@ -1,12 +1,4 @@
|
||||
local map = core.misc.map
|
||||
|
||||
return {
|
||||
on_attach = function(_, bufnr)
|
||||
-- add some clangd specific mappings
|
||||
local opts = { buffer = bufnr }
|
||||
map("n", "<leader>o", "<cmd>ClangdSwitchSourceHeader<CR>", opts)
|
||||
end,
|
||||
|
||||
cmd = {
|
||||
"clangd",
|
||||
"--background-index",
|
||||
|
@ -11,14 +11,14 @@ return {
|
||||
enable = false
|
||||
},
|
||||
workspace = {
|
||||
checkThirdParty = true,
|
||||
checkThirdParty = "ApplyInMemory",
|
||||
library = {
|
||||
vim.env.VIMRUNTIME
|
||||
vim.env.VIMRUNTIME,
|
||||
"${3rd}/luv/library"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
root_markers = { ".luarc.json", ".luarc.jsonc", ".luacheckrc", ".stylua.toml",
|
||||
"stylua.toml", "selene.toml", "selene.yml", "README.md" }
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
if vim.fn.has("termguicolors") and not os.getenv("TERM") ~= "linux" then
|
||||
vim.cmd("colorscheme mellow")
|
||||
vim.cmd("colo mellow")
|
||||
else
|
||||
vim.cmd("colorscheme default")
|
||||
vim.cmd("colo default")
|
||||
end
|
||||
|
@ -1,3 +0,0 @@
|
||||
# TODO:
|
||||
# add something to check if we need to run bear again to update
|
||||
# clangd build options
|
6
init.lua
6
init.lua
@ -1,6 +1,3 @@
|
||||
-- TODO: after switching to dep with lazy loading check out vim-startuptime
|
||||
-- again
|
||||
|
||||
-- load core utilities
|
||||
_G.core = require("core")
|
||||
|
||||
@ -10,6 +7,9 @@ vim.loader.enable()
|
||||
-- load user config
|
||||
require("conf")
|
||||
|
||||
-- setup lsp stuff
|
||||
core.lsp.setup()
|
||||
|
||||
-- bootstrap plugin manager
|
||||
local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep"
|
||||
if not vim.uv.fs_stat(path) then
|
||||
|
@ -1,6 +1,6 @@
|
||||
local auto, augroup = core.misc.auto, core.misc.augroup
|
||||
|
||||
-- auto commands which interact with bufferes without modifying them
|
||||
-- auto commands which interact with buffers without modifying them
|
||||
local bufcheck = augroup("bufcheck")
|
||||
-- auto commands which modify things on the filesystem
|
||||
local fsmod = augroup("fsmod")
|
||||
@ -11,14 +11,6 @@ auto("FocusGained", {
|
||||
command = "checktime"
|
||||
})
|
||||
|
||||
auto("TextYankPost", {
|
||||
group = bufcheck,
|
||||
desc = "Highlight on yank.",
|
||||
callback = function()
|
||||
vim.highlight.on_yank { timeout = 250 }
|
||||
end
|
||||
})
|
||||
|
||||
auto("BufRead", {
|
||||
group = bufcheck,
|
||||
desc = "Return to the last place the buffer was closed in.",
|
||||
@ -38,14 +30,4 @@ auto("BufWritePre", {
|
||||
end
|
||||
})
|
||||
|
||||
auto("BufWritePre", {
|
||||
group = fsmod,
|
||||
desc = "Basically mkdir -p.",
|
||||
callback = function(ctx)
|
||||
if ctx.match:match("^%w%w+://") then return end
|
||||
local dir = vim.fn.fnamemodify(ctx.file, ":p:h")
|
||||
vim.fn.mkdir(dir, "p")
|
||||
end
|
||||
})
|
||||
|
||||
core.color.setup_termbg_sync()
|
||||
|
@ -1,64 +1,65 @@
|
||||
local map = core.misc.map
|
||||
local map, lz = core.misc.map, core.misc.lz
|
||||
|
||||
--- feed keys as userinput
|
||||
---@param keys string keys
|
||||
local function feedkeys(keys)
|
||||
vim.api.nvim_feedkeys(
|
||||
vim.api.nvim_replace_termcodes(keys, true, false, true),
|
||||
"n", true)
|
||||
end
|
||||
|
||||
-- vim binds
|
||||
vim.g.mapleader = " " -- set leader key
|
||||
|
||||
map("x", "<leader>p", [["_dP]], { desc = "Greatest remap of all time." })
|
||||
map("n", "<esc>", ":nohlsearch<Bar>:echo<CR>", { desc = "Clear search." })
|
||||
-- move selected text up/down
|
||||
map("v", "<S-k>", ":m '<-2<CR>gv=gv", { desc = "Move selected text up." })
|
||||
map("v", "<S-j>", ":m '>+1<CR>gv=gv", { desc = "Move selected text down." })
|
||||
map("n", "<esc>", "<cmd>noh<Bar>:ec<CR>", { desc = "Clear search." })
|
||||
map("n", "<leader>a", lz "<cmd>e #<CR>zz", { desc = "swap to alt file" })
|
||||
|
||||
-- the cursor STAYS IN THE MIDDLE
|
||||
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>zz") -- half page jumping
|
||||
map("n", "<C-u>", "<C-u>zz")
|
||||
map("n", "<S-j>", lz "mzJ`z<cmd>delm z<CR>") -- when combining lines
|
||||
map("n", "n", lz "nzzzv") -- when searching
|
||||
map("n", "N", lz "Nzzzv")
|
||||
map("n", "<C-d>", lz "<C-d>zz") -- half page jumping
|
||||
map("n", "<C-u>", lz "<C-u>zz")
|
||||
map("n", "<C-o>", lz "<C-o>zz") -- jump history
|
||||
map("n", "<C-i>", lz "<C-i>zz")
|
||||
|
||||
map({ "n", "i" }, "<C-c>", "<Esc>")
|
||||
|
||||
map("n", "<leader>x", function() -- execute order 111
|
||||
local fn = vim.fn.expand("%:p")
|
||||
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.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.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")
|
||||
end
|
||||
end, { desc = "toggle executable flag of the file" })
|
||||
|
||||
-- good spell suggestion ui
|
||||
-- (stolen from https://github.com/neovim/neovim/pull/25833)
|
||||
vim.keymap.set("n", "z=", function()
|
||||
local spell_on_choice = vim.schedule_wrap(function(_, idx)
|
||||
if type(idx) == "number" then
|
||||
vim.cmd("normal! "..idx.."z=")
|
||||
end
|
||||
end)
|
||||
|
||||
if vim.v.count > 0 then
|
||||
spell_on_choice(nil, vim.v.count)
|
||||
return
|
||||
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)
|
||||
end, { desc = "Shows spelling suggestions" })
|
||||
-- trigger completion menu
|
||||
-- (stolen from https://gist.github.com/MariaSolOs/2e44a86f569323c478e5a078d0cf98cc)
|
||||
map("i", "<C-n>", function()
|
||||
-- if the completion menu is already visible just go to the next item
|
||||
if vim.fn.pumvisible() ~= 0 then
|
||||
feedkeys("<C-n>")
|
||||
else
|
||||
if #vim.lsp.get_clients({ bufnr = 0 }) > 0 then
|
||||
vim.lsp.completion.get()
|
||||
else
|
||||
if vim.bo.omnifunc == "" then
|
||||
feedkeys("<C-x><C-n>")
|
||||
else
|
||||
feedkeys("<C-x><C-o>")
|
||||
end
|
||||
end
|
||||
end
|
||||
end, { desc = "Trigger/select next completion" })
|
||||
map("i", "<C-s>", "<C-x><C-s>", { desc = "Trigger spell completion" })
|
||||
map("n", "<C-s>", lz "<cmd>se spell<CR>ea<C-x><C-s><cmd>se nospell<CR>", { desc = "Trigger spell completion" })
|
||||
|
||||
-- quickfix
|
||||
map("n", "<M-j>", "<cmd>cnext<CR>")
|
||||
map("n", "<M-k>", "<cmd>cprev<CR>")
|
||||
map("n", "<M-c>", "<cmd>cclose<CR>")
|
||||
map("n", "<M-j>", "<cmd>cnext<CR>", { desc = "qf next" })
|
||||
map("n", "<M-k>", "<cmd>cprev<CR>", { desc = "qf prev" })
|
||||
map("n", "<M-c>", "<cmd>cclose<CR>", { desc = "qf close" })
|
||||
map("n", "<M-x>", "<cmd>cope<CR>", { desc = "qf open" })
|
||||
|
||||
-- man pages
|
||||
map("n", "<C-k>", "<cmd>Man<CR>")
|
||||
|
||||
-- okay this is gonna sound crazy, but I like emacs binds for editing when I'm
|
||||
-- stuck without modal editing like in command mode.
|
||||
map("c", "<C-a>", function() feedkeys("<Home>") end)
|
||||
map("c", "<C-e>", function() feedkeys("<End>") end)
|
||||
map("c", "<C-d>", function() feedkeys("<Del>") end)
|
||||
|
||||
-- execute line/block
|
||||
map("n", "<leader>x", ":.lua<CR>")
|
||||
map("x", "<leader>x", ":lua<CR>")
|
||||
|
@ -1,84 +1,49 @@
|
||||
-- color stuff
|
||||
if vim.fn.has("termguicolors") then
|
||||
vim.opt.termguicolors = true
|
||||
end
|
||||
|
||||
-- make .h files default to c code
|
||||
vim.filetype.add({ extension = { h = "c", }, })
|
||||
|
||||
-- numbers
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.o.nu = true
|
||||
vim.o.rnu = true
|
||||
|
||||
-- buffer
|
||||
vim.opt.scrolloff = 5
|
||||
vim.opt.wrap = true -- wraping lines
|
||||
vim.opt.linebreak = true -- fix where line is wraped
|
||||
vim.opt.cursorline = true
|
||||
vim.opt.colorcolumn = { 80 }
|
||||
vim.o.lbr = true -- fix where line is wraped
|
||||
vim.o.cul = true
|
||||
vim.o.cc = "80"
|
||||
|
||||
-- indents + tabs
|
||||
local tabwidth = 2
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.smarttab = true
|
||||
vim.opt.cindent = true
|
||||
vim.opt.autoindent = true
|
||||
vim.opt.tabstop = tabwidth
|
||||
vim.opt.shiftwidth = tabwidth
|
||||
vim.opt.softtabstop = tabwidth
|
||||
vim.o.ts = tabwidth
|
||||
vim.o.sw = tabwidth
|
||||
vim.o.sts = -1
|
||||
|
||||
-- Schedule the setting after `UiEnter` because it can increase startup-time.
|
||||
-- (yoinked from kickstart.nvim)
|
||||
vim.schedule(function()
|
||||
vim.opt.clipboard = "unnamedplus" -- system clipboard
|
||||
vim.o.cb = "unnamedplus" -- system clipboard
|
||||
end)
|
||||
|
||||
vim.opt.updatetime = 200
|
||||
|
||||
-- file saving
|
||||
vim.opt.swapfile = false
|
||||
vim.opt.undofile = true
|
||||
vim.opt.confirm = true
|
||||
vim.o.swf = false
|
||||
vim.o.udf = true
|
||||
|
||||
-- searching
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.opt.wrapscan = true
|
||||
vim.opt.showmatch = true
|
||||
vim.opt.incsearch = true
|
||||
vim.o.ic = true
|
||||
|
||||
-- make windows look nice
|
||||
vim.o.winborder = "solid"
|
||||
|
||||
-- wild menus
|
||||
vim.opt.wildoptions = "pum"
|
||||
vim.opt.pumblend = 3
|
||||
vim.opt.pumheight = 20
|
||||
vim.o.ph = 20
|
||||
vim.o.wic = true
|
||||
vim.o.wop = "fuzzy,pum,tagfile"
|
||||
|
||||
vim.opt.wildignorecase = true
|
||||
vim.opt.wildignore = "*.o"
|
||||
|
||||
-- netrw
|
||||
vim.g.netrw_banner = 0
|
||||
vim.g.netrw_winsize = 30
|
||||
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)
|
||||
vim.g.border_style = "solid"
|
||||
|
||||
do -- folding
|
||||
vim.opt.foldmethod = "syntax"
|
||||
vim.opt.foldlevelstart = 99
|
||||
vim.opt.foldlevel = 99
|
||||
vim.opt.foldenable = true
|
||||
vim.o.fillchars = "fold: ,eob: "
|
||||
|
||||
vim.opt.foldtext = "v:lua.core.folding()"
|
||||
end
|
||||
-- completion
|
||||
vim.o.cot = "menu,menuone,noinsert,fuzzy,popup"
|
||||
vim.o.cia = "kind,abbr,menu"
|
||||
-- waiting for https://github.com/neovim/neovim/pull/25541 to land
|
||||
-- vim.o.completepopup = "border:"..vim.o.winborder
|
||||
|
||||
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
|
||||
@ -101,64 +66,9 @@ do -- statusline
|
||||
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%
|
||||
-- opts.lua [+] λ1 163,61-60 88%
|
||||
--
|
||||
return table.concat {
|
||||
"%t", -- file name
|
||||
@ -167,10 +77,8 @@ do -- statusline
|
||||
"%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(), " ",
|
||||
"λ"..#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
|
||||
@ -178,6 +86,6 @@ do -- statusline
|
||||
" "..percentage() -- percentage through the buffer
|
||||
}
|
||||
end
|
||||
vim.opt.statusline = "%!v:lua.Status()"
|
||||
vim.opt.laststatus = 3
|
||||
vim.o.stl = "%!v:lua.Status()"
|
||||
vim.o.ls = 3
|
||||
end
|
||||
|
@ -1,126 +0,0 @@
|
||||
return { "Saghen/blink.cmp",
|
||||
branch = "v1.*",
|
||||
reqs = {
|
||||
"xzbdmw/colorful-menu.nvim",
|
||||
"L3MON4D3/LuaSnip"
|
||||
},
|
||||
lazy = dep_short.auto("InsertEnter"),
|
||||
load = function()
|
||||
local colormenu = require("colorful-menu")
|
||||
require("blink.cmp").setup {
|
||||
keymap = {
|
||||
preset = "none", -- I don't like the default documentation scroll binds
|
||||
["<C-y>"] = { "select_and_accept" },
|
||||
["<C-n>"] = { "select_next", "fallback_to_mappings" },
|
||||
["<C-p>"] = { "select_prev", "fallback_to_mappings" },
|
||||
|
||||
["<C-u>"] = { "scroll_documentation_up", "fallback" },
|
||||
["<C-d>"] = { "scroll_documentation_down", "fallback" }
|
||||
},
|
||||
|
||||
completion = {
|
||||
menu = {
|
||||
scrollbar = false,
|
||||
border = vim.g.border_style,
|
||||
draw = {
|
||||
columns = {
|
||||
{ "kind_icon" },
|
||||
{ "label", "label_description", gap = 1 },
|
||||
{ "kind" }
|
||||
},
|
||||
|
||||
-- blink.cmp should not take this much damn work to make it look
|
||||
-- semi-decent
|
||||
components = {
|
||||
-- we replace the kind icon with the an icon for the source
|
||||
kind_icon = {
|
||||
text = function(ctx)
|
||||
local menu_icon = {
|
||||
"?", -- fallback
|
||||
lsp = "λ",
|
||||
snippets = "%",
|
||||
buffer = "@",
|
||||
path = "#",
|
||||
cmdline = "$"
|
||||
}
|
||||
|
||||
local icon = menu_icon[ctx.source_id]
|
||||
if icon == nil then
|
||||
icon = menu_icon[1]
|
||||
end
|
||||
|
||||
return icon
|
||||
end,
|
||||
highlight = function(_)
|
||||
return { { group = "CmpItemMenu" } }
|
||||
end
|
||||
},
|
||||
label = {
|
||||
text = function(ctx)
|
||||
return colormenu.blink_components_text(ctx)
|
||||
end,
|
||||
highlight = function(ctx)
|
||||
return colormenu.blink_components_highlight(ctx)
|
||||
end
|
||||
},
|
||||
kind = {
|
||||
-- these highlights are technically for nvim-cmp, but they're
|
||||
-- built into my colorscheme so I don"t mind using them here
|
||||
highlight = function(ctx)
|
||||
return {
|
||||
{ group = "CmpItemKind"..ctx.kind, priority = 20000 }
|
||||
}
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ghost_text = {
|
||||
enabled = true
|
||||
},
|
||||
|
||||
-- documentation should show up immediately
|
||||
documentation = {
|
||||
auto_show = true,
|
||||
auto_show_delay_ms = 0,
|
||||
window = {
|
||||
border = vim.g.border_style
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
-- I like the default command line completion
|
||||
cmdline = {
|
||||
enabled = false
|
||||
},
|
||||
|
||||
-- signature support is necessary
|
||||
signature = {
|
||||
enabled = true,
|
||||
window = {
|
||||
border = vim.g.border_style
|
||||
}
|
||||
},
|
||||
|
||||
-- TODO: find a way to make my fancy luasnip snippets with multiple
|
||||
-- triggers not look stupid e.g. "fn\|main" for a function that could
|
||||
-- be triggered by fn or main
|
||||
snippets = {
|
||||
preset = "luasnip"
|
||||
},
|
||||
|
||||
sources = {
|
||||
default = { "lsp", "path", "snippets", "buffer" }
|
||||
},
|
||||
|
||||
fuzzy = {
|
||||
implementation = "prefer_rust_with_warning",
|
||||
sorts = {
|
||||
"score",
|
||||
"sort_text"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
return { "numToStr/Comment.nvim",
|
||||
load = function()
|
||||
require("Comment").setup {
|
||||
ignore = "^$"
|
||||
}
|
||||
end
|
||||
}
|
@ -40,7 +40,6 @@ return {
|
||||
"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")
|
||||
|
@ -1,88 +0,0 @@
|
||||
local map = core.misc.map
|
||||
|
||||
return { "lewis6991/gitsigns.nvim",
|
||||
disable = not vim.fn.has("nvim-0.9.0"),
|
||||
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 {
|
||||
signs = {
|
||||
add = { text = "│" },
|
||||
change = { text = "│" },
|
||||
delete = { text = "-" },
|
||||
topdelete = { text = "‾" },
|
||||
changedelete = { text = "~" },
|
||||
untracked = { text = "┆" }
|
||||
},
|
||||
|
||||
signcolumn = true,
|
||||
numhl = false,
|
||||
linehl = false,
|
||||
word_diff = false,
|
||||
|
||||
watch_gitdir = {
|
||||
interval = 1000,
|
||||
follow_files = true
|
||||
},
|
||||
|
||||
attach_to_untracked = true,
|
||||
current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
|
||||
|
||||
preview_config = { border = vim.g.border_style },
|
||||
|
||||
on_attach = function(bufnr)
|
||||
local opts = { buffer = bufnr }
|
||||
|
||||
-- Navigation
|
||||
map("n", "]c", function()
|
||||
if vim.wo.diff then
|
||||
return "]c"
|
||||
end
|
||||
vim.schedule(function() gs.next_hunk() end)
|
||||
return "<Ignore>"
|
||||
end, { expr = true, buffer = bufnr })
|
||||
|
||||
map("n", "[c", function()
|
||||
if vim.wo.diff then
|
||||
return "[c"
|
||||
end
|
||||
vim.schedule(function() gs.prev_hunk() end)
|
||||
return "<Ignore>"
|
||||
end, { expr = true, buffer = bufnr })
|
||||
|
||||
-- Actions
|
||||
map("n", "<leader>hs", gs.stage_hunk, opts)
|
||||
map("n", "<leader>hr", gs.reset_hunk, opts)
|
||||
map("v", "<leader>hs", function()
|
||||
gs.stage_hunk { vim.fn.line("."), vim.fn.line("v") }
|
||||
end, opts)
|
||||
map("v", "<leader>hr", function()
|
||||
gs.reset_hunk { vim.fn.line("."), vim.fn.line("v") }
|
||||
end, opts)
|
||||
map("n", "<leader>hS", gs.stage_buffer, opts)
|
||||
map("n", "<leader>hu", gs.undo_stage_hunk, opts)
|
||||
map("n", "<leader>hR", gs.reset_buffer, opts)
|
||||
map("n", "<leader>hp", gs.preview_hunk, opts)
|
||||
map("n", "<leader>hb", function() gs.blame_line { full=true } end, opts)
|
||||
map("n", "<leader>tb", gs.toggle_current_line_blame, opts)
|
||||
map("n", "<leader>hd", gs.diffthis, opts)
|
||||
map("n", "<leader>hD", function() gs.diffthis("~") end, opts)
|
||||
map("n", "<leader>td", gs.toggle_deleted, opts)
|
||||
|
||||
-- Text object
|
||||
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", opts)
|
||||
end
|
||||
}
|
||||
end
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
return { "tweekmonster/helpful.vim",
|
||||
lazy = dep_short.cmd("HelpfulVersion")
|
||||
}
|
@ -1,107 +1,26 @@
|
||||
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"),
|
||||
reqs = "neovim/nvim-lspconfig",
|
||||
load = function()
|
||||
local mason = require("mason")
|
||||
|
||||
mason.setup {
|
||||
require("mason").setup {
|
||||
ui = {
|
||||
border = vim.g.border_style,
|
||||
width = 0.8,
|
||||
height = 0.9,
|
||||
|
||||
-- not sure why these are nerdfont icons by default
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
core.mason.ensure_installed()
|
||||
end
|
||||
},
|
||||
|
||||
{ "mfussenegger/nvim-jdtls",
|
||||
disable = not vim.fn.has("nvim-0.6.0"),
|
||||
reqs = "mfussenegger/nvim-dap",
|
||||
lazy = dep_short.ft("java")
|
||||
reqs = "mfussenegger/nvim-dap"
|
||||
},
|
||||
|
||||
{ "nvimtools/none-ls.nvim",
|
||||
@ -111,11 +30,11 @@ return {
|
||||
|
||||
null_ls.setup {
|
||||
sources = {
|
||||
null_ls.builtins.formatting.black,
|
||||
null_ls.builtins.formatting.black
|
||||
},
|
||||
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
if client:supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({
|
||||
group = nonels_augroup,
|
||||
buffer = bufnr
|
||||
|
@ -1,75 +1,49 @@
|
||||
local map, auto = core.misc.map, core.misc.auto
|
||||
local map = core.misc.map
|
||||
|
||||
return { "L3MON4D3/LuaSnip",
|
||||
branch = "v2.*",
|
||||
disable = not vim.fn.has("nvim-0.7.0"),
|
||||
config = function()
|
||||
vim.cmd("make install_jsregexp")
|
||||
end,
|
||||
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")
|
||||
branch = "v2.*",
|
||||
config = function()
|
||||
vim.cmd("make install_jsregexp")
|
||||
end,
|
||||
lazy = function(load)
|
||||
load:keymap({"i", "s"}, "<c-a>")
|
||||
load:keymap({"i", "s"}, "<c-e>")
|
||||
load:keymap({"i", "s"}, "<c-j>")
|
||||
load:keymap({"i", "s"}, "<c-k>")
|
||||
load:auto("InsertEnter")
|
||||
end,
|
||||
load = function()
|
||||
local ls = require("luasnip")
|
||||
|
||||
luasnip.config.set_config {
|
||||
history = true, -- return back into snippet
|
||||
enable_autosnippets = true,
|
||||
-- replace the builtin snippet handler with luasnip so I get all my fancy
|
||||
-- stuff
|
||||
vim.snippet.expand = ls.lsp_expand
|
||||
|
||||
-- update on text insert and cursor hold
|
||||
updateevents = { "TextChanged", "TextChangedI", "CursorHold" },
|
||||
ext_opts = {
|
||||
[types.choiceNode] = {
|
||||
active = {
|
||||
virt_text = {{ "?", "@boolean" }}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ls.config.setup {
|
||||
keep_roots = true,
|
||||
link_roots = true,
|
||||
link_children = true,
|
||||
exit_roots = not true
|
||||
}
|
||||
|
||||
map({"i", "s"}, "<c-a>", function()
|
||||
if luasnip.choice_active() then
|
||||
luasnip.change_choice(1)
|
||||
end
|
||||
end)
|
||||
map({"i", "s"}, "<C-e>", ls.expand)
|
||||
map({"i", "s"}, "<C-j>", function() ls.jump(1) end)
|
||||
map({"i", "s"}, "<C-k>", function() ls.jump(-1) end)
|
||||
map({"i", "s"}, "<C-a>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
end
|
||||
end)
|
||||
|
||||
map({"i", "s"}, "<c-e>", function()
|
||||
if luasnip.expandable() then
|
||||
luasnip.expand()
|
||||
end
|
||||
end)
|
||||
-- collect all snippets and add them
|
||||
for _, file in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua",
|
||||
true)) do
|
||||
local fn = file:gsub("^.*/", ""):gsub("%.lua$", "")
|
||||
|
||||
map({"i", "s"}, "<C-j>", function()
|
||||
if luasnip.jumpable(1) then
|
||||
luasnip.jump(1)
|
||||
end
|
||||
end)
|
||||
|
||||
map({"i", "s"}, "<C-k>", function()
|
||||
if luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end)
|
||||
|
||||
-- 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$", "")
|
||||
|
||||
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
|
||||
local ret = require("snippets."..fn)
|
||||
if type(ret) ~= "boolean" then
|
||||
ls.add_snippets(fn, ret, { key = fn })
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
@ -1,42 +1,51 @@
|
||||
return { "mellow-theme/mellow.nvim",
|
||||
disable = not vim.fn.has("nvim-0.8.0"),
|
||||
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 splits look cleaner
|
||||
["WinSeparator"] = { link = "Normal" },
|
||||
-- revert change with statusline coloring
|
||||
["StatusLine"] = { fg = c.white, bg = c.gray01 },
|
||||
["StatusLineNC"] = { fg = c.bg_dark },
|
||||
|
||||
-- make floats darker
|
||||
["NormalFloat"] = { fg = c.fg, bg = "#111111" },
|
||||
["FloatBorder"] = { link = "NormalFloat" },
|
||||
-- make splits look cleaner
|
||||
["WinSeparator"] = { fg = c.gray01 },
|
||||
|
||||
-- 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 floats darker
|
||||
["NormalFloat"] = { fg = c.fg, bg = "#111111" },
|
||||
["FloatBorder"] = { link = "NormalFloat" },
|
||||
|
||||
-- make blink actually look nice
|
||||
["BlinkCmpMenu"] = { link = "NormalFloat" },
|
||||
["BlinkCmpMenuBorder"] = { link = "BlinkCmpMenu" },
|
||||
["BlinkCmpMenuSelection"] = { bg = c.gray01 },
|
||||
["BlinkCmpLabelDeprecated"] = { link = "CmpItemAbbrDeprecated" },
|
||||
-- Make pmenu look good
|
||||
["Pmenu"] = { link = "NormalFloat" },
|
||||
["PmenuSel"] = { link = "Normal" },
|
||||
["PmenuKind"] = { link = "@constant" },
|
||||
["PmenuKindSel"] = {
|
||||
fg = core.color.copyhl("Comment").fg,
|
||||
bold = true
|
||||
},
|
||||
|
||||
-- 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" }
|
||||
}
|
||||
-- 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
|
||||
|
||||
-- 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
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
return { "norcalli/nvim-colorizer.lua",
|
||||
disable = not vim.fn.has("nvim-0.4.0") and not vim.fn.has("termguicolors"),
|
||||
load = function()
|
||||
require("colorizer").setup(nil, {
|
||||
names = false,
|
||||
css = true
|
||||
})
|
||||
end
|
||||
}
|
@ -1,51 +1,5 @@
|
||||
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
|
||||
-- Remove trailing slash
|
||||
line = line:gsub("/$", "")
|
||||
ret[line] = true
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
-- build git status cache
|
||||
local function new_git_status()
|
||||
return setmetatable({}, {
|
||||
__index = function(self, key)
|
||||
local ignore_proc = vim.system(
|
||||
{ "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 ret = {
|
||||
ignored = parse_output(ignore_proc),
|
||||
tracked = parse_output(tracked_proc),
|
||||
}
|
||||
|
||||
rawset(self, key, ret)
|
||||
return ret
|
||||
end,
|
||||
})
|
||||
end
|
||||
local git_status = new_git_status()
|
||||
|
||||
local permission_hlgroups = {
|
||||
["-"] = "NonText",
|
||||
["r"] = "DiagnosticSignWarn",
|
||||
@ -53,190 +7,34 @@ local permission_hlgroups = {
|
||||
["x"] = "DiagnosticSignOk",
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
return { "stevearc/oil.nvim",
|
||||
lazy = dep_short.keymap("n", "-"),
|
||||
load = function()
|
||||
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
|
||||
-- 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
|
||||
return hls
|
||||
end,
|
||||
},
|
||||
{ "size", highlight = "@number" }
|
||||
},
|
||||
|
||||
-- Configuration for the floating window in oil.open_float
|
||||
float = {
|
||||
border = vim.g.border_style
|
||||
},
|
||||
-- fix the damn border
|
||||
confirmation = { border = vim.o.winborder },
|
||||
progress = { border = vim.o.winborder },
|
||||
ssh = { border = vim.o.winborder },
|
||||
keymaps_help = { border = vim.o.winborder }
|
||||
}
|
||||
|
||||
-- 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
|
||||
},
|
||||
|
||||
{ "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
|
||||
}
|
||||
map("n", "-", "<cmd>Oil<CR>")
|
||||
end
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
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
|
||||
}
|
@ -21,14 +21,8 @@ local function telebuilt_picker(fn)
|
||||
end
|
||||
|
||||
return { "nvim-telescope/telescope.nvim",
|
||||
disable = not vim.fn.has("nvim-0.9.0"),
|
||||
reqs = {
|
||||
{ "nvim-lua/plenary.nvim",
|
||||
-- lazy = function(load)
|
||||
-- load:cmd("PlenaryBustedDirectory")
|
||||
-- load:cmd("PlenaryBustedFile")
|
||||
-- end
|
||||
},
|
||||
"nvim-lua/plenary.nvim",
|
||||
{ "nvim-telescope/telescope-fzf-native.nvim",
|
||||
config = function()
|
||||
vim.cmd("make")
|
||||
@ -40,11 +34,8 @@ return { "nvim-telescope/telescope.nvim",
|
||||
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,
|
||||
@ -52,35 +43,86 @@ return { "nvim-telescope/telescope.nvim",
|
||||
load = function()
|
||||
local telescope = require("telescope")
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
|
||||
local function send_limited_to_qflist_and_open(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local entries = {}
|
||||
local max_items = 100
|
||||
local count = 0
|
||||
|
||||
for entry in picker.manager:iter() do
|
||||
if count >= max_items then
|
||||
break
|
||||
end
|
||||
|
||||
local filename = entry.path or entry.filename or entry.value
|
||||
local text = entry.text or entry.value
|
||||
if not text then
|
||||
if type(entry.value) == "table" then
|
||||
text = entry.value.text
|
||||
else
|
||||
text = entry.value
|
||||
end
|
||||
end
|
||||
|
||||
local pattern
|
||||
if not entry.lnum then
|
||||
if type(entry.display) == "string" then
|
||||
pattern = entry.display
|
||||
elseif type(entry.ordinal) == "string" then
|
||||
pattern = entry.ordinal
|
||||
elseif type(text) == "string" then
|
||||
pattern = text
|
||||
else
|
||||
entry.lnum = 1
|
||||
end
|
||||
end
|
||||
|
||||
if filename then
|
||||
table.insert(entries, {
|
||||
filename = filename,
|
||||
text = text,
|
||||
lnum = entry.lnum,
|
||||
col = entry.col,
|
||||
|
||||
-- we try and put a pattern in based on the info we receive from
|
||||
-- telescope so that the qf list takes us to the correct place
|
||||
pattern = pattern
|
||||
})
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
if #entries > 0 then
|
||||
-- make sure errors get suppressed. I don't care
|
||||
pcall(vim.fn.setqflist, {}, " ", {
|
||||
title = "Telescope Limited Results",
|
||||
items = entries
|
||||
})
|
||||
end
|
||||
|
||||
actions.select_default(prompt_bufnr)
|
||||
end
|
||||
|
||||
telescope.setup {
|
||||
defaults = {
|
||||
borderchars = {
|
||||
prompt = { " ", " ", " ", " ", " ", " ", " ", " " },
|
||||
results = { " ", " ", " ", " ", " ", " ", " ", " " },
|
||||
preview = { " ", " ", " ", " ", " ", " ", " ", " " },
|
||||
},
|
||||
winblend = 0,
|
||||
layout_strategy = "horizontal",
|
||||
sorting_strategy = "descending",
|
||||
scroll_strategy = "limit",
|
||||
layout_config = {
|
||||
horizontal = {
|
||||
height = 20,
|
||||
prompt_position = "bottom",
|
||||
anchor = "N",
|
||||
}
|
||||
},
|
||||
layout_strategy = "bottom_pane",
|
||||
borderchars = { " ", " ", " ", " ", " ", " ", " ", " " },
|
||||
mappings = {
|
||||
i = {
|
||||
["<esc>"] = actions.close,
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-u>"] = actions.preview_scrolling_up,
|
||||
["<C-d>"] = actions.preview_scrolling_down,
|
||||
["<CR>"] = send_limited_to_qflist_and_open,
|
||||
}
|
||||
}
|
||||
},
|
||||
pickers = {
|
||||
colorscheme = {
|
||||
enable_preview = true
|
||||
}
|
||||
},
|
||||
extensions = {
|
||||
fzf = {}
|
||||
}
|
||||
@ -95,17 +137,10 @@ return { "nvim-telescope/telescope.nvim",
|
||||
map("n", "<leader>f", telebuilt_picker(telebuilt.find_files), {
|
||||
desc = "Find files."
|
||||
})
|
||||
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()
|
||||
@ -117,11 +152,6 @@ return { "nvim-telescope/telescope.nvim",
|
||||
}
|
||||
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
|
||||
}
|
||||
end
|
||||
map("n", "<leader>tt", "<cmd>Telescope<CR>")
|
||||
end
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
-- 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",
|
||||
reqs = "nvim-lua/plenary.nvim",
|
||||
load = function()
|
||||
require("todo-comments").setup {
|
||||
keywords = {
|
||||
FIX = {
|
||||
icon = "# ",
|
||||
alt = { "FIXME", "BUG" },
|
||||
},
|
||||
HACK = {
|
||||
icon = "* ",
|
||||
color = "warning",
|
||||
},
|
||||
WARN = {
|
||||
icon = "! ",
|
||||
color = "warning",
|
||||
alt = { "WARNING", "XXX" },
|
||||
},
|
||||
NOTE = {
|
||||
icon = "i ",
|
||||
color = "hint",
|
||||
alt = { "INFO", "TODO" },
|
||||
},
|
||||
PERF = {
|
||||
icon = "@ ",
|
||||
alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" },
|
||||
},
|
||||
TEST = {
|
||||
icon = "@ ",
|
||||
color = "test",
|
||||
alt = { "TESTING", "PASSED", "FAILED" },
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
}
|
@ -1,79 +1,53 @@
|
||||
local map, auto = core.misc.map, core.misc.auto
|
||||
|
||||
--- to highlight a buffer or not
|
||||
---@param buf number buffer number
|
||||
---@return boolean to_highlight
|
||||
local function highlight(buf)
|
||||
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
|
||||
|
||||
-- disable highlighting on big files
|
||||
local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||
if ok and stats and stats.size > (1000 * 100 * 10) --[[1MB]] then
|
||||
return false
|
||||
end
|
||||
|
||||
-- fts to stop highlighting in
|
||||
if table.contains({
|
||||
"diff", "tex"
|
||||
}, ft) then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- to indent a buffer or not
|
||||
---@param buf number buffer number
|
||||
---@return boolean to_indent
|
||||
local function indent(buf)
|
||||
local ft = vim.api.nvim_get_option_value("ft", { buf = buf })
|
||||
|
||||
-- disable indentation on filetypes
|
||||
if not table.contains({
|
||||
"php"
|
||||
}, ft) then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
local map = core.misc.map
|
||||
|
||||
return {
|
||||
{ "nvim-treesitter/nvim-treesitter",
|
||||
branch = "main",
|
||||
disable = not vim.fn.has("nvim-0.11.0"),
|
||||
config = function()
|
||||
vim.cmd("TSUpdate")
|
||||
end,
|
||||
load = function()
|
||||
local treesitter = require("nvim-treesitter")
|
||||
require("nvim-treesitter.configs").setup {
|
||||
-- good default parsers
|
||||
ensure_installed = { "c", "lua", "vim", "vimdoc", "markdown",
|
||||
"markdown_inline", "java", "bash", "css", "html", "luadoc",
|
||||
"make"
|
||||
},
|
||||
|
||||
-- seems to not be very async despite the docs saying it is
|
||||
-- default parsers to install
|
||||
-- treesitter.install { "c", "lua", "vim", "vimdoc", "markdown",
|
||||
-- "markdown_inline", "java", "bash", "css", "html", "luadoc", "make"
|
||||
-- }
|
||||
-- indentation
|
||||
indent = {
|
||||
enable = true,
|
||||
|
||||
-- enable highlighting
|
||||
auto("FileType", {
|
||||
callback = function(e)
|
||||
-- I like both treesitter and default highlighting enabled
|
||||
if highlight(e.buf) then
|
||||
-- stop errors from showing up, I don't care
|
||||
pcall(vim.treesitter.start)
|
||||
vim.bo.syntax = "on"
|
||||
disable = function(lang, _)
|
||||
-- disable indenting in php (it's more broken with than without)
|
||||
return table.contains(({
|
||||
"php"
|
||||
}), lang)
|
||||
end
|
||||
},
|
||||
|
||||
-- indenting
|
||||
if indent(e.buf) then
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
-- 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
|
||||
|
||||
-- set the folding method
|
||||
vim.opt.foldmethod = "expr"
|
||||
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||
end
|
||||
})
|
||||
}
|
||||
}
|
||||
end
|
||||
},
|
||||
|
||||
@ -97,7 +71,7 @@ return {
|
||||
|
||||
{ "windwp/nvim-ts-autotag",
|
||||
reqs = "nvim-treesitter/nvim-treesitter",
|
||||
disable = not vim.fn.has("nvim-0.9.5"),
|
||||
disable = true,
|
||||
-- lazy = dep_short.auto({ "BufReadPre", "BufNewFile" }),
|
||||
load = function()
|
||||
require("nvim-ts-autotag").setup {}
|
||||
|
@ -1,12 +0,0 @@
|
||||
local map = core.misc.map
|
||||
|
||||
return { "mbbill/undotree",
|
||||
lazy = dep_short.keymap("n", "<leader>u"),
|
||||
load = function()
|
||||
if vim.g.loaded_undotree then
|
||||
vim.g.undotree_DiffAutoOpen = 0
|
||||
end
|
||||
|
||||
map("n", "<leader>u", "<cmd>UndotreeToggle<CR>")
|
||||
end
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
return { "lervag/vimtex",
|
||||
lazy = dep_short.ft("tex"),
|
||||
setup = function()
|
||||
vim.g.vimtex_view_method = "zathura"
|
||||
end
|
||||
|
@ -29,24 +29,6 @@ function M.copyhl(hlgroup, namespace)
|
||||
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+)$')
|
||||
|
@ -1,124 +0,0 @@
|
||||
--- Stolen from: https://github.com/Wansmer/nvim-config/blob/main/lua/modules/foldtext.lua
|
||||
--- modified for my use
|
||||
---
|
||||
---@module Foldtext
|
||||
---Based on https://www.reddit.com/r/neovim/comments/16sqyjz/finally_we_can_have_highlighted_folds/
|
||||
---Updated with vim.treesitter._fold.foldtext()
|
||||
|
||||
|
||||
local function parse_line(linenr)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, linenr - 1, linenr, false)[1]
|
||||
if not line then
|
||||
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 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
|
||||
|
||||
for id, node, metadata in query:iter_captures(tree:root(), 0, linenr - 1, linenr) do
|
||||
local name = query.captures[id]
|
||||
local start_row, start_col, end_row, end_col = node:range()
|
||||
|
||||
local priority = tonumber(metadata.priority or vim.highlight.priorities.treesitter)
|
||||
|
||||
if start_row == linenr - 1 and end_row == linenr - 1 then
|
||||
-- check for characters ignored by treesitter
|
||||
if start_col > line_pos then
|
||||
table.insert(result, {
|
||||
line:sub(line_pos + 1, start_col),
|
||||
{ { "Folded", priority } },
|
||||
range = { line_pos, start_col },
|
||||
})
|
||||
end
|
||||
line_pos = end_col
|
||||
|
||||
local text = line:sub(start_col + 1, end_col)
|
||||
table.insert(result, { text, { { "@" .. name, priority } }, range = { start_col, end_col } })
|
||||
end
|
||||
end
|
||||
|
||||
local i = 1
|
||||
while i <= #result do
|
||||
-- find first capture that is not in current range and apply highlights on the way
|
||||
local j = i + 1
|
||||
while j <= #result and result[j].range[1] >= result[i].range[1] and result[j].range[2] <= result[i].range[2] do
|
||||
for k, v in ipairs(result[i][2]) do
|
||||
if not vim.tbl_contains(result[j][2], v) then
|
||||
table.insert(result[j][2], k, v)
|
||||
end
|
||||
end
|
||||
j = j + 1
|
||||
end
|
||||
|
||||
-- remove the parent capture if it is split into children
|
||||
if j > i + 1 then
|
||||
table.remove(result, i)
|
||||
else
|
||||
-- highlights need to be sorted by priority, on equal prio, the deeper nested capture (earlier
|
||||
-- in list) should be considered higher prio
|
||||
if #result[i][2] > 1 then
|
||||
table.sort(result[i][2], function(a, b)
|
||||
return a[2] < b[2]
|
||||
end)
|
||||
end
|
||||
|
||||
result[i][2] = vim.tbl_map(function(tbl)
|
||||
return tbl[1]
|
||||
end, result[i][2])
|
||||
result[i] = { result[i][1], result[i][2] }
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
--- create a string of highlighted text for folds
|
||||
---@return table|string
|
||||
local function HighlightedFoldtext()
|
||||
local result = parse_line(vim.v.foldstart)
|
||||
if not result then
|
||||
return vim.fn.foldtext()
|
||||
end
|
||||
|
||||
table.insert(result, {
|
||||
" ... ",
|
||||
"LspCodeLens",
|
||||
})
|
||||
|
||||
local result2 = parse_line(vim.v.foldend)
|
||||
if result2 then
|
||||
local first = result2[1]
|
||||
result2[1] = { vim.trim(first[1]), first[2] }
|
||||
for _, item in ipairs(result2) do
|
||||
table.insert(result, item)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(result, {
|
||||
" "..(vim.v.foldend - vim.v.foldstart + 1).." Lines Folded ",
|
||||
"LspCodeLens",
|
||||
})
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return HighlightedFoldtext
|
@ -29,13 +29,51 @@ 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 = {
|
||||
packages = {
|
||||
formatters = { "black" },
|
||||
daps = { "debugpy" },
|
||||
lsps = {
|
||||
"clangd",
|
||||
"mesonlsp",
|
||||
"bashls",
|
||||
"lua_ls",
|
||||
"jdtls",
|
||||
"basedpyright"
|
||||
}
|
||||
},
|
||||
|
||||
--- Attempt to install all desired packages. This only really works on first
|
||||
--- install as mason seems to not remove the paths of the things we uninstall
|
||||
--- and instead just removes the code, leaving behind it's metadata.
|
||||
ensure_installed = function()
|
||||
local to_install = {}
|
||||
|
||||
for _, type in pairs(M.mason.packages) do
|
||||
for _, pkg in ipairs(type) do
|
||||
-- HACK: some servers don't have the same name in mason as they do in
|
||||
-- the vim lsp, we use the vim lsp names, and therefore need to
|
||||
-- convert them in here when they're incorrect for mason
|
||||
if pkg == "bashls" then pkg = "bash-language-server"
|
||||
elseif pkg == "lua_ls" then pkg = "lua-language-server"
|
||||
end
|
||||
|
||||
if vim.fn.isdirectory(M.mason.get_pkg_path(pkg)) == 0 then
|
||||
table.insert(to_install, pkg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #to_install > 0 then
|
||||
vim.cmd.MasonInstall(to_install)
|
||||
end
|
||||
end,
|
||||
|
||||
--- 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.
|
||||
|
@ -1,99 +0,0 @@
|
||||
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
|
66
lua/core/lsp/binds.lua
Normal file
66
lua/core/lsp/binds.lua
Normal file
@ -0,0 +1,66 @@
|
||||
local misc = require("core.misc")
|
||||
local map, auto = misc.map, misc.auto
|
||||
|
||||
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 group = misc.augroup("lsp.bind")
|
||||
auto("LspAttach", {
|
||||
group = group,
|
||||
callback = function(ctx)
|
||||
local list_opts = { on_list = on_list }
|
||||
local opts = { buffer = ctx.buf, nowait = true }
|
||||
|
||||
-- LSP actions
|
||||
map("n", "K", vim.lsp.buf.hover, opts)
|
||||
map("n", "gd", function() vim.lsp.buf.definition(list_opts) end, opts)
|
||||
map("n", "gD", function() vim.lsp.buf.declaration(list_opts) end, opts)
|
||||
map("n", "gi", function() vim.lsp.buf.implementation(list_opts) end, opts)
|
||||
map("n", "gy", function() vim.lsp.buf.type_definition(list_opts) end, opts)
|
||||
map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
|
||||
map("n", "<S-Tab>", vim.lsp.buf.signature_help, opts)
|
||||
map("n", "<leader>r", vim.lsp.buf.rename, opts)
|
||||
map("n", "gA", 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)
|
||||
map("n", "gb", vim.diagnostic.setqflist, opts)
|
||||
|
||||
-- formatting
|
||||
map("n", "<leader>c", vim.lsp.buf.format)
|
||||
end
|
||||
})
|
188
lua/core/lsp/completion.lua
Normal file
188
lua/core/lsp/completion.lua
Normal file
@ -0,0 +1,188 @@
|
||||
-- My neovim autocomplete setup.
|
||||
-- partially stolen from https://github.com/glepnir/nvim
|
||||
--
|
||||
-- To make this work nicely you're gonna want a solid snippet setup, for me this
|
||||
-- is luasnip. If you too would like to use luasnip just set vim.snippet.expand
|
||||
-- to luasnip.lsp_expand
|
||||
|
||||
--- add char to list of triggerable chars
|
||||
---@param list table list of chars
|
||||
---@param char number|string char to add
|
||||
local function add_to_client(list, char)
|
||||
local c
|
||||
|
||||
if type(char) == "string" then
|
||||
c = char
|
||||
elseif type(char) == "number" then
|
||||
c = string.char(char)
|
||||
end
|
||||
if not table.contains(list, c) then
|
||||
table.insert(list, c)
|
||||
end
|
||||
end
|
||||
|
||||
-- make sure we can add autos
|
||||
local misc = require("core.misc")
|
||||
local auto = misc.auto
|
||||
local completion_group = misc.augroup("lsp.completion")
|
||||
|
||||
-- Configure the lsp completion menu. In addition to setting up lsp completion
|
||||
-- this also styles it to look nice.
|
||||
auto("LspAttach", {
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
local client = vim.lsp.get_client_by_id(ctx.data.client_id)
|
||||
if not client or not client:supports_method("textDocument/completion") then
|
||||
return
|
||||
end
|
||||
|
||||
-- Make completion menu appear whenever you type something.
|
||||
local c = client.server_capabilities.completionProvider.triggerCharacters
|
||||
if c then
|
||||
for i = 32, 126 do
|
||||
add_to_client(c, string.char(i))
|
||||
end
|
||||
end
|
||||
|
||||
vim.lsp.completion.enable(true, client.id, ctx.buf, {
|
||||
autotrigger = true,
|
||||
convert = function(item)
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'u'
|
||||
return {
|
||||
-- in the future if we ever get the ability to highlight specific
|
||||
-- entries in the pummenu I'd like to add treesitter highlighting to
|
||||
-- the entries
|
||||
abbr = item.label:gsub('%b()', ''),
|
||||
kind = kind:sub(1, 1):lower(),
|
||||
menu = ''
|
||||
}
|
||||
end
|
||||
})
|
||||
end
|
||||
})
|
||||
|
||||
-- attempt to style the completion documentation popup
|
||||
auto("CompleteChanged", {
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local info = vim.fn.complete_info({ "selected" })
|
||||
if info.preview_bufnr and vim.bo[info.preview_bufnr].filetype == "" then
|
||||
vim.bo[info.preview_bufnr].filetype = "markdown"
|
||||
vim.wo[info.preview_winid].conceallevel = 2
|
||||
vim.wo[info.preview_winid].concealcursor = "niv"
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Add snippet support to lsp clients who don't do it for us. Currently this
|
||||
-- only supports function calls.
|
||||
--
|
||||
-- there's a very good chance this will give us problems for languages who do
|
||||
-- not follow the c-style function call style. I've only gotten this working in
|
||||
-- lua thus far.
|
||||
auto("CompleteDonePre", {
|
||||
group = completion_group,
|
||||
callback = function()
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
-- if the item isn't a snippet then we might want to create a snippet
|
||||
if item.label and item.kind and item.insertTextFormat then
|
||||
if item.insertTextFormat ~= 2 and item.kind == 3 then
|
||||
local n_complete_item = vim.v.completed_item
|
||||
|
||||
-- attempt to modify the function args to create a snippet
|
||||
local paren1 = string.find(item.label, "%(")
|
||||
if not paren1 then
|
||||
return
|
||||
end
|
||||
|
||||
-- try and create a snippet from a function call
|
||||
local i = 1
|
||||
local text = ""
|
||||
local l_paren = paren1
|
||||
local next, is_paren
|
||||
while not is_paren do
|
||||
-- find the next token
|
||||
next = string.find(item.label, "%,", l_paren + 1)
|
||||
if not next then
|
||||
next = string.find(item.label, "%)", l_paren + 1)
|
||||
if not next then
|
||||
return
|
||||
end
|
||||
is_paren = true
|
||||
end
|
||||
|
||||
-- concat text
|
||||
if text == "" then
|
||||
-- start the snippet
|
||||
text = string.sub(item.label, 0, l_paren).."${"..i..":"
|
||||
else
|
||||
-- continue the snippet
|
||||
text = text.."}, ".."${"..i..":"
|
||||
end
|
||||
|
||||
do -- add the content of the argument to the snippet
|
||||
-- we need to account for cases in which the developer uses spaces
|
||||
-- between their commas and code
|
||||
local is_space = string.sub(item.label, l_paren + 1, l_paren + 1)
|
||||
local plus = is_space == " " and 2 or 1
|
||||
|
||||
text = text..string.sub(item.label, l_paren + plus, next - 1)
|
||||
end
|
||||
|
||||
-- increment
|
||||
l_paren = next
|
||||
i = i + 1
|
||||
end
|
||||
-- end the snippet
|
||||
text = text.."})"
|
||||
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertText = text
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.insertTextFormat = 2
|
||||
n_complete_item.user_data.nvim.lsp.completion_item.kind = 3
|
||||
vim.v.completed_item = n_complete_item
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- show the signature help when inside a function call
|
||||
auto("CompleteDone", {
|
||||
group = completion_group,
|
||||
callback = function(ctx)
|
||||
-- make sure there's an lsp client, and make sure the lsp client supports
|
||||
-- textDocument/signatureHelp
|
||||
local client = vim.lsp.get_clients({ bufnr = ctx.buf })[1]
|
||||
if not client or not client:supports_method("textDocument/signatureHelp") then
|
||||
return
|
||||
end
|
||||
|
||||
-- show the signature help
|
||||
local item = vim.tbl_get(
|
||||
vim.v.completed_item,
|
||||
"user_data",
|
||||
"nvim",
|
||||
"lsp",
|
||||
"completion_item"
|
||||
)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
-- show signature help when the completion is a function
|
||||
if item.kind == 3 and (item.textEdit ~= nil or item.insertText ~= nil) then
|
||||
-- for some reason calling vim.schedule didn't work for me
|
||||
vim.defer_fn(vim.lsp.buf.signature_help, 100)
|
||||
end
|
||||
end,
|
||||
desc = "Auto show signature help when completion is done"
|
||||
})
|
34
lua/core/lsp/init.lua
Normal file
34
lua/core/lsp/init.lua
Normal file
@ -0,0 +1,34 @@
|
||||
local M = {}
|
||||
|
||||
--- setup vim lsp options
|
||||
function M.setup()
|
||||
-- ensure the severs are setup
|
||||
require("core.lsp.servers")
|
||||
|
||||
-- confgiure lsp
|
||||
vim.diagnostic.config {
|
||||
virtual_lines = {
|
||||
current_line = 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()
|
||||
}
|
||||
|
||||
require("core.lsp.binds")
|
||||
require("core.lsp.completion")
|
||||
require("core.lsp.wtf")
|
||||
end
|
||||
|
||||
return M
|
11
lua/core/lsp/servers.lua
Normal file
11
lua/core/lsp/servers.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local servers = require("core").mason.packages.lsps
|
||||
|
||||
-- enable the servers I want
|
||||
for _, server in ipairs(servers) do
|
||||
-- skip jdtls, we start this on our own
|
||||
if servers == "jdtls" then
|
||||
goto continue
|
||||
end
|
||||
vim.lsp.enable(server)
|
||||
::continue::
|
||||
end
|
29
lua/core/lsp/wtf.lua
Normal file
29
lua/core/lsp/wtf.lua
Normal file
@ -0,0 +1,29 @@
|
||||
-- wtf why does the language server protocol have these features?
|
||||
-- partially stolen from https://github.com/glepnir/nvim
|
||||
|
||||
local misc = require("core.misc")
|
||||
local auto = misc.auto
|
||||
local wtf_group = misc.augroup("lsp.wtf")
|
||||
|
||||
auto('LspAttach', {
|
||||
group = wtf_group,
|
||||
callback = function(ctx)
|
||||
local client = vim.lsp.get_client_by_id(ctx.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
-- highlight color codes via lsp (supported by cssls)
|
||||
-- #ff0000
|
||||
if client:supports_method('textDocument/documentColor') then
|
||||
vim.lsp.document_color.enable(true, ctx.buf)
|
||||
end
|
||||
|
||||
-- enable linked editing this allows lsps to modify things like html tags
|
||||
-- for example when you change <p> to <a> </p> will be changed by the lsp
|
||||
-- to </a>
|
||||
if client:supports_method('textDocument/linkedEditingRange') then
|
||||
vim.lsp.linked_editing_range.enable(true, { client_id = client.id })
|
||||
end
|
||||
end
|
||||
})
|
@ -3,20 +3,9 @@ local M = {}
|
||||
--- vim.notify title
|
||||
M.appid = "Nvim Config"
|
||||
|
||||
--- 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
|
||||
---@param ext string? desired file extension of files to be returned from directory
|
||||
function M.loopf(path, body, ext)
|
||||
ext = ext and [[v:val =~ '\.]]..ext..[[$']] or nil
|
||||
for _, file in ipairs(vim.fn.readdir(path, ext)) do
|
||||
body(file)
|
||||
end
|
||||
end
|
||||
|
||||
--- extend vim.kemap.set
|
||||
---@param mode string|table mode for the keymap
|
||||
---@param bind string|table keymap
|
||||
---@param bind string keymap
|
||||
---@param cmd function|string command to run
|
||||
---@param opts vim.keymap.set.Opts? keymap options
|
||||
function M.map(mode, bind, cmd, opts)
|
||||
@ -35,19 +24,12 @@ function M.map(mode, bind, cmd, opts)
|
||||
end
|
||||
end
|
||||
|
||||
-- define the keybinds
|
||||
if type(bind) == "table" then
|
||||
for i in pairs(bind) do
|
||||
vim.keymap.set(mode, bind[i], cmd, opts)
|
||||
end
|
||||
elseif type(bind) == "string" then
|
||||
vim.keymap.set(mode, bind, cmd, opts)
|
||||
end
|
||||
vim.keymap.set(mode, bind, cmd, opts)
|
||||
end
|
||||
|
||||
--- a small map wrapper to easily create local buffer mappings
|
||||
---@param mode string|table mode for the keymap
|
||||
---@param bind string|table keymap
|
||||
---@param bind string keymap
|
||||
---@param cmd function|string command to run
|
||||
---@param opts table? keymap options
|
||||
function M.map_local(mode, bind, cmd, opts)
|
||||
@ -56,100 +38,25 @@ function M.map_local(mode, bind, cmd, opts)
|
||||
M.map(mode, bind, cmd, opts)
|
||||
end
|
||||
|
||||
--- extend vim.api.nvim_create_autocmd
|
||||
---@param event string|table event or events
|
||||
---@param opts vim.api.keyset.create_autocmd options
|
||||
function M.auto(event, opts)
|
||||
vim.api.nvim_create_autocmd(event, opts)
|
||||
end
|
||||
--- shorten vim.api.nvim_create_autocmd call
|
||||
M.auto = vim.api.nvim_create_autocmd
|
||||
|
||||
--- extend auto group
|
||||
---@param name string name of the autogroup
|
||||
---@param opts table? table of options
|
||||
---@return integer
|
||||
function M.augroup(name, opts)
|
||||
opts = opts or {}
|
||||
vim.api.nvim_create_augroup(name, opts)
|
||||
return vim.api.nvim_create_augroup(name, opts)
|
||||
end
|
||||
|
||||
--- extend vim.api.nvim_set_hl
|
||||
---@param group string|table highlight group
|
||||
---@param opts table highlight options
|
||||
---@param namespace? number highlight space
|
||||
function M.highlight(group, opts, namespace)
|
||||
namespace = namespace or 0
|
||||
|
||||
if type(group) == "table" then
|
||||
for i in pairs(group) do
|
||||
vim.api.nvim_set_hl(namespace, group[i], opts)
|
||||
end
|
||||
elseif type(group) == "string" then
|
||||
vim.api.nvim_set_hl(namespace, group, opts)
|
||||
end
|
||||
end
|
||||
|
||||
--- highlight something with some highlight group for a certain amount of time
|
||||
--- example:
|
||||
--- ```lua
|
||||
--- {
|
||||
--- -- highlight group to use
|
||||
--- hl = "IncSearch",
|
||||
---
|
||||
--- -- # of ms to stay highlighted for
|
||||
--- timeout = 250,
|
||||
---
|
||||
--- -- line to highlight
|
||||
--- line = vim.api.nvim_win_get_cursor(0)[1],
|
||||
---
|
||||
--- -- range to highlight if this is used line will be ignored
|
||||
--- range = {
|
||||
--- { 0, 0 },
|
||||
--- { 0, 0 }
|
||||
--- }
|
||||
--- }
|
||||
--- ```
|
||||
--- 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"
|
||||
opts.timeout = opts.timeout or 250
|
||||
if type(opts.range) ~= "table" or type(opts.range[1]) ~= "table" or
|
||||
type(opts.range[2]) ~= "table" then
|
||||
local curline = opts.line or vim.api.nvim_win_get_cursor(0)[1]
|
||||
opts.range = {
|
||||
{ curline - 1, 0 },
|
||||
{ curline, 0 }
|
||||
}
|
||||
end
|
||||
|
||||
local namespaceid = vim.api.nvim_create_namespace("timeout_highlight")
|
||||
|
||||
-- timer code was happily stolen from neovim/runtime/lua/vim/highlight.lua :)
|
||||
local timer, timer_cancel
|
||||
if not vim.fn.has("nvim-0.11") then
|
||||
if timer then
|
||||
timer:close()
|
||||
assert(timer_cancel)
|
||||
timer_cancel()
|
||||
end
|
||||
end
|
||||
|
||||
-- set the highlight
|
||||
vim.highlight.range(0, namespaceid, opts.hl, opts.range[1], opts.range[2], {
|
||||
opts.timeout,
|
||||
})
|
||||
|
||||
if not vim.fn.has("nvim-0.11") then
|
||||
timer_cancel = function()
|
||||
timer = nil
|
||||
timer_cancel = nil
|
||||
pcall(vim.api.nvim_buf_clear_namespace, 0, namespaceid, 0, -1)
|
||||
pcall(vim.api.nvim_win_remove_ns, 0, namespaceid)
|
||||
end
|
||||
|
||||
timer = vim.defer_fn(timer_cancel, opts.timeout)
|
||||
end
|
||||
--- Make an action lazy. This is mostly useful for keybinds which do a lot and
|
||||
--- you want to make sure the screen doesn't flash
|
||||
---@param txt string the action
|
||||
---@return string lazified
|
||||
---@nodiscard
|
||||
function M.lz(txt)
|
||||
return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>"
|
||||
end
|
||||
|
||||
return M
|
||||
|
19
lua/snippets/lua.lua
Normal file
19
lua/snippets/lua.lua
Normal file
@ -0,0 +1,19 @@
|
||||
dofile(core.snippets)
|
||||
|
||||
return {
|
||||
-- print inspect text
|
||||
s("inspect", {
|
||||
t("print(vim.inspect("),
|
||||
i(0),
|
||||
t("))")
|
||||
}),
|
||||
|
||||
-- print inspect text
|
||||
s("M", {
|
||||
i(1, "M");
|
||||
t({ " = {}", "" }),
|
||||
i(0),
|
||||
t({ "", "return " }),
|
||||
r(1)
|
||||
})
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
dofile(core.snippets)
|
||||
|
||||
return {
|
||||
-- header level 1, usually this has the same name as the file
|
||||
s("h1", {
|
||||
t("* "),
|
||||
c(1, {
|
||||
f(file_name, {}),
|
||||
i(1, "header")
|
||||
})
|
||||
}),
|
||||
|
||||
-- link snippet
|
||||
s("link", {
|
||||
t("{"),
|
||||
c(1, {
|
||||
sn(nil, { t({":$/"}), i(1, "path to file"), t(":") }),
|
||||
i(1, "https://example.com")
|
||||
}),
|
||||
t("}["),
|
||||
i(2, "description"),
|
||||
t("]")
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user