style(nvim): format with stylua

This commit is contained in:
Price Hiller 2023-09-13 16:32:27 -05:00
parent ec4f0146ad
commit b8765d1df6
No known key found for this signature in database
18 changed files with 160 additions and 153 deletions

View File

@ -23,7 +23,7 @@ vim.keymap.set("n", "<leader>fr", function()
"-o", "-o",
executable_path, executable_path,
"&& \n", "&& \n",
executable_path executable_path,
} }
require("toggleterm").exec(table.concat(cmd, " ")) require("toggleterm").exec(table.concat(cmd, " "))
end, { end, {

View File

@ -10,12 +10,12 @@ vim.keymap.set("n", "<leader>fr", function()
"nix-instantiate", "nix-instantiate",
"--eval", "--eval",
"--strict", "--strict",
vim.api.nvim_buf_get_name(0) vim.api.nvim_buf_get_name(0),
} }
require("toggleterm").exec(table.concat(cmd, " ")) require("toggleterm").exec(table.concat(cmd, " "))
end, { end, {
buffer = true, buffer = true,
desc = "Nix: Run with default output" desc = "Nix: Run with default output",
}) })
vim.keymap.set("n", "<leader>fj", function() vim.keymap.set("n", "<leader>fj", function()
@ -26,10 +26,10 @@ vim.keymap.set("n", "<leader>fj", function()
"--json", "--json",
vim.api.nvim_buf_get_name(0), vim.api.nvim_buf_get_name(0),
"|", "|",
"jq" "jq",
} }
require("toggleterm").exec(table.concat(cmd, " ")) require("toggleterm").exec(table.concat(cmd, " "))
end, { end, {
buffer = true, buffer = true,
desc = "Nix: Run with json output" desc = "Nix: Run with json output",
}) })

View File

