From 771b84141fedc0ca221992e287a86eaa929e8bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:22:35 +0100 Subject: [PATCH] plugin: linter: Use new `onBufferOptionChanged` callback --- runtime/plugins/linter/linter.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/runtime/plugins/linter/linter.lua b/runtime/plugins/linter/linter.lua index 0ce4b2b0..d5bd9541 100644 --- a/runtime/plugins/linter/linter.lua +++ b/runtime/plugins/linter/linter.lua @@ -141,6 +141,32 @@ function onSave(bp) return true end +function onBufferOptionChanged(buf, option, old, new) + if option == "filetype" then + if old ~= new then + for k, v in pairs(linters) do + local ftmatch = old == v.filetype + if v.domatch then + ftmatch = string.match(old, v.filetype) + end + + local hasOS = contains(v.os, runtime.GOOS) + if not hasOS and v.whitelist then + ftmatch = false + end + if hasOS and not v.whitelist then + ftmatch = false + end + + if ftmatch then + buf:ClearMessages(k) + end + end + end + end + return true +end + function lint(buf, linter, cmd, args, errorformat, loff, coff, callback) buf:ClearMessages(linter)