Skip to content

Commit 700458d

Browse files
committed
fix: move untested parser notification to the go buf attach callback
1 parent bdb9356 commit 700458d

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

‎lua/auto-fix-return/lib.lua‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,6 @@ function M.setup_user_commands()
6969
end
7070

7171
function M.enable_tree_cbs()
72-
local rev = M.get_parser_version()
73-
74-
if rev ~= nil and rev ~= TESTED_PARSER_REV then
75-
log(
76-
"AutoFixReturn: Current Go treesitter parser version '"
77-
.. rev
78-
.. "' is not tested with this plugin.\n"
79-
.. "If you encounter issues please upgrade your Go Treesitter parser to the tested version '"
80-
.. TESTED_PARSER_REV
81-
.. "'",
82-
vim.log.levels.WARN
83-
)
84-
end
85-
8672
for bufnr, _ in pairs(registered_ts_cbs_bufs) do
8773
registered_ts_cbs_bufs[bufnr] = true
8874
end
@@ -116,6 +102,21 @@ function M.register_buf_cbs(bufnr)
116102
return
117103
end
118104

105+
-- We should warn the users if they are using a parser version we do not know about
106+
-- but only once on the initial go buffer attach otherwise it is annoying
107+
local rev = M.get_parser_version()
108+
if rev ~= nil and rev ~= TESTED_PARSER_REV then
109+
log_once(
110+
"AutoFixReturn: Current Go treesitter parser version '"
111+
.. rev
112+
.. "' is not tested with this plugin.\n"
113+
.. "If you encounter issues please upgrade your Go Treesitter parser to the tested version '"
114+
.. TESTED_PARSER_REV
115+
.. "'",
116+
vim.log.levels.WARN
117+
)
118+
end
119+
119120
local tree = vim.treesitter.get_parser(bufnr)
120121

121122
if tree == nil then

‎lua/auto-fix-return/log.lua‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ function log(message, level)
1313
vim.notify(message, level)
1414
end
1515
end
16+
17+
---@param message string
18+
---@param level integer
19+
function log_once(message, level)
20+
if level >= _log_level then
21+
vim.notify_once(message, level)
22+
end
23+
end

0 commit comments

Comments
 (0)