I'm not gonna bother

This commit is contained in:
2025-08-10 13:10:05 -04:00
parent 7c96b43098
commit d320577772
18 changed files with 182 additions and 192 deletions

View File

@ -12,8 +12,8 @@ local java_dap_install = core.mason.get_pkg_path("java-debug-adapter")
-- make sure to check if things with 💀 need updating -- make sure to check if things with 💀 need updating
local config = { local config = {
cmd = { cmd = {
"/usr/lib/jvm/openjdk21/bin/java", -- 💀 "java", -- 💀
"-jar", -- 💀 "-jar",
vim.fn.glob(vim.fs.joinpath(jdtls_install, "plugins/org.eclipse.equinox.launcher_*.jar")), vim.fn.glob(vim.fs.joinpath(jdtls_install, "plugins/org.eclipse.equinox.launcher_*.jar")),
"-configuration", jdtls_install.."config_linux", "-configuration", jdtls_install.."config_linux",
"-data", vim.fn.stdpath("cache").."/nvim-jdtls", "-data", vim.fn.stdpath("cache").."/nvim-jdtls",
@ -71,12 +71,6 @@ local config = {
dap.adapters.java = nil -- remove any old java adapters dap.adapters.java = nil -- remove any old java adapters
jdtls.setup_dap({ hotcodereplace = "auto" }) jdtls.setup_dap({ hotcodereplace = "auto" })
end, end,
-- don't print out status messages
handlers = {
["language/status"] = function() end
},
init_options = { init_options = {
bundles = { bundles = {
vim.fs.joinpath(java_dap_install, vim.fs.joinpath(java_dap_install,
@ -84,6 +78,10 @@ local config = {
true) true)
) )
} }
},
-- don't print out status messages
handlers = {
["language/status"] = function() end
} }
} }
@ -157,7 +155,6 @@ local function version_check()
return true return true
end end
-- start the jdtls with dap! -- start the jdtls with dap!
if not version_check() then if not version_check() then
return return

View File

@ -0,0 +1,3 @@
" will remove when my pr gets into neovim
" https://github.com/vim/vim/pull/17902
setl commentstring=//\ %s

View File

@ -1,6 +1,3 @@
-- TODO: after switching to dep with lazy loading check out vim-startuptime
-- again
-- load core utilities -- load core utilities
_G.core = require("core") _G.core = require("core")
@ -10,6 +7,9 @@ vim.loader.enable()
-- load user config -- load user config
require("conf") require("conf")
-- setup lsp stuff
core.lsp.setup()
-- bootstrap plugin manager -- bootstrap plugin manager
local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep" local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep"
if not vim.uv.fs_stat(path) then if not vim.uv.fs_stat(path) then

View File

@ -1,4 +1,7 @@
local map, lz = core.misc.map, core.misc.lz local map, lz = core.misc.map, core.misc.lz
--- feed keys as userinput
---@param keys string keys
local function feedkeys(keys) local function feedkeys(keys)
vim.api.nvim_feedkeys( vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(keys, true, false, true), vim.api.nvim_replace_termcodes(keys, true, false, true),
@ -9,7 +12,8 @@ end
vim.g.mapleader = " " -- set leader key vim.g.mapleader = " " -- set leader key
map("x", "<leader>p", [["_dP]], { desc = "Greatest remap of all time." }) map("x", "<leader>p", [["_dP]], { desc = "Greatest remap of all time." })
map("n", "<esc>", ":nohlsearch<Bar>:echo<CR>", { desc = "Clear search." }) 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 -- the cursor STAYS IN THE MIDDLE
map("n", "<S-j>", lz "mzJ`z<cmd>delm z<CR>") -- when combining lines map("n", "<S-j>", lz "mzJ`z<cmd>delm z<CR>") -- when combining lines
@ -17,6 +21,8 @@ map("n", "n", lz "nzzzv") -- when searching
map("n", "N", lz "Nzzzv") map("n", "N", lz "Nzzzv")
map("n", "<C-d>", lz "<C-d>zz") -- half page jumping map("n", "<C-d>", lz "<C-d>zz") -- half page jumping
map("n", "<C-u>", lz "<C-u>zz") 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")
-- trigger completion menu -- trigger completion menu
-- (stolen from https://gist.github.com/MariaSolOs/2e44a86f569323c478e5a078d0cf98cc) -- (stolen from https://gist.github.com/MariaSolOs/2e44a86f569323c478e5a078d0cf98cc)
@ -40,10 +46,20 @@ 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" }) map("n", "<C-s>", lz "<cmd>se spell<CR>ea<C-x><C-s><cmd>se nospell<CR>", { desc = "Trigger spell completion" })
-- quickfix -- quickfix
map("n", "<M-j>", "<cmd>cnext<CR>") map("n", "<M-j>", "<cmd>cnext<CR>", { desc = "qf next" })
map("n", "<M-k>", "<cmd>cprev<CR>") map("n", "<M-k>", "<cmd>cprev<CR>", { desc = "qf prev" })
map("n", "<M-c>", "<cmd>cclose<CR>") map("n", "<M-c>", "<cmd>cclose<CR>", { desc = "qf close" })
map("n", "<M-x>", "<cmd>cope<CR>") map("n", "<M-x>", "<cmd>cope<CR>", { desc = "qf open" })
-- man pages -- man pages
map("n", "<C-k>", "<cmd>Man<CR>") 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>")

View File

@ -29,6 +29,9 @@ vim.o.udf = true
-- searching -- searching
vim.o.ic = true vim.o.ic = true
-- make windows look nice
vim.o.winborder = "solid"
-- wild menus -- wild menus
vim.o.ph = 20 vim.o.ph = 20
vim.o.wic = true vim.o.wic = true
@ -37,9 +40,8 @@ vim.o.wop = "fuzzy,pum,tagfile"
-- completion -- completion
vim.o.cot = "menu,menuone,noinsert,fuzzy,popup" vim.o.cot = "menu,menuone,noinsert,fuzzy,popup"
vim.o.cia = "kind,abbr,menu" vim.o.cia = "kind,abbr,menu"
-- waiting for https://github.com/neovim/neovim/pull/25541 to land
-- make windows look nice -- vim.o.completepopup = "border:"..vim.o.winborder
vim.o.winborder = "solid"
do -- statusline do -- statusline
---@return string out formatted status line ---@return string out formatted status line

View File

@ -1,32 +1,8 @@
local nonels_augroup = core.misc.augroup("nullls formatting") local nonels_augroup = core.misc.augroup("nullls formatting")
return { return {
{ "neovim/nvim-lspconfig",
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",
"black",
"debugpy"
}
}
end
},
{ "mason-org/mason.nvim", { "mason-org/mason.nvim",
reqs = "neovim/nvim-lspconfig",
load = function() load = function()
require("mason").setup { require("mason").setup {
ui = { ui = {
@ -38,6 +14,8 @@ return {
} }
} }
} }
core.mason.ensure_installed()
end end
}, },

View File

@ -10,9 +10,13 @@ return { "L3MON4D3/LuaSnip",
load:keymap({"i", "s"}, "<c-e>") load:keymap({"i", "s"}, "<c-e>")
load:keymap({"i", "s"}, "<c-j>") load:keymap({"i", "s"}, "<c-j>")
load:keymap({"i", "s"}, "<c-k>") load:keymap({"i", "s"}, "<c-k>")
load:auto("InsertEnter")
end, end,
load = function() load = function()
local ls = require("luasnip") local ls = require("luasnip")
-- replace the builtin snippet handler with luasnip so I get all my fancy
-- stuff
vim.snippet.expand = ls.lsp_expand vim.snippet.expand = ls.lsp_expand
ls.config.setup { ls.config.setup {

View File

@ -151,5 +151,7 @@ return { "nvim-telescope/telescope.nvim",
cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "site/pack/deps/opt") cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "site/pack/deps/opt")
} }
end, { desc = "find files in plugin directory" }) end, { desc = "find files in plugin directory" })
map("n", "<leader>tt", "<cmd>Telescope<CR>")
end end
} }

