feat(linter): add file/filename template arguments for command
This commit is contained in:
+13
-3
@@ -36,7 +36,9 @@ M.__index = M
|
|||||||
---@field deprecated? string[]
|
---@field deprecated? string[]
|
||||||
|
|
||||||
---@class LinterConfig
|
---@class LinterConfig
|
||||||
---@field cmd string[]
|
---@field cmd string[] Command to run. The following keywords get replaces by the specified values:
|
||||||
|
--- * %file% - path to the current file
|
||||||
|
--- * %filename% - name of the current file
|
||||||
---@field stdin? boolean
|
---@field stdin? boolean
|
||||||
---@field stdout? boolean
|
---@field stdout? boolean
|
||||||
---@field stderr? boolean
|
---@field stderr? boolean
|
||||||
@@ -268,14 +270,22 @@ end
|
|||||||
function M:run(bufnr)
|
function M:run(bufnr)
|
||||||
local input
|
local input
|
||||||
|
|
||||||
-- TODO: add placeholder variables for when not using stdin
|
|
||||||
if self.config.stdin then
|
if self.config.stdin then
|
||||||
input = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
input = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cmd = self.config.cmd
|
||||||
|
local file = vim.fn.expand("%")
|
||||||
|
local filename = vim.fn.expand("%:t")
|
||||||
|
for i, arg in ipairs(cmd) do
|
||||||
|
arg = arg:gsub("%%file%%", file)
|
||||||
|
arg = arg:gsub("%%filename%%", filename)
|
||||||
|
cmd[i] = arg
|
||||||
|
end
|
||||||
|
|
||||||
local ok, resp = pcall(
|
local ok, resp = pcall(
|
||||||
vim.system,
|
vim.system,
|
||||||
self.config.cmd,
|
cmd,
|
||||||
{ stdin = input },
|
{ stdin = input },
|
||||||
---@param out vim.SystemCompleted
|
---@param out vim.SystemCompleted
|
||||||
vim.schedule_wrap(function(out)
|
vim.schedule_wrap(function(out)
|
||||||
|
|||||||
Reference in New Issue
Block a user