neovim

Personal neovim configuration files
git clone git://gtms.dev:neovim
Log | Files | Refs

commit d4099522f64492f1321a26622dce0a1e5ef7c383
parent 10dd0cefae3c744f90de2e0861d5a55c8adb3b82
Author: Tomas Nemec <nemi@skaut.cz>
Date:   Mon,  6 Mar 2023 08:46:41 +0100

update

Diffstat:
Mplugin/trun.lua | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 78 insertions(+), 17 deletions(-)

diff --git a/plugin/trun.lua b/plugin/trun.lua @@ -24,13 +24,14 @@ local function trun_list() return truns end --- add trun to quickfix list +local diag_ns = vim.api.nvim_create_namespace('trun_diag') + +-- return lines that can be added to quickfix list -- it needs to have its tempfile for output -local function trun_to_qf(name) +local function trun_to_qf_list(name) if not name then return end - vim.fn.setqflist({}, 'r') -- Depends on `trun-status` viz->tools/trun-status.lua local handle = io.popen('trun-status ' .. name) local o = {} @@ -48,7 +49,13 @@ local function trun_to_qf(name) local errorfile = o[2] if errorfile then local package_name = require('tms.ft.dart.package').package_name() + if not package_name then + return + end local packages_paths = require('tms.ft.dart.package').packages() + if not packages_paths then + return + end local errfile = io.open(errorfile, 'r') local lines = {} if not errfile then @@ -65,7 +72,7 @@ local function trun_to_qf(name) return package_root .. '/' .. '.dart_tool/build/generated/' .. package .. '/lib/' .. path end) line = string.gsub(line, 'asset:(.-)/(.-):', function(package, path) - local root = packages_paths[package].lib + local root = packages_paths[package].root return root .. '/' .. path end) line = string.gsub(line, '\'package:(.-)/(.-)\'', function(package, path) @@ -89,37 +96,91 @@ local function trun_to_qf(name) [[%-G%.%#]], } - vim.fn.setqflist({}, ' ', { lines = lines, efm = table.concat(efm, ',') }) - if #vim.fn.getqflist() > 0 then - vim.cmd.copen() - else - vim.notify('no errors found', vim.log.levels.INFO) + local qf_items = vim.fn.getqflist({ lines = lines, efm = table.concat(efm, ',') }) + + -- normalize template location + for _, item in pairs(qf_items.items) do + local lines = vim.api.nvim_buf_get_lines(item.bufnr, 0, -1, false) + for line_num, line in ipairs(lines) do + -- template inside annotation + if string.find(line, [[template:]]) then + item.lnum = item.lnum + line_num + end + end end + + return qf_items else vim.notify('Trun for "' .. name .. '" does not have tmp file', vim.log.levels.INFO) return end end +local function open_diag(qf_items) + local per_buf = {} + for _, item in pairs(qf_items.items) do + per_buf[item.bufnr] = per_buf[item.bufnr] or {} + table.insert(per_buf[item.bufnr], item) + end + + for bufnr, items in pairs(per_buf) do + vim.diagnostic.reset(diag_ns, bufnr) + local diag_items = vim.diagnostic.fromqflist(items) + vim.diagnostic.set(diag_ns, bufnr, diag_items, {}) + end +end + +local function open_qf(qf_items) + vim.fn.setqflist({}, ' ', { items = qf_items.items }) + if #vim.fn.getqflist() > 0 then + vim.cmd.copen() + else + vim.notify('no errors found', vim.log.levels.INFO) + end +end + local function select() local list = trun_list() if #list == 0 then vim.notify('no truns', vim.log.levels.INFO) end vim.ui.select(list, { prompt = 'Select trun:' }, function(trun) - trun_to_qf(trun) + local lines = trun_to_qf_list(trun) + open_qf(lines) end) end +local autocomplete = { + nargs = '?', + complete = function(ArgLead, CmdLine, CursorPos) + return trun_list() + end, +} + +vim.api.nvim_create_user_command('TrunDiagClear', function(opts) + vim.diagnostic.reset(diag_ns, nil) +end, autocomplete) + +vim.api.nvim_create_user_command('TrunDiag', function(opts) + if #opts.fargs == 0 then + select() + else + local qf_items = trun_to_qf_list(opts.fargs[1]) + if not qf_items then + return + end + open_diag(qf_items) + end +end, autocomplete) + vim.api.nvim_create_user_command('Trun', function(opts) if #opts.fargs == 0 then select() else - trun_to_qf(opts.fargs[1]) + local qf_items = trun_to_qf_list(opts.fargs[1]) + if not qf_items then + return + end + open_qf(qf_items) end -end, { - nargs = '?', - complete = function(ArgLead, CmdLine, CursorPos) - return trun_list() - end, -}) +end, autocomplete)