@ -7,14 +7,22 @@ vim.api.nvim_create_autocmd("InsertCharPre", {
--- @return nil --- @return nil
callback = function(opts) callback = function(opts)
-- Only run if f-string escape character is typed -- Only run if f-string escape character is typed
if vim.v.char ~= "{" then return end if vim.v.char ~= "{" then
return
end
-- Get node and return early if not in a string -- Get node and return early if not in a string
local node = vim.treesitter.get_node() local node = vim.treesitter.get_node()
if not node then return end if not node then
if node:type() ~= "string" then node = node:parent() end return
if not node or node:type() ~= "string" then return end end
if node:type() ~= "string" then
node = node:parent()
end
if not node or node:type() ~= "string" then
return
end
vim.print(node:type()) vim.print(node:type())
local row, col, _, _ = vim.treesitter.get_node_range(node) local row, col, _, _ = vim.treesitter.get_node_range(node)
@ -23,7 +31,9 @@ vim.api.nvim_create_autocmd("InsertCharPre", {
local first_char = vim.api.nvim_buf_get_text(opts.buf, row, col, row, col + 1, {})[1] local first_char = vim.api.nvim_buf_get_text(opts.buf, row, col, row, col + 1, {})[1]
vim.print("row " .. row .. " col " .. col) vim.print("row " .. row .. " col " .. col)
vim.print("char: '" .. first_char .. "'") vim.print("char: '" .. first_char .. "'")
if first_char == "f" then return end if first_char == "f" then
return
end
-- Otherwise, make the string a format string -- Otherwise, make the string a format string
vim.api.nvim_input("<Esc>m'" .. row + 1 .. "gg" .. col + 1 .. "|if<Esc>`'la") vim.api.nvim_input("<Esc>m'" .. row + 1 .. "gg" .. col + 1 .. "|if<Esc>`'la")

View File

@ -17,17 +17,12 @@ M.setup = function()
if not strip_trail_space then if not strip_trail_space then
intercept_state = "`Disabled`" intercept_state = "`Disabled`"
end end
vim.notify("Strip Trail Space set to " .. intercept_state, vim.log.levels.INFO, vim.notify("Strip Trail Space set to " .. intercept_state, vim.log.levels.INFO, {
{
title = "Strip Trail Space", title = "Strip Trail Space",
---@param win integer The window handle ---@param win integer The window handle
on_open = function(win) on_open = function(win)
vim.api.nvim_buf_set_option( vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
vim.api.nvim_win_get_buf(win), end,
"filetype",
"markdown"
)
end
}) })
end, { desc = "Toggles intercepting BufWritePre to strip trail space" }) end, { desc = "Toggles intercepting BufWritePre to strip trail space" })
@ -38,7 +33,7 @@ M.setup = function()
if strip_trail_space then if strip_trail_space then
vim.cmd.StripTrailSpace() vim.cmd.StripTrailSpace()
end end
end end,
}) })
-- NOTE: Disables status column elements in Terminal buffer -- NOTE: Disables status column elements in Terminal buffer
@ -60,7 +55,9 @@ M.setup = function()
desc = "Delete [No Name] buffers", desc = "Delete [No Name] buffers",
callback = function(event) callback = function(event)
if event.file == "" and vim.bo[event.buf].buftype == "" and not vim.bo[event.buf].modified then if event.file == "" and vim.bo[event.buf].buftype == "" and not vim.bo[event.buf].modified then
vim.schedule(function() pcall(vim.api.nvim_buf_delete, event.buf, {}) end) vim.schedule(function()
pcall(vim.api.nvim_buf_delete, event.buf, {})
end)
end end
end, end,
}) })
@ -72,17 +69,12 @@ M.setup = function()
if not intercept_file_open then if not intercept_file_open then
intercept_state = "`Disabled`" intercept_state = "`Disabled`"
end end
vim.notify("Intercept file open set to " .. intercept_state, vim.log.levels.INFO, vim.notify("Intercept file open set to " .. intercept_state, vim.log.levels.INFO, {
{
title = "Intercept File Open", title = "Intercept File Open",
---@param win integer The window handle ---@param win integer The window handle
on_open = function(win) on_open = function(win)
vim.api.nvim_buf_set_option( vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
vim.api.nvim_win_get_buf(win), end,
"filetype",
"markdown"
)
end
}) })
end, { desc = "Toggles intercepting BufNew to open files in custom programs" }) end, { desc = "Toggles intercepting BufNew to open files in custom programs" })
@ -106,21 +98,13 @@ M.setup = function()
---@param fpath string The file path given to the program ---@param fpath string The file path given to the program
---@param fname string The file name used in notifications ---@param fname string The file name used in notifications
local function open_mime(buf, fpath, fname) local function open_mime(buf, fpath, fname)
vim.notify( vim.notify(string.format("Opening `%s` in external program", fname), vim.log.levels.INFO, {
string.format("Opening `%s` in external program", fname),
vim.log.levels.INFO,
{
title = "Open File in External Program", title = "Open File in External Program",
---@param win integer The window handle ---@param win integer The window handle
on_open = function(win) on_open = function(win)
vim.api.nvim_buf_set_option( vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
vim.api.nvim_win_get_buf(win), end,
"filetype", })
"markdown"
)
end
}
)
vim.system({ "xdg-open", fpath }, { detach = true }) vim.system({ "xdg-open", fpath }, { detach = true })
vim.api.nvim_buf_delete(buf, { force = true }) vim.api.nvim_buf_delete(buf, { force = true })
end end
@ -136,7 +120,7 @@ M.setup = function()
["mp4"] = function(buf, fpath, fname) ["mp4"] = function(buf, fpath, fname)
open_mime(buf, fpath, fname) open_mime(buf, fpath, fname)
end, end,
["gif"] = "mp4" ["gif"] = "mp4",
} }
---Get the extension callback for a given extension. Will do a recursive lookup if an extension callback is actually ---Get the extension callback for a given extension. Will do a recursive lookup if an extension callback is actually
@ -157,7 +141,7 @@ M.setup = function()
callback(bufnr, path, filename) callback(bufnr, path, filename)
end end
end end
end end,
}) })
end end

View File

