razak17 / tailwind-fold.nvim

Neovim plugin to conceal long class attributes.
62 stars 7 forks source link

Non-predefined config ft values cause error on start #11

Closed benallen-dev closed 3 months ago

benallen-dev commented 3 months ago

I use tailwind-fold mostly for projects written with Templ in Go. I noticed that after updating I got an error when starting Neovim:

Error detected while processing BufEnter Autocommands for "*":
packer.nvim: Error running config for tailwind-fold.nvim: ...cker/start/tailwind-fold.nvim/lua
/tailwind-fold/init.lua:33: attempt to concatenate local 'extension' (a nil value)

This happened because I had added "templ" to my config, and the code in init.lua does this:

    local ft_to_pattern = {}
    for _, ft in ipairs(config.options.ft) do
        local extension = config.filetype_to_extension[ft]
        table.insert(ft_to_pattern, "*." .. extension)
    end

where config.filetype_to_extension[ft] is nil for unknown values of ft.

The quick-fix I did locally was to make templ a known value, but an alternative could be doing this

    local ft_to_pattern = {}
    for _, ft in ipairs(config.options.ft) do
        local extension = config.filetype_to_extension[ft] or ft
        table.insert(ft_to_pattern, "*." .. extension)
    end
benallen-dev commented 3 months ago

Issue has been resolved after merging PR, thanks!