ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.22k stars 144 forks source link

Syntax highlighting doesn't work in files preview for custom file types. #803

Closed ievgenii-shepeliuk closed 1 year ago

ievgenii-shepeliuk commented 1 year ago

Info

Description

I am using following auto command to want to enable SQL syntax highlighting for files with extension *.ksql

autocmd BufEnter *.ksql setlocal filetype=sql

When I open such files - syntax highlighting works, but when I execute :FzfLua files - the preview window doesn't highlight the syntax for *.ksql files.

Can you please help ?

ibhagwan commented 1 year ago

The preview buffer has autocmds disabled and the treesitter highlighting is performed manually, this has many reasons one of which to disable LSP analysis on the preview buffer as well as other potential collisions with other plug-in autocmds - this means your autocmd doesn’t do anything in the context of the preview buffer.

The filetype is determined by a call to vim.filetype.match which doesn’t know about your override:

https://github.com/ibhagwan/fzf-lua/blob/c3c71df6ffba3cc90335c538fad81aa7a0182e57/lua/fzf-lua/previewer/builtin.lua#L774-L775

The only solution I can offer is a manual config override within Fzf-lua, something like:

ext_override = { ['ksql'] = 'sql', … }

If this is something you can live with I can implement if pretty quickly.

ibhagwan commented 1 year ago

https://github.com/ibhagwan/fzf-lua/commit/4553b0aa5bd6265117ad063045ba04e55fb42761

@ievgenii-shepeliuk, update to the latest commit and add the below to your setup:

require("fzf-lua").setup({
  previewers = {
    builtin = {
      ext_ft_override = {
        ["ksql"] = "sql",
        -- other filetype overrides
      }
    }
  }
})
ievgenii-shepeliuk commented 1 year ago

Hello @ibhagwan

It's working now, thank you.