Skip to content

Commit f8b1f2f

Browse files
committed
fix: Failing test on earlier NeoVim versions
1 parent 9202716 commit f8b1f2f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lua/debugprint/init.lua

+17-2
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,29 @@ end
120120
---@return DebugprintFileTypeConfig?
121121
local get_filetype_config = function()
122122
local effective_filetypes = utils.get_effective_filetypes()
123+
local config = {}
124+
local found_config = false
123125

124126
for _, effective_filetype in ipairs(effective_filetypes) do
125127
if global_opts.filetypes[effective_filetype] ~= nil then
126-
return global_opts.filetypes[effective_filetype]
128+
found_config = true
129+
-- Combine all valid configs into the same object. This seems to
130+
-- make sense as an approach; the only case where I've found where
131+
-- this applies so far is ["bash", "sh"]. If this causes problems we
132+
-- may need to come up with something more sophisticated.
133+
config = vim.tbl_deep_extend(
134+
"keep",
135+
vim.deepcopy(global_opts.filetypes[effective_filetype]),
136+
config
137+
)
127138
end
128139
end
129140

130-
return nil
141+
if not found_config then
142+
return nil
143+
else
144+
return config
145+
end
131146
end
132147

133148
---@param opts DebugprintFunctionOptionsInternal

lua/debugprint/utils/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ M.get_effective_filetypes = function()
8888
:lang()
8989

9090
local filetypes = vim.treesitter.language.get_filetypes(treesitter_lang)
91+
-- The order in which filetypes are provided seems to be semi-random
92+
-- (esp on NeoVim 0.9.5) so we are sorting them to at least give some
93+
-- stability.
94+
table.sort(filetypes)
9195
assert(vim.tbl_count(filetypes) > 0)
9296
return filetypes
9397
else

0 commit comments

Comments
 (0)