refactor(lua): reformat and clean up Lua configuration files
This commit is contained in:
1 parent
b4b165fb96
commit
54444c9f33
7 files changed
+131
-185
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ return {
|
||||
{ import = "astrocommunity.pack.go" },
|
||||
{ import = "astrocommunity.pack.golangci-lint" },
|
||||
{ import = "astrocommunity.pack.html-css" },
|
||||
{ import = "astrocommunity.pack.oxlint" },
|
||||
-- oxlint configured manually in astrolsp.lua via nvim-lint
|
||||
{ import = "astrocommunity.pack.toml" },
|
||||
{ import = "astrocommunity.pack.templ" },
|
||||
{ import = "astrocommunity.pack.tailwindcss" },
|
||||
|
||||
+19
-62
@@ -86,9 +86,15 @@ return {
|
||||
local filepath = vim.fn.expand "%:p"
|
||||
local filename = vim.fn.expand "%:t"
|
||||
|
||||
-- If no file is open, show Nvim only
|
||||
-- If no file is open, try to show just the repo name
|
||||
if filename == "" then
|
||||
local cwd = vim.fn.getcwd()
|
||||
local github_match = cwd:match "github%.com/([^/]+/[^/]+)"
|
||||
if github_match then
|
||||
vim.opt.titlestring = github_match
|
||||
else
|
||||
vim.opt.titlestring = "Nvim"
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@@ -96,8 +102,8 @@ return {
|
||||
local github_match = filepath:match "github%.com/([^/]+/[^/]+)"
|
||||
|
||||
if github_match then
|
||||
-- Format: filename (org/repo) | Nvim
|
||||
vim.opt.titlestring = string.format("%s (%s) | Nvim", filename, github_match)
|
||||
-- Format: filename | org/repo
|
||||
vim.opt.titlestring = string.format("%s | %s", filename, github_match)
|
||||
else
|
||||
-- Fallback: filename | Nvim
|
||||
vim.opt.titlestring = string.format("%s | Nvim", filename)
|
||||
@@ -105,13 +111,13 @@ return {
|
||||
end,
|
||||
},
|
||||
},
|
||||
-- Show recent files or git repos on startup
|
||||
-- Show smart picker on startup
|
||||
startup_picker = {
|
||||
{
|
||||
event = "VimEnter",
|
||||
desc = "Show recent files for git repo or git repos picker on startup",
|
||||
desc = "Show smart picker on startup",
|
||||
callback = function()
|
||||
-- Skip if opening with arguments (files, directories, stdin)
|
||||
-- Skip if opening with arguments
|
||||
if vim.fn.argc() > 0 then return end
|
||||
|
||||
-- Skip if current buffer has content
|
||||
@@ -120,59 +126,9 @@ return {
|
||||
|
||||
-- Delay to ensure everything is loaded
|
||||
vim.defer_fn(function()
|
||||
-- Check if we're in a git repo
|
||||
local git_dir = vim.fn.systemlist("git rev-parse --git-dir 2>/dev/null")[1]
|
||||
local is_git_repo = vim.v.shell_error == 0 and git_dir ~= nil and git_dir ~= ""
|
||||
|
||||
if is_git_repo then
|
||||
-- In a git repo: show recent files
|
||||
require("snacks").picker.recent()
|
||||
else
|
||||
-- Not in a git repo: show git repos using ghq
|
||||
if vim.fn.executable "ghq" == 1 then
|
||||
-- Get list of repos from ghq
|
||||
local repos = vim.fn.systemlist "ghq list --full-path"
|
||||
if #repos > 0 then
|
||||
-- Build items list with formatted display
|
||||
local items = {}
|
||||
for _, repo_path in ipairs(repos) do
|
||||
-- Extract org/repo from path
|
||||
local display = repo_path:match "github%.com/([^/]+/[^/]+)" or vim.fn.fnamemodify(repo_path, ":t")
|
||||
table.insert(items, {
|
||||
text = display,
|
||||
path = repo_path,
|
||||
})
|
||||
end
|
||||
|
||||
-- Use snacks picker to show repos
|
||||
require("snacks").picker({
|
||||
title = "Git Repositories",
|
||||
layout = { preview = false },
|
||||
items = items,
|
||||
format = function(item)
|
||||
return { { item.text } }
|
||||
end,
|
||||
confirm = function(picker, item)
|
||||
picker:close()
|
||||
-- Change to the selected repo directory
|
||||
vim.cmd("cd " .. item.path)
|
||||
-- Show recent files from the new directory
|
||||
vim.defer_fn(function()
|
||||
require("snacks").picker.recent()
|
||||
require("snacks").picker.smart()
|
||||
end, 50)
|
||||
end,
|
||||
})
|
||||
else
|
||||
-- Fallback to recent files if no repos found
|
||||
require("snacks").picker.recent()
|
||||
end
|
||||
else
|
||||
-- ghq not available, just show recent files
|
||||
require("snacks").picker.recent()
|
||||
end
|
||||
end
|
||||
end, 10)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -511,10 +467,10 @@ return {
|
||||
},
|
||||
-- AI/Assistant mappings (Claude Code)
|
||||
["<C-a>"] = { nil, desc = "AI/Claude Code" },
|
||||
["<C-a><C-a>"] = { function() _G.claude_at_root("ClaudeCode")() end, desc = "Toggle Claude" },
|
||||
["<C-a>f"] = { function() _G.claude_at_root("ClaudeCodeFocus")() end, desc = "Focus Claude" },
|
||||
["<C-a>C"] = { function() _G.claude_at_root("ClaudeCode --resume")() end, desc = "Resume Claude" },
|
||||
["<C-a>c"] = { function() _G.claude_at_root("ClaudeCode --continue")() end, desc = "Continue Claude" },
|
||||
["<C-a><C-a>"] = { function() _G.claude_at_root "ClaudeCode"() end, desc = "Toggle Claude" },
|
||||
["<C-a>f"] = { function() _G.claude_at_root "ClaudeCodeFocus"() end, desc = "Focus Claude" },
|
||||
["<C-a>C"] = { function() _G.claude_at_root "ClaudeCode --resume"() end, desc = "Resume Claude" },
|
||||
["<C-a>c"] = { function() _G.claude_at_root "ClaudeCode --continue"() end, desc = "Continue Claude" },
|
||||
["<C-a>m"] = { "<cmd>ClaudeCodeSelectModel<cr>", desc = "Select Claude model" },
|
||||
["<C-a>b"] = { "<cmd>ClaudeCodeAdd %<cr>", desc = "Add current buffer" },
|
||||
["<C-a>y"] = { "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
|
||||
@@ -575,7 +531,8 @@ return {
|
||||
},
|
||||
["<leader>ua"] = {
|
||||
function() require("snacks").toggle.animate():toggle() end,
|
||||
desc = "Toggle Animations", },
|
||||
desc = "Toggle Animations",
|
||||
},
|
||||
["<leader>uS"] = {
|
||||
function() require("snacks").toggle.scroll():toggle() end,
|
||||
desc = "Toggle Smooth Scroll",
|
||||
|
||||
+27
-65
@@ -50,7 +50,8 @@ return {
|
||||
},
|
||||
-- Disable LSP formatting for these (use conform.nvim/oxfmt instead)
|
||||
disabled = {
|
||||
"tsserver", -- Use oxfmt via conform
|
||||
"ts_ls", -- Use oxfmt via conform
|
||||
"tsserver", -- Old name, keeping for compatibility
|
||||
"vtsls", -- Use oxfmt via conform
|
||||
"html", -- Use conform
|
||||
"cssls", -- Use conform
|
||||
@@ -59,13 +60,16 @@ return {
|
||||
timeout_ms = 5000, -- Increase timeout for large Go files
|
||||
filter = function(client)
|
||||
-- Prefer conform.nvim for JS/TS formatting
|
||||
if vim.bo.filetype == "typescript" or vim.bo.filetype == "javascript" or vim.bo.filetype == "typescriptreact" or vim.bo.filetype == "javascriptreact" then
|
||||
if
|
||||
vim.bo.filetype == "typescript"
|
||||
or vim.bo.filetype == "javascript"
|
||||
or vim.bo.filetype == "typescriptreact"
|
||||
or vim.bo.filetype == "javascriptreact"
|
||||
then
|
||||
return false
|
||||
end
|
||||
-- Use gopls for Go formatting
|
||||
if vim.bo.filetype == "go" then
|
||||
return client.name == "gopls"
|
||||
end
|
||||
if vim.bo.filetype == "go" then return client.name == "gopls" end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
@@ -142,7 +146,7 @@ return {
|
||||
},
|
||||
|
||||
-- TypeScript configuration for Vite/React/Cloudflare
|
||||
tsserver = {
|
||||
ts_ls = {
|
||||
settings = {
|
||||
typescript = {
|
||||
inlayHints = {
|
||||
@@ -345,7 +349,7 @@ return {
|
||||
|
||||
-- LSP Rename (using inc-rename plugin)
|
||||
["<C-a>r"] = {
|
||||
function() return ":IncRename " .. vim.fn.expand("<cword>") end,
|
||||
function() return ":IncRename " .. vim.fn.expand "<cword>" end,
|
||||
expr = true,
|
||||
desc = "Rename current symbol",
|
||||
cond = "textDocument/rename",
|
||||
@@ -465,42 +469,6 @@ return {
|
||||
config = function()
|
||||
local lint = require "lint"
|
||||
|
||||
-- Configure oxlint for TypeScript/JavaScript
|
||||
lint.linters.oxlint = {
|
||||
cmd = "oxlint",
|
||||
stdin = false,
|
||||
args = {
|
||||
"--format=json",
|
||||
},
|
||||
stream = "stdout",
|
||||
ignore_exitcode = true,
|
||||
parser = function(output)
|
||||
if output == "" or output == nil then return {} end
|
||||
|
||||
local ok, decoded = pcall(vim.fn.json_decode, output)
|
||||
if not ok then return {} end
|
||||
|
||||
local diagnostics = {}
|
||||
for _, item in ipairs(decoded) do
|
||||
if item.diagnostics then
|
||||
for _, diagnostic in ipairs(item.diagnostics) do
|
||||
table.insert(diagnostics, {
|
||||
lnum = diagnostic.start.line - 1,
|
||||
end_lnum = diagnostic["end"].line - 1,
|
||||
col = diagnostic.start.column - 1,
|
||||
end_col = diagnostic["end"].column - 1,
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
source = "oxlint",
|
||||
message = diagnostic.message,
|
||||
code = diagnostic.rule_id,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
return diagnostics
|
||||
end,
|
||||
}
|
||||
|
||||
-- Configure linters per filetype
|
||||
lint.linters_by_ft = {
|
||||
typescript = { "oxlint" },
|
||||
@@ -659,35 +627,28 @@ return {
|
||||
optional = true,
|
||||
opts = function(_, opts)
|
||||
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, {
|
||||
"tsserver",
|
||||
-- TypeScript/JavaScript
|
||||
"ts_ls", -- tsserver was renamed to ts_ls
|
||||
"tailwindcss",
|
||||
"cssls",
|
||||
"html",
|
||||
|
||||
-- Styling
|
||||
"cssls",
|
||||
|
||||
-- Config files
|
||||
"jsonls",
|
||||
"yamlls",
|
||||
|
||||
-- Lua
|
||||
"lua_ls",
|
||||
|
||||
-- Go (Cosmos SDK)
|
||||
"gopls",
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- Mason tool installer for linters/formatters
|
||||
{
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
dependencies = { "williamboman/mason.nvim" },
|
||||
cmd = { "MasonToolsInstall", "MasonToolsUpdate" },
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
-- Formatters
|
||||
"stylua",
|
||||
"rustfmt",
|
||||
"taplo",
|
||||
-- Linters
|
||||
"stylelint",
|
||||
"markdownlint",
|
||||
-- Note: oxlint and oxfmt should be installed via cargo/npm separately
|
||||
},
|
||||
auto_update = false,
|
||||
run_on_start = true,
|
||||
},
|
||||
},
|
||||
-- Note: mason-tool-installer is configured in lua/plugins/mason.lua
|
||||
|
||||
-- ============================================================================
|
||||
-- Package Management Tools
|
||||
@@ -762,4 +723,5 @@ return {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -12,9 +12,7 @@ return {
|
||||
-- Helper function to get git root and change directory
|
||||
local function ensure_git_root()
|
||||
local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
||||
if git_root and vim.v.shell_error == 0 then
|
||||
vim.api.nvim_set_current_dir(git_root)
|
||||
end
|
||||
if git_root and vim.v.shell_error == 0 then vim.api.nvim_set_current_dir(git_root) end
|
||||
end
|
||||
|
||||
-- Wrapper function to run commands at git root
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
-- Customize Mason
|
||||
-- This file configures non-LSP tools (formatters, linters, debuggers, etc.)
|
||||
-- LSP servers are configured in astrolsp.lua via mason-lspconfig
|
||||
|
||||
---@type LazySpec
|
||||
return {
|
||||
-- use mason-tool-installer for automatically installing Mason packages
|
||||
{
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
-- overrides `require("mason-tool-installer").setup(...)`
|
||||
opts = {
|
||||
-- Make sure to use the names found in `:Mason`
|
||||
ensure_installed = {
|
||||
-- Formatters (non-LSP)
|
||||
"stylua",
|
||||
"rustfmt",
|
||||
"taplo",
|
||||
|
||||
-- Linters
|
||||
"stylelint",
|
||||
"markdownlint",
|
||||
|
||||
-- Debuggers
|
||||
"debugpy",
|
||||
|
||||
-- Other tools
|
||||
"tree-sitter-cli",
|
||||
|
||||
-- Note: oxlint and oxfmt should be installed separately via cargo/npm
|
||||
-- Note: LSP servers are configured in astrolsp.lua
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -36,7 +36,7 @@ return {
|
||||
self.esc_timer = self.esc_timer or (vim.uv or vim.loop).new_timer()
|
||||
if self.esc_timer:is_active() then
|
||||
self.esc_timer:stop()
|
||||
vim.cmd("stopinsert")
|
||||
vim.cmd "stopinsert"
|
||||
else
|
||||
self.esc_timer:start(200, 0, function() end)
|
||||
return "<esc>"
|
||||
|
||||
+48
-53
@@ -23,6 +23,52 @@ return {
|
||||
template.register("{{_dir_}}", function() return vim.fn.expand "%:p:h" end)
|
||||
template.register("{{_project_}}", function() return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") end)
|
||||
|
||||
-- Helper function to insert template
|
||||
local function insert_template(lines)
|
||||
local cursor_line = nil
|
||||
local processed = {}
|
||||
|
||||
for i, line in ipairs(lines) do
|
||||
-- Replace template markers
|
||||
line = line:gsub("{{_date_}}", os.date "%Y-%m-%d %H:%M:%S")
|
||||
line = line:gsub("{{_author_}}", "Prad")
|
||||
line = line:gsub("{{_email_}}", "prad@sonr.io")
|
||||
line = line:gsub("{{_file_name_}}", vim.fn.expand "%:t:r")
|
||||
line = line:gsub("{{_upper_file_}}", vim.fn.expand("%:t:r"):upper())
|
||||
|
||||
-- Convert snake_case to CamelCase
|
||||
local file_name = vim.fn.expand "%:t:r"
|
||||
local camel_case = file_name:gsub("_(%w)", function(c) return c:upper() end)
|
||||
camel_case = camel_case:gsub("^%w", string.upper)
|
||||
line = line:gsub("{{_camel_case_file_}}", camel_case)
|
||||
|
||||
-- Handle lua expressions
|
||||
line = line:gsub("{{_lua:(.-)_}}", function(expr)
|
||||
local func = load("return " .. expr)
|
||||
if func then
|
||||
local ok, result = pcall(func)
|
||||
if ok then return tostring(result) end
|
||||
end
|
||||
return ""
|
||||
end)
|
||||
|
||||
-- Track cursor position
|
||||
if line:match "{{_cursor_}}" then
|
||||
cursor_line = i
|
||||
line = line:gsub("{{_cursor_}}", "")
|
||||
end
|
||||
|
||||
table.insert(processed, line)
|
||||
end
|
||||
|
||||
-- Insert lines at cursor
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
vim.api.nvim_buf_set_lines(0, row - 1, row - 1, false, processed)
|
||||
|
||||
-- Set cursor position if marker found
|
||||
if cursor_line then vim.api.nvim_win_set_cursor(0, { row + cursor_line - 1, 0 }) end
|
||||
end
|
||||
|
||||
-- Custom template picker using Snacks
|
||||
vim.api.nvim_create_user_command("TemplateSnacks", function(opts)
|
||||
local temp_dir = vim.fn.stdpath "config" .. "/templates"
|
||||
@@ -36,7 +82,6 @@ return {
|
||||
for _, file in ipairs(template_files) do
|
||||
if vim.fn.isdirectory(file) == 0 then
|
||||
local filename = vim.fn.fnamemodify(file, ":t")
|
||||
local relative_path = vim.fn.fnamemodify(file, ":~:.")
|
||||
local category = vim.fn.fnamemodify(file, ":h:t")
|
||||
|
||||
-- Extract filetype from template
|
||||
@@ -90,9 +135,7 @@ return {
|
||||
-- Skip filetype marker line
|
||||
if not line:match "^;; %w+" then
|
||||
-- Check for variable placeholder
|
||||
if line:match "{{_variable_}}" and not variable_name then
|
||||
needs_variable = true
|
||||
end
|
||||
if line:match "{{_variable_}}" and not variable_name then needs_variable = true end
|
||||
table.insert(processed, line)
|
||||
end
|
||||
end
|
||||
@@ -120,54 +163,6 @@ return {
|
||||
}
|
||||
end, { nargs = "?", desc = "Open template picker" })
|
||||
|
||||
-- Helper function to insert template
|
||||
function insert_template(lines)
|
||||
local cursor_line = nil
|
||||
local processed = {}
|
||||
|
||||
for i, line in ipairs(lines) do
|
||||
-- Replace template markers
|
||||
line = line:gsub("{{_date_}}", os.date "%Y-%m-%d %H:%M:%S")
|
||||
line = line:gsub("{{_author_}}", "Prad")
|
||||
line = line:gsub("{{_email_}}", "prad@sonr.io")
|
||||
line = line:gsub("{{_file_name_}}", vim.fn.expand "%:t:r")
|
||||
line = line:gsub("{{_upper_file_}}", vim.fn.expand("%:t:r"):upper())
|
||||
|
||||
-- Convert snake_case to CamelCase
|
||||
local file_name = vim.fn.expand "%:t:r"
|
||||
local camel_case = file_name:gsub("_(%w)", function(c) return c:upper() end)
|
||||
camel_case = camel_case:gsub("^%w", string.upper)
|
||||
line = line:gsub("{{_camel_case_file_}}", camel_case)
|
||||
|
||||
-- Handle lua expressions
|
||||
line = line:gsub("{{_lua:(.-)_}}", function(expr)
|
||||
local func, err = load("return " .. expr)
|
||||
if func then
|
||||
local ok, result = pcall(func)
|
||||
if ok then return tostring(result) end
|
||||
end
|
||||
return ""
|
||||
end)
|
||||
|
||||
-- Track cursor position
|
||||
if line:match "{{_cursor_}}" then
|
||||
cursor_line = i
|
||||
line = line:gsub("{{_cursor_}}", "")
|
||||
end
|
||||
|
||||
table.insert(processed, line)
|
||||
end
|
||||
|
||||
-- Insert lines at cursor
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
vim.api.nvim_buf_set_lines(0, row - 1, row - 1, false, processed)
|
||||
|
||||
-- Set cursor position if marker found
|
||||
if cursor_line then
|
||||
vim.api.nvim_win_set_cursor(0, { row + cursor_line - 1, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
-- Command to create new templates easily
|
||||
vim.api.nvim_create_user_command("TemplateCreate", function(opts)
|
||||
local temp_dir = vim.fn.stdpath "config" .. "/templates"
|
||||
@@ -199,7 +194,7 @@ return {
|
||||
vim.notify("Created template: " .. template_path, vim.log.levels.INFO)
|
||||
end, {
|
||||
nargs = "+",
|
||||
complete = function(_, line)
|
||||
complete = function(_, _line)
|
||||
local temp_dir = vim.fn.stdpath "config" .. "/templates"
|
||||
local categories = {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user