From b7c38200f43ebe87c0ff73cf2522c9021b0f6cb1 Mon Sep 17 00:00:00 2001 From: caprain Date: Thu, 16 Apr 2026 21:33:18 +0800 Subject: [PATCH] =?UTF-8?q?ts=E5=92=8Cjs=E4=BD=BF=E7=94=A8deno=E6=9D=A5?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/pack/configs/conform.lua | 41 ++++++++++++++++++++++++++-------- lua/pack/configs/lspconfig.lua | 4 ++-- lua/pack/configs/mini.lua | 2 +- lua/pack/configs/peek.lua | 4 ++-- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lua/pack/configs/conform.lua b/lua/pack/configs/conform.lua index 113908d..0b05798 100644 --- a/lua/pack/configs/conform.lua +++ b/lua/pack/configs/conform.lua @@ -17,8 +17,15 @@ local formatters_by_ft = { html = { "djlint" }, sh = { "shfmt" }, zsh = { "shfmt" }, + typescript = { "deno_fmt" }, + javascript = { "deno_fmt" }, + markdown = { "deno_fmt_markdown" }, } +local real_executable_map = { + deno_fmt = "deno", + deno_fmt_markdown = "deno", +} -- 辅助函数:从指定文件类型的配置中提取所有工具名称(去重) local function get_ensure_installed_for_ft(ft, ft_table) @@ -44,17 +51,33 @@ end vim.keymap.set({ "n", "x" }, "f", function() PackUtils.load(P, function() require("conform").setup({ -- At a minimum, you will need to set up some formatters by filetype - formatters_by_ft = formatters_by_ft - }) + formatters_by_ft = formatters_by_ft, + formatters = { + deno_fmt_markdown = { + inherit = "deno_fmt", -- 继承格式化程序 + append_args = { "--indent-width", "4" }, + } + }, + } + ) end) - local registry = require("mason-registry") local ft = vim.bo.filetype - local tools = get_ensure_installed_for_ft(ft, formatters_by_ft) - for _, tool in ipairs(tools) do - if not registry.is_installed(tool) then - vim.notify("Installing formatter: " .. tool, vim.log.levels.INFO) - registry.get_package(tool):install() + local raw_tools = get_ensure_installed_for_ft(ft, formatters_by_ft) + local need_install = false + for _, raw_tool in ipairs(raw_tools) do + local real_tool = real_executable_map[raw_tool] or raw_tool + if vim.fn.executable(real_tool) == 0 then + need_install = true + local registry = require("mason-registry") + if not registry.is_installed(real_tool) then + vim.notify("⬇️ Installing formatter: " .. real_tool, vim.log.levels.INFO) + registry.get_package(real_tool):install() + end end end - require("conform").format({ async = true, lsp_fallback = true }) + if need_install then + vim.notify("⏳ 格式化工具正在后台安装,请稍后重试...", vim.log.levels.WARN) + else + require("conform").format({ async = true, lsp_fallback = true }) + end end, { desc = "格式化代码(检测安装缺失工具)" }) diff --git a/lua/pack/configs/lspconfig.lua b/lua/pack/configs/lspconfig.lua index 9d60b77..873cc88 100644 --- a/lua/pack/configs/lspconfig.lua +++ b/lua/pack/configs/lspconfig.lua @@ -5,9 +5,9 @@ if vim.g.vscode then return end local arch = jit and jit.arch or "" local is_arm = arch:match("arm") or arch:match("aarch64") -local servers = { "lua_ls", "rust_analyzer", "pylsp" } +local servers = { "lua_ls", "rust_analyzer", "pylsp", "denols", } if not is_arm then - vim.list_extend(servers, { "marksman", "ts_ls", "svelte", "cssls", "html" }) + vim.list_extend(servers, { "marksman", "svelte", "cssls", "html" }) end -- 2. 插件配置清单 diff --git a/lua/pack/configs/mini.lua b/lua/pack/configs/mini.lua index 42102b1..64bf7f5 100644 --- a/lua/pack/configs/mini.lua +++ b/lua/pack/configs/mini.lua @@ -29,7 +29,7 @@ vim.api.nvim_create_autocmd({ input = { '%*().-()%*' }, output = { left = '*', right = '*' } }, - c = { + d = { input = { '`().-()`' }, output = { left = '`', right = '`' } } diff --git a/lua/pack/configs/peek.lua b/lua/pack/configs/peek.lua index 0a6dfc9..c133b1c 100644 --- a/lua/pack/configs/peek.lua +++ b/lua/pack/configs/peek.lua @@ -13,9 +13,9 @@ vim.api.nvim_create_user_command("PeekOpen", function() PackUtils.load(P, function() require("peek").setup({ port = 9000, - app = { "zen", "-private-window" }, + -- app = { "zen", "-private-window" }, -- app = { "firefox-esr", "-private-window" }, - -- app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" }, + app = { "chromium", "--app=http://localhost:9000/?theme=dark", "--incognito" }, }) end) require("peek").open()