@ -17,14 +17,11 @@ local function indent_traverse(direction, equal) -- {{{
-- Look for a line of appropriate indent -- Look for a line of appropriate indent
-- level without going out of the buffer -- level without going out of the buffer
while (not match) while (not match) and (match_line ~= buf_length) and (match_line ~= 1) do
and (match_line ~= buf_length)
and (match_line ~= 1)
do
match_line = match_line + direction match_line = match_line + direction
local match_line_str = vim.api.nvim_buf_get_lines(0, match_line - 1, match_line, false)[1] local match_line_str = vim.api.nvim_buf_get_lines(0, match_line - 1, match_line, false)[1]
-- local match_line_is_whitespace = match_line_str and match_line_str:match('^%s*$') -- local match_line_is_whitespace = match_line_str and match_line_str:match('^%s*$')
local match_line_is_whitespace = match_line_str:match('^%s*$') local match_line_is_whitespace = match_line_str:match("^%s*$")
if equal then if equal then
match_indent = vim.fn.indent(match_line) <= vim.fn.indent(current_line) match_indent = vim.fn.indent(match_line) <= vim.fn.indent(current_line)

View File

@ -66,25 +66,35 @@ return {
s = s / 100 s = s / 100
l = l / 100 l = l / 100
local r, g, b; local r, g, b
if s == 0 then if s == 0 then
r, g, b = l, l, l; -- achromatic r, g, b = l, l, l -- achromatic
else else
local function hue2rgb(p, q, t) local function hue2rgb(p, q, t)
if t < 0 then t = t + 1 end if t < 0 then
if t > 1 then t = t - 1 end t = t + 1
if t < 1 / 6 then return p + (q - p) * 6 * t end end
if t < 1 / 2 then return q end if t > 1 then
if t < 2 / 3 then return p + (q - p) * (2 / 3 - t) * 6 end t = t - 1
return p; end
if t < 1 / 6 then
return p + (q - p) * 6 * t
end
if t < 1 / 2 then
return q
end
if t < 2 / 3 then
return p + (q - p) * (2 / 3 - t) * 6
end
return p
end end
local q = l < 0.5 and l * (1 + s) or l + s - l * s; local q = l < 0.5 and l * (1 + s) or l + s - l * s
local p = 2 * l - q; local p = 2 * l - q
r = hue2rgb(p, q, h + 1 / 3); r = hue2rgb(p, q, h + 1 / 3)
g = hue2rgb(p, q, h); g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1 / 3); b = hue2rgb(p, q, h - 1 / 3)
end end
local function round(num) local function round(num)
@ -93,7 +103,6 @@ return {
return round(r * 255), round(g * 255), round(b * 255) return round(r * 255), round(g * 255), round(b * 255)
end end
---@param sources table? ---@param sources table?
local standard_sources = function(sources) local standard_sources = function(sources)
sources = sources or {} sources = sources or {}
@ -170,8 +179,12 @@ return {
return conversion return conversion
end end
end end
return string.format("#%s%s%s", convertNumHex(red), convertNumHex(green), return string.format(
convertNumHex(blue)) "#%s%s%s",
convertNumHex(red),
convertNumHex(green),
convertNumHex(blue)
)
end end
if type(hl) == string then if type(hl) == string then
@ -180,11 +193,11 @@ return {
hl = rgbToHex(red, green, blue) hl = rgbToHex(red, green, blue)
end end
local start, _, hue, saturation, lightness = hl:find( local start, _, hue, saturation, lightness =
"hsl.*%((%d+), (%d+)%%, (%d+)%%.*%)") hl:find("hsl.*%((%d+), (%d+)%%, (%d+)%%.*%)")
if start ~= nil then if start ~= nil then
red, green, blue = hslToRgb(tonumber(hue), tonumber(saturation), red, green, blue =
tonumber(lightness)) hslToRgb(tonumber(hue), tonumber(saturation), tonumber(lightness))
hl = rgbToHex(red, green, blue) hl = rgbToHex(red, green, blue)
end end

View File

@ -8,11 +8,11 @@ return {
return { return {
window = { window = {
open = "alternate" open = "alternate",
}, },
one_per = { one_per = {
wezterm = false, wezterm = false,
kitty = false kitty = false,
}, },
callbacks = { callbacks = {
should_block = function(argv) should_block = function(argv)
@ -49,7 +49,7 @@ return {
once = true, once = true,
callback = vim.schedule_wrap(function() callback = vim.schedule_wrap(function()
vim.api.nvim_buf_delete(bufnr, {}) vim.api.nvim_buf_delete(bufnr, {})
end) end),
}) })
end end
end, end,
@ -61,9 +61,9 @@ return {
saved_terminal = nil saved_terminal = nil
end end
end) end)
end end,
} },
}
end
} }
end,
},
} }

