local util = require("rc.util") local monaqa = require("monaqa") local motion_autoselect = monaqa.edit.motion_autoselect local logic = monaqa.logic local create_cmd = monaqa.shorthand.create_cmd local mapset = monaqa.shorthand.mapset local vec = require("rc.util.vec") local plugins = vec {} -- coc plugins:push { "https://github.com/neoclide/coc.nvim", branch = "release", cond = function() return monaqa.lsp.choose_lsp() == "coc" end, config = function() local function coc_service_names(arglead, cmdline, cursorpos) return vim.tbl_map(function(service) return service["id"] end, vim.fn.CocAction("services")) end create_cmd("CocToggleService") { desc = [[引数に与えた coc のサービスを有効化・無効化する]], nargs = 1, complete = coc_service_names, function(meta) vim.fn.CocAction("toggleService", meta.args) end, } vim.opt.tagfunc = "CocTagFunc" vim.g["coc_global_extensions"] = { "coc-deno", "coc-json", "coc-marketplace", "coc-pyright", "coc-rust-analyzer", "coc-snippets", "coc-sumneko-lua", "coc-toml", "coc-tsserver", "coc-yaml", "coc-tsdetect", "coc-css", "@yaegassy/coc-tailwindcss3", "coc-eslint", } vim.keymap.set("n", "gd", "") mapset.n("t") { "" } mapset.n("td") { "Telescope coc definitions" } mapset.n("ti") { "Telescope coc implementations" } mapset.n("tr") { "Telescope coc references" } mapset.n("ty") { "Telescope coc type_definitions" } mapset.n("tA") { "Telescope coc code_actions" } mapset.n("tn") { "(coc-rename)" } mapset.n("ta") { "(coc-codeaction-cursor)" } mapset.x("ta") { "(coc-codeaction-selected)" } mapset.n("tw") { "(coc-float-jump)" } mapset.n("K") { "call CocActionAsync('doHover')" } mapset.n("tf") { "call CocActionAsync('format')" } mapset.n("th") { "CocCommand document.toggleInlayHint" } -- coc#_select_confirm などは Lua 上では動かないので、 にマッピングして使えるようにする mapset.i("(vimrc-coc-select-confirm)") { "coc#_select_confirm()", expr = true } mapset.i("(vimrc-lexima-expand-cr)") { "lexima#expand('CR>', 'i')", expr = true } -- mapset.i("") { -- desc = [[lexima と coc 両方を加味したエンター]], -- expr = true, -- remap = true, -- function() -- if logic.to_bool(vim.fn["coc#pum#visible"]()) then -- -- 補完候補をセレクトしていたときのみ、補完候補の内容で確定する -- -- (意図せず補完候補がセレクトされてしまうのを抑止) -- if vim.fn["coc#pum#info"]()["index"] >= 0 then -- return "(vimrc-coc-select-confirm)" -- end -- return "(vimrc-lexima-expand-cr)" -- end -- return "(vimrc-lexima-expand-cr)" -- end, -- } vim.cmd([[ function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~ '\s' endfunction " Insert when previous text is space, refresh completion if not. inoremap \ coc#pum#visible() ? coc#pum#next(1): \ pumvisible() ? "\": \ check_back_space() ? "\" : \ coc#refresh() inoremap \ coc#pum#visible() ? coc#pum#prev(1) : \ pumvisible() ? "\": \ "\" ]]) vim.g.coc_snippet_next = "" vim.g.coc_snippet_prev = "" -- coc の diagnostics の内容を QuiciFix に流し込む。 local function coc_diag_to_quickfix() local diags = vim.fn["CocAction"]("diagnosticList") ---@type any[] local entries = vim.tbl_map(function(diag) return { filename = diag.file, lnum = diag.lnum, end_lnum = diag.end_lnum, col = diag.col, end_col = diag.end_col, text = diag.message, type = diag.severity:sub(1, 1), } end, diags) vim.fn.setqflist(entries) vim.fn.setqflist({}, "a", { title = "Coc diagnostics" }) end create_cmd("CocQuickfix") { desc = [[coc.nvim の診断情報を QuiciFix に表示する]], function() coc_diag_to_quickfix() vim.cmd.cwindow() end, } ---diagnostics のある位置にジャンプする。ただし種類に応じて優先順位を付ける。 ---つまり、エラーがあればまずエラーにジャンプする。 ---エラーがなく警告があれば、警告にジャンプする。みたいな。 ---@param forward boolean local function jump_diag(forward) local action_name = logic.ifexpr(forward, "diagnosticNext", "diagnosticPrevious") motion_autoselect { function() vim.fn.CocAction(action_name, "error") end, function() vim.fn.CocAction(action_name, "warning") end, function() vim.fn.CocAction(action_name, "information") end, function() vim.fn.CocAction(action_name, "hint") end, } end mapset.n(")") { desc = [[次の diagnostics の場所にうつる]], function() jump_diag(true) end, } mapset.n("(") { desc = [[前の diagnostics の場所にうつる]], function() jump_diag(false) end, } end, } plugins:push { "https://github.com/chomosuke/typst-preview.nvim", ft = "typst", -- version = "1.*", build = function() require("typst-preview").update() end, config = function() local function get_modeline() ---@type string local line = vim.fn.getline(1) if vim.startswith(line, "//!{") then return vim.json.decode(line:sub(4)) end if vim.startswith(line, "//! target:") then local _, _, file = line:find([[^//! target:%s*(%S+)$]]) return { target = file } end return {} end local function resolve_target() local modeline = get_modeline() if modeline.target == nil then return vim.fn.resolve(vim.fn.expand("%")) end return vim.fn.resolve(vim.fn.expand("%:h") .. "/" .. modeline.target) end require("typst-preview").setup { -- Setting this true will enable printing debug information with print() debug = true, -- Custom format string to open the output link provided with %s -- Example: open_cmd = 'firefox %s -P typst-preview --class typst-preview' open_cmd = [[open -a "Zen Browser" %s]], -- Setting this to 'always' will invert black and white in the preview -- Setting this to 'auto' will invert depending if the browser has enable -- dark mode -- Setting this to '{"rest": "