refactor: correctness fixes, API modernization, and cleanup
This commit is contained in:
+47
-70
@@ -33,9 +33,9 @@ local util = require("util")
|
||||
--- * %filename% - name of the current file
|
||||
---@field cmd string[]
|
||||
--- Events that trigger the linter (default: TextChanged, TextChangedI)
|
||||
---@field events? string[]
|
||||
---@field events? vim.api.keyset.events[]
|
||||
--- Events that clear diagnostics
|
||||
---@field clear_events? string[]
|
||||
---@field clear_events? vim.api.keyset.events[]
|
||||
--- Pass buffer content via stdin (default: false)
|
||||
---@field stdin? boolean
|
||||
--- Read diagnostics from stdout (default: false)
|
||||
@@ -51,7 +51,7 @@ local util = require("util")
|
||||
--- Source name for diagnostics (default: command name)
|
||||
---@field source? string
|
||||
--- Debounce delay in ms (default: 100)
|
||||
---@field debounce? number
|
||||
---@field debounce? integer
|
||||
--- Configuration for JSON output parsing
|
||||
---@field json? ow.lsp.linter.JsonConfig
|
||||
--- Map diagnostic codes to tags
|
||||
@@ -68,9 +68,9 @@ local util = require("util")
|
||||
---@field hook? fun(self: ow.lsp.Linter, diagnostics: vim.Diagnostic[])
|
||||
|
||||
---@class ow.lsp.Linter
|
||||
---@field namespace number
|
||||
---@field augroup number
|
||||
---@field bufnr number
|
||||
---@field namespace integer
|
||||
---@field augroup integer
|
||||
---@field bufnr integer
|
||||
---@field config ow.lsp.linter.Config
|
||||
Linter = {}
|
||||
Linter.__index = Linter
|
||||
@@ -161,21 +161,21 @@ end
|
||||
---@param diag vim.Diagnostic
|
||||
function Linter:fix_indexing(diag)
|
||||
if not self.config.zero_idx_lnum then
|
||||
if diag.lnum then
|
||||
if diag.lnum and diag.lnum > 0 then
|
||||
diag.lnum = diag.lnum - 1
|
||||
end
|
||||
|
||||
if diag.end_lnum then
|
||||
if diag.end_lnum and diag.end_lnum > 0 then
|
||||
diag.end_lnum = diag.end_lnum - 1
|
||||
end
|
||||
end
|
||||
|
||||
if not self.config.zero_idx_col then
|
||||
if diag.col then
|
||||
if diag.col and diag.col > 0 then
|
||||
diag.col = diag.col - 1
|
||||
end
|
||||
|
||||
if diag.end_col then
|
||||
if diag.end_col and diag.end_col > 0 then
|
||||
diag.end_col = diag.end_col - 1
|
||||
end
|
||||
end
|
||||
@@ -236,68 +236,45 @@ end
|
||||
---@param config ow.lsp.linter.Config
|
||||
---@return boolean
|
||||
function Linter.validate(config)
|
||||
local ok, resp = pcall(vim.validate, {
|
||||
config = { config, "table" },
|
||||
})
|
||||
|
||||
if ok then
|
||||
ok, resp = pcall(vim.validate, {
|
||||
cmd = {
|
||||
config.cmd,
|
||||
function(t)
|
||||
return util.is_list(t, "string")
|
||||
end,
|
||||
"list of strings",
|
||||
},
|
||||
events = {
|
||||
config.events,
|
||||
function(t)
|
||||
return util.is_list(t, "string")
|
||||
end,
|
||||
true,
|
||||
"list of strings",
|
||||
},
|
||||
clear_events = {
|
||||
config.clear_events,
|
||||
function(t)
|
||||
return util.is_list(t, "string")
|
||||
end,
|
||||
true,
|
||||
"list of strings",
|
||||
},
|
||||
stdin = { config.stdin, "boolean", true },
|
||||
stdout = { config.stdout, "boolean", true },
|
||||
stderr = { config.stderr, "boolean", true },
|
||||
pattern = { config.pattern, "string", true },
|
||||
groups = {
|
||||
config.groups,
|
||||
function(t)
|
||||
return util.is_list(t, "string")
|
||||
end,
|
||||
true,
|
||||
"list of strings",
|
||||
},
|
||||
severity_map = {
|
||||
config.severity_map,
|
||||
function(t)
|
||||
return util.is_map(t, "string", "number")
|
||||
end,
|
||||
true,
|
||||
"map of string and number",
|
||||
},
|
||||
debounce = { config.debounce, "number", true },
|
||||
source = { config.source, "string", true },
|
||||
json = { config.json, "table", true },
|
||||
tags = { config.tags, "table", true },
|
||||
zero_idx_lnum = { config.zero_idx_lnum, "boolean", true },
|
||||
zero_idx_col = { config.zero_idx_col, "boolean", true },
|
||||
ignore_stderr = { config.ignore_stderr, "boolean", true },
|
||||
ignore_exit = { config.ignore_exit, "boolean", true },
|
||||
})
|
||||
local function list_of(ty)
|
||||
return function(t)
|
||||
return util.is_list(t, ty)
|
||||
end
|
||||
end
|
||||
|
||||
local ok, err = pcall(function()
|
||||
vim.validate("config", config, "table")
|
||||
vim.validate("cmd", config.cmd, list_of("string"), "list of strings")
|
||||
vim.validate(
|
||||
"events", config.events, list_of("string"), true, "list of strings"
|
||||
)
|
||||
vim.validate(
|
||||
"clear_events", config.clear_events, list_of("string"), true,
|
||||
"list of strings"
|
||||
)
|
||||
vim.validate("stdin", config.stdin, "boolean", true)
|
||||
vim.validate("stdout", config.stdout, "boolean", true)
|
||||
vim.validate("stderr", config.stderr, "boolean", true)
|
||||
vim.validate("pattern", config.pattern, "string", true)
|
||||
vim.validate(
|
||||
"groups", config.groups, list_of("string"), true, "list of strings"
|
||||
)
|
||||
vim.validate("severity_map", config.severity_map, function(t)
|
||||
return util.is_map(t, "string", "number")
|
||||
end, true, "map of string to number"
|
||||
)
|
||||
vim.validate("debounce", config.debounce, "number", true)
|
||||
vim.validate("source", config.source, "string", true)
|
||||
vim.validate("json", config.json, "table", true)
|
||||
vim.validate("tags", config.tags, "table", true)
|
||||
vim.validate("zero_idx_lnum", config.zero_idx_lnum, "boolean", true)
|
||||
vim.validate("zero_idx_col", config.zero_idx_col, "boolean", true)
|
||||
vim.validate("ignore_stderr", config.ignore_stderr, "boolean", true)
|
||||
vim.validate("ignore_exit", config.ignore_exit, "boolean", true)
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
log.error("Invalid config for linter: %s", resp)
|
||||
log.error("Invalid config for linter: %s", err)
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -452,7 +429,7 @@ function Linter.add(bufnr, config)
|
||||
buffer = linter.bufnr,
|
||||
callback = util.debounce(function()
|
||||
linter:run()
|
||||
end, linter.config.debounce),
|
||||
end, config.debounce),
|
||||
group = linter.augroup,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user