View File

@ -28,9 +28,9 @@ return {
asm = function() asm = function()
return { return {
exe = "asmfmt", exe = "asmfmt",
stdin = true stdin = true,
} }
end end,
}, },
} }
end, end,

View File

@ -1,12 +1,12 @@
return { return {
{ {
'pwntester/octo.nvim', "pwntester/octo.nvim",
cmd = "Octo", cmd = "Octo",
dependencies = { dependencies = {
'nvim-lua/plenary.nvim', "nvim-lua/plenary.nvim",
'nvim-telescope/telescope.nvim', "nvim-telescope/telescope.nvim",
'nvim-tree/nvim-web-devicons', "nvim-tree/nvim-web-devicons",
},
config = true,
}, },
config = true
}
} }

View File

@ -142,11 +142,11 @@ return {
local filename = self.filename local filename = self.filename
local extension = vim.fn.fnamemodify(filename, ":e") local extension = vim.fn.fnamemodify(filename, ":e")
local buftype = vim.api.nvim_get_option_value("buftype", { local buftype = vim.api.nvim_get_option_value("buftype", {
buf = self.bufnr buf = self.bufnr,
}) })
local filetype = vim.api.nvim_get_option_value("filetype", { local filetype = vim.api.nvim_get_option_value("filetype", {
buf = self.bufnr buf = self.bufnr,
}) })
self.icon, self.icon_color = self.icon, self.icon_color =
require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) require("nvim-web-devicons").get_icon_color(filename, extension, { default = true })
@ -155,11 +155,11 @@ return {
["rust"] = { icon = "", icon_color = self.icon_color }, ["rust"] = { icon = "", icon_color = self.icon_color },
["sshconfig"] = { icon = "󰴳", icon_color = colors.carpYellow }, ["sshconfig"] = { icon = "󰴳", icon_color = colors.carpYellow },
["sshdconfig"] = "sshconfig", ["sshdconfig"] = "sshconfig",
["help"] = { icon = "󰋗", icon_color = colors.springGreen } ["help"] = { icon = "󰋗", icon_color = colors.springGreen },
} }
local buftype_overrides = { local buftype_overrides = {
["terminal"] = { icon = "", icon_color = colors.roninYellow } ["terminal"] = { icon = "", icon_color = colors.roninYellow },
} }
local function get_override(name, overrides) local function get_override(name, overrides)
@ -194,7 +194,7 @@ return {
provider = function(self) provider = function(self)
local filename = "" local filename = ""
local buftype = vim.api.nvim_get_option_value("buftype", { local buftype = vim.api.nvim_get_option_value("buftype", {
buf = self.bufnr buf = self.bufnr,
}) })
if buftype == "terminal" then if buftype == "terminal" then
local subs = 0 local subs = 0
@ -562,7 +562,7 @@ return {
end end
return { fg = colors.oniViolet, bg = bg } return { fg = colors.oniViolet, bg = bg }
end end,
}, },
}, },
{ {
@ -589,7 +589,7 @@ return {
return { fg = colors.oniViolet2, bg = bg } return { fg = colors.oniViolet2, bg = bg }
end, end,
}, },
} },
}, },
{ {
condition = conditions.has_diagnostics, condition = conditions.has_diagnostics,
@ -676,7 +676,7 @@ return {
}, },
{ {
FileIcon, FileIcon,
hl = { bg = colors.sumiInk4 } hl = { bg = colors.sumiInk4 },
}, },
{ {
provider = seps.full.right, provider = seps.full.right,

View File

@ -1,9 +1,9 @@
return { return {
{ {
'tzachar/highlight-undo.nvim', "tzachar/highlight-undo.nvim",
keys = { keys = {
{ "u" }, { "u" },
{"<C-r>"} { "<C-r>" },
}, },
opts = {}, opts = {},
}, },

View File

@ -9,7 +9,7 @@ return {
}, },
keys = { keys = {
{ "<leader>h", desc = "> Hydra" }, { "<leader>h", desc = "> Hydra" },
{ "<C-w>" } { "<C-w>" },
}, },
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
config = function() config = function()

View File

@ -462,16 +462,17 @@ return {
require("typescript-tools").setup({ require("typescript-tools").setup({
on_attach = on_attach, on_attach = on_attach,
settings = { settings = {
tsserver_path = vim.fn.stdpath("data") .. "/mason/packages/typescript-language-server/node_modules/typescript/lib/tsserver.js", tsserver_path = vim.fn.stdpath("data")
.. "/mason/packages/typescript-language-server/node_modules/typescript/lib/tsserver.js",
expose_as_code_action = { expose_as_code_action = {
"fix_all", "fix_all",
"add_missing_imports", "add_missing_imports",
"remove_unused", "remove_unused",
"remove_unused_imports", "remove_unused_imports",
"organize_imports" "organize_imports",
}, },
tsserver_plugins = { tsserver_plugins = {
"@styled/typescript-styled-plugin" "@styled/typescript-styled-plugin",
}, },
tsserver_file_preferences = { tsserver_file_preferences = {
includeInlayParameterNameHints = "all", includeInlayParameterNameHints = "all",
@ -497,11 +498,10 @@ return {
functionTypeParameters = true, functionTypeParameters = true,
parameterNames = true, parameterNames = true,
rangeVariableTypes = true, rangeVariableTypes = true,
} },
} },
} },
} })
)
-- NOTE: GENERIC LSP SERVERS -- NOTE: GENERIC LSP SERVERS
for _, server in ipairs({ for _, server in ipairs({

View File

@ -193,9 +193,14 @@ return {
---@param obj vim.SystemCompleted ---@param obj vim.SystemCompleted
vim.system({ "xdg-open", selection["value"][2] }, { text = true }, function(obj) vim.system({ "xdg-open", selection["value"][2] }, { text = true }, function(obj)
if obj.code ~= 0 then if obj.code ~= 0 then
vim.notify(string.format( vim.notify(
string.format(
"Failed to open selection, exit code: %s!\n---Stdout---\n%s\n---Stderr---\n%s", "Failed to open selection, exit code: %s!\n---Stdout---\n%s\n---Stderr---\n%s",
obj.code, obj.stdout, obj.stderr)) obj.code,
obj.stdout,
obj.stderr
)
)
end end
end) end)
end) end)

View File

@ -22,7 +22,7 @@ return {
vim.cmd.ToggleTerm() vim.cmd.ToggleTerm()
end end
end, end,
desc = "ToggleTerm: Toggle" desc = "ToggleTerm: Toggle",
}, },
}, },
opts = { opts = {

View File

@ -122,7 +122,7 @@ return {
}, },
"JoosepAlviste/nvim-ts-context-commentstring", "JoosepAlviste/nvim-ts-context-commentstring",
"nvim-treesitter/nvim-treesitter-textobjects", "nvim-treesitter/nvim-treesitter-textobjects",
"RRethy/nvim-treesitter-endwise" "RRethy/nvim-treesitter-endwise",
}, },
config = function() config = function()
local treesitter_dir = vim.fn.stdpath("data") .. "/treesitter" local treesitter_dir = vim.fn.stdpath("data") .. "/treesitter"
@ -180,7 +180,7 @@ return {
enable = true, enable = true,
}, },
endwise = { endwise = {
enable = true enable = true,
}, },
textobjects = { textobjects = {
select = { select = {
@ -234,7 +234,6 @@ return {
}, },
include_surrounding_whitespace = true, include_surrounding_whitespace = true,
}, },
}) })
end, end,
}, },

View File

@ -51,5 +51,4 @@ U.title_case = function(str)
return string.gsub(str, "(%a)([%w_']*)", inner) return string.gsub(str, "(%a)([%w_']*)", inner)
end end
return U return U