View File

@ -71,7 +71,7 @@ return {
{ "windwp/nvim-ts-autotag", { "windwp/nvim-ts-autotag",
reqs = "nvim-treesitter/nvim-treesitter", reqs = "nvim-treesitter/nvim-treesitter",
disable = not vim.fn.has("nvim-0.9.5"), disable = true,
-- lazy = dep_short.auto({ "BufReadPre", "BufNewFile" }), -- lazy = dep_short.auto({ "BufReadPre", "BufNewFile" }),
load = function() load = function()
require("nvim-ts-autotag").setup {} require("nvim-ts-autotag").setup {}

View File

@ -29,24 +29,6 @@ function M.copyhl(hlgroup, namespace)
return res return res
end 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 -- Source: 'runtime/lua/vim/_defaults.lua' in Neovim source
local function parse_osc11(x) local function parse_osc11(x)
local r, g, b = x:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$') local r, g, b = x:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$')

View File

@ -35,6 +35,45 @@ local M = {
} }
M.mason = { 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. --- Gets a path to a package in the Mason registry.
--- Prefer this to `get_package`, since the package might not always be --- Prefer this to `get_package`, since the package might not always be
--- available yet and trigger errors. --- available yet and trigger errors.

View File

@ -48,8 +48,8 @@ auto("LspAttach", {
map("n", "gy", function() vim.lsp.buf.type_definition(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", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
map("n", "<S-Tab>", vim.lsp.buf.signature_help, opts) map("n", "<S-Tab>", vim.lsp.buf.signature_help, opts)
map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts) map("n", "<leader>r", vim.lsp.buf.rename, opts)
map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, opts) map("n", "gA", vim.lsp.buf.code_action, opts)
-- Diagnostics -- Diagnostics
map("n", "[d", function() map("n", "[d", function()
@ -58,6 +58,7 @@ auto("LspAttach", {
map("n", "]d", function() map("n", "]d", function()
vim.diagnostic.jump({ count = 1 }) vim.diagnostic.jump({ count = 1 })
end, opts) end, opts)
map("n", "gb", vim.diagnostic.setqflist, opts)
-- formatting -- formatting
map("n", "<leader>c", vim.lsp.buf.format) map("n", "<leader>c", vim.lsp.buf.format)

View File

@ -1,4 +1,9 @@
-- stolen from https://github.com/glepnir/nvim with some modifications by me -- 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 --- add char to list of triggerable chars
---@param list table list of chars ---@param list table list of chars
@ -16,14 +21,15 @@ local function add_to_client(list, char)
end end
end end
-- make sure we can add autos
local misc = require("core.misc") local misc = require("core.misc")
local auto = misc.auto local auto = misc.auto
local completion_group = misc.augroup("lsp.completion")
local competion_group = misc.augroup("lsp.completion") -- Configure the lsp completion menu. In addition to setting up lsp completion
-- this also styles it to look nice.
-- configure the lsp completion menu
auto("LspAttach", { auto("LspAttach", {
group = competion_group, group = completion_group,
callback = function(ctx) callback = function(ctx)
local client = vim.lsp.get_client_by_id(ctx.data.client_id) local client = vim.lsp.get_client_by_id(ctx.data.client_id)
if not client or not client:supports_method("textDocument/completion") then if not client or not client:supports_method("textDocument/completion") then
@ -43,6 +49,9 @@ auto("LspAttach", {
convert = function(item) convert = function(item)
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'u' local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or 'u'
return { 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()', ''), abbr = item.label:gsub('%b()', ''),
kind = kind:sub(1, 1):lower(), kind = kind:sub(1, 1):lower(),
menu = '' menu = ''
@ -54,7 +63,7 @@ auto("LspAttach", {
-- attempt to style the completion documentation popup -- attempt to style the completion documentation popup
auto("CompleteChanged", { auto("CompleteChanged", {
group = competion_group, group = completion_group,
callback = function() callback = function()
local info = vim.fn.complete_info({ "selected" }) local info = vim.fn.complete_info({ "selected" })
if info.preview_bufnr and vim.bo[info.preview_bufnr].filetype == "" then if info.preview_bufnr and vim.bo[info.preview_bufnr].filetype == "" then
@ -69,9 +78,10 @@ auto("CompleteChanged", {
-- only supports function calls. -- only supports function calls.
-- --
-- there's a very good chance this will give us problems for languages who do -- there's a very good chance this will give us problems for languages who do
-- not follow the c-style function call style -- not follow the c-style function call style. I've only gotten this working in
-- lua thus far.
auto("CompleteDonePre", { auto("CompleteDonePre", {
group = competion_group, group = completion_group,
callback = function() callback = function()
local item = vim.tbl_get( local item = vim.tbl_get(
vim.v.completed_item, vim.v.completed_item,
@ -138,6 +148,7 @@ auto("CompleteDonePre", {
n_complete_item.user_data.nvim.lsp.completion_item.insertText = 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.insertTextFormat = 2
n_complete_item.user_data.nvim.lsp.completion_item.kind = 3
vim.v.completed_item = n_complete_item vim.v.completed_item = n_complete_item
end end
end end
@ -146,12 +157,12 @@ auto("CompleteDonePre", {
-- show the signature help when inside a function call -- show the signature help when inside a function call
auto("CompleteDone", { auto("CompleteDone", {
group = competion_group, group = completion_group,
callback = function(ctx) callback = function(ctx)
-- make sure there's an lsp client, and make sure the lsp client supports -- make sure there's an lsp client, and make sure the lsp client supports
-- textDocument/signatureHelp -- textDocument/signatureHelp
local client = vim.lsp.get_clients({ bufnr = ctx.buf })[0] local client = vim.lsp.get_clients({ bufnr = ctx.buf })[1]
if not client or not client[0]:supports_method("textDocument/signatureHelp") then if not client or not client:supports_method("textDocument/signatureHelp") then
return return
end end
@ -169,9 +180,8 @@ auto("CompleteDone", {
-- show signature help when the completion is a function -- show signature help when the completion is a function
if item.kind == 3 and (item.textEdit ~= nil or item.insertText ~= nil) then if item.kind == 3 and (item.textEdit ~= nil or item.insertText ~= nil) then
vim.schedule(function() -- for some reason calling vim.schedule didn't work for me
vim.lsp.buf.signature_help() vim.defer_fn(vim.lsp.buf.signature_help, 100)
end)
end end
end, end,
desc = "Auto show signature help when completion is done" desc = "Auto show signature help when completion is done"

View File

@ -2,14 +2,14 @@ local M = {}
--- setup vim lsp options --- setup vim lsp options
function M.setup() function M.setup()
-- ensure the severs are setup
require("core.lsp.servers")
-- confgiure lsp -- confgiure lsp
vim.diagnostic.config { vim.diagnostic.config {
virtual_text = false,
virtual_lines = { virtual_lines = {
current_line = true current_line = true
}, },
update_in_insert = false,
underline = true,
severity_sort = true, severity_sort = true,
signs = { signs = {
text = { text = {
@ -28,6 +28,7 @@ function M.setup()
require("core.lsp.binds") require("core.lsp.binds")
require("core.lsp.completion") require("core.lsp.completion")
require("core.lsp.wtf")
end end
return M return M

11
lua/core/lsp/servers.lua Normal file
View 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
View 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
})

View File

@ -3,20 +3,9 @@ local M = {}
--- vim.notify title --- vim.notify title
M.appid = "Nvim Config" 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 --- extend vim.kemap.set
---@param mode string|table mode for the keymap ---@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 cmd function|string command to run
---@param opts vim.keymap.set.Opts? keymap options ---@param opts vim.keymap.set.Opts? keymap options
function M.map(mode, bind, cmd, opts) function M.map(mode, bind, cmd, opts)
@ -35,19 +24,12 @@ function M.map(mode, bind, cmd, opts)
end end
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) vim.keymap.set(mode, bind, cmd, opts)
end
end end
--- a small map wrapper to easily create local buffer mappings --- a small map wrapper to easily create local buffer mappings
---@param mode string|table mode for the keymap ---@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 cmd function|string command to run
---@param opts table? keymap options ---@param opts table? keymap options
function M.map_local(mode, bind, cmd, opts) function M.map_local(mode, bind, cmd, opts)
@ -56,13 +38,8 @@ function M.map_local(mode, bind, cmd, opts)
M.map(mode, bind, cmd, opts) M.map(mode, bind, cmd, opts)
end end
--- extend vim.api.nvim_create_autocmd --- shorten vim.api.nvim_create_autocmd call
---@param event string|table event or events M.auto = vim.api.nvim_create_autocmd
---@param opts vim.api.keyset.create_autocmd options
---@return integer
function M.auto(event, opts)
return vim.api.nvim_create_autocmd(event, opts)
end
--- extend auto group --- extend auto group
---@param name string name of the autogroup ---@param name string name of the autogroup
@ -82,85 +59,4 @@ function M.lz(txt)
return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>" return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>"
end 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
end
return M return M

19
lua/snippets/lua.lua Normal file
View 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)
})
}