grace/dots
dotfiles/nix configs
git clone https://git.gae.moe/grace/dots
ddf0c79
vulcan
1---@brief 2--- 3--- https://github.com/Myriad-Dreamin/tinymist 4--- An integrated language service for Typst [taɪpst]. You can also call it "微霭" [wēi ǎi] in Chinese. 5--- 6--- Currently some of Tinymist's workspace commands are supported, namely: 7--- `LspTinymistExportSvg`, `LspTinymistExportPng`, `LspTinymistExportPdf 8--- `LspTinymistExportMarkdown`, `LspTinymistExportText`, `LspTinymistExportQuery`, 9--- `LspTinymistExportAnsiHighlight`, `LspTinymistGetServerInfo`, 10--- `LspTinymistGetDocumentTrace`, `LspTinymistGetWorkspaceLabels`, and 11--- `LspTinymistGetDocumentMetrics`. 12 13---@param command_name string 14---@param client vim.lsp.Client 15---@param bufnr integer 16---@return fun():nil run_tinymist_command, string cmd_name, string cmd_desc 17local function create_tinymist_command ( command_name , client , bufnr ) 18local export_type =command_name : match 'tinymist%.export(%w+)' 19local info_type =command_name : match 'tinymist%.(%w+)' 20if info_type and info_type : match '^get' then 21info_type =info_type : gsub ( '^get' , 'Get' ) 22end 23local cmd_display =export_type or info_type 24---@return nil 25local function run_tinymist_command () 26local arguments ={ vim . api . nvim_buf_get_name ( bufnr ) } 27local title_str =export_type and ( 'Export ' .. cmd_display ) or cmd_display 28---@type lsp.Handler 29local function handler ( err , res ) 30if err then 31return vim . notify ( err . code .. ': ' .. err . message , vim . log . levels . ERROR ) 32end 33-- If exporting, show the string result; else, show the table for inspection 34vim . notify ( export_type and res or vim . inspect ( res ), vim . log . levels . INFO ) 35end 36return client : exec_cmd ( { 37title =title_str , 38command =command_name , 39arguments =arguments , 40} , { bufnr =bufnr } , handler ) 41end 42-- Construct a readable command name/desc 43local cmd_name =export_type and ( 'TinymistExport' .. cmd_display ) or ( 'Tinymist' .. cmd_display ) ---@type string 44local cmd_desc =export_type and ( 'Export to ' .. cmd_display ) or ( 'Get ' .. cmd_display ) ---@type string 45return run_tinymist_command , cmd_name , cmd_desc 46end 47 48---@type vim.lsp.Config 49return { 50cmd ={ 'tinymist' } , 51filetypes ={ 'typst' } , 52root_markers ={ '.git' , '.jj' } , 53on_attach =function ( client , bufnr ) 54for _ , command in ipairs { 55'tinymist.exportSvg' , 56'tinymist.exportPng' , 57'tinymist.exportPdf' , 58-- 'tinymist.exportHtml', -- Use typst 0.13 59'tinymist.exportMarkdown' , 60'tinymist.exportText' , 61'tinymist.exportQuery' , 62'tinymist.exportAnsiHighlight' , 63'tinymist.getServerInfo' , 64'tinymist.getDocumentTrace' , 65'tinymist.getWorkspaceLabels' , 66'tinymist.getDocumentMetrics' , 67} do 68local cmd_func , cmd_name , cmd_desc =create_tinymist_command ( command , client , bufnr ) 69vim . api . nvim_buf_create_user_command ( bufnr , 'Lsp' .. cmd_name , cmd_func , { nargs =0 , desc =cmd_desc } ) 70end 71end , 72settings ={ 73[ "tinymist" ] ={ 74formatterMode ="typstyle" 75} 76} 77}