Skip to content

Commit

Permalink
refactor(nvim-lint): use new patch_func utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Sep 19, 2024
1 parent 895c28f commit ad0153f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lua/astrocommunity/lsp/nvim-lint/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return {
},
opts = {},
config = function(_, opts)
local lint = require "lint"
local lint, astrocore = require "lint", require "astrocore"

lint.linters_by_ft = opts.linters_by_ft or {}
for name, linter in pairs(opts.linters or {}) do
Expand All @@ -28,17 +28,16 @@ return {
end, linters)
end

local orig_resolve_linter_by_ft = lint._resolve_linter_by_ft
lint._resolve_linter_by_ft = function(...)
lint._resolve_linter_by_ft = astrocore.patch_func(lint._resolve_linter_by_ft, function(orig, ...)
local ctx = { filename = vim.api.nvim_buf_get_name(0) }
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h")

local linters = valid_linters(ctx, orig_resolve_linter_by_ft(...))
local linters = valid_linters(ctx, orig(...))
if not linters[1] then linters = valid_linters(ctx, lint.linters_by_ft["_"]) end -- fallback
require("astrocore").list_insert_unique(linters, valid_linters(ctx, lint.linters_by_ft["*"])) -- global
astrocore.list_insert_unique(linters, valid_linters(ctx, lint.linters_by_ft["*"])) -- global

return linters
end
end)

lint.try_lint() -- start linter immediately
local timer = vim.loop.new_timer()
Expand Down

0 comments on commit ad0153f

Please sign in to comment.