Skip to content

Commit

Permalink
feat(treesitter): enable treesitter for lines|blines|git_blame
Browse files Browse the repository at this point in the history
This commits also includes many other changes:
- `winopts.treesitter` can also be enabled (disabled by default)
  in grep/LSP pickers, but will be disabled in `live_grep` as ts
  highlights will override the regex highlighting
- When enabled `fzf_colors` will automatically set `hl,hl+` to
  `-1:reverse` which changes the background of the character,
  this is done to make the TS highlights more distingished
  NOTE1: `reverse` doesn't work as well with skim
  NOTE2: To disable set `winopts.treesitter.fzf_colors=false`
- Formatting changes for `lines,blines`, will match the formatting
  of `fzf.vim`, `treesitter` picker formatting slightly improved
- New highlights:
    + `FzfLuaBufId`: linked to `TabLine` by default, used to highlight
       the bufnr in `lines`
    + `FzfLuaBufLineNr`: linked to `LineNr` by default, used in
       `lines,blines,treesitter` for line numbers
- New option: `lines.show_bufname`, default value is `120`, will only
  display buffer name (filepath) if neovim's `columns > show_bufname`
- Separated `grep_curbuf|lgrep_curbuf` options to its own category
- Disabled with fzf-tmux profile as it does nothing (not a neovim
  buffer and thus can't enable the TS injector)
- Fixed Telescope profile gutter color (transparent)
- Highlights picker fuzzy matching colors set to "-1:reverse"
  • Loading branch information
ibhagwan committed Dec 14, 2024
1 parent 2b35807 commit 17da908
Show file tree
Hide file tree
Showing 15 changed files with 1,549 additions and 280 deletions.
20 changes: 16 additions & 4 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,25 +554,37 @@ Interactive headers description highlight group, e.g. `<ctrl-g> to Disable .giti

Type: `string`, Default: `FzfLuaPathLineNr`

Highlight group for the line part of paths, e.g. `file:<line>:<col>:`, used in pickers such as `buffers`, `lines`, `quickfix`, `lsp`, `diagnostics`, etc.
Highlight group for the line part of paths, e.g. `file:<line>:<col>:`, used in pickers such as `buffers`, `quickfix`, `lsp`, `diagnostics`, etc.

#### globals.hls.path_colnr

Type: `string`, Default: `FzfLuaPathColNr`

Highlight group for the column part of paths, e.g. `file:<line>:<col>:`, used in pickers such as `buffers`, `lines`, `quickfix`, `lsp`, `diagnostics`, etc.
Highlight group for the column part of paths, e.g. `file:<line>:<col>:`, used in pickers such as `buffers`, `quickfix`, `lsp`, `diagnostics`, etc.

#### globals.hls.buf_name

Type: `string`, Default: `FzfLuaBufName`

Highlight group for buffer name in `lines`.
Highlight group for buffer name (filepath) in `lines`.

#### globals.hls.buf_id

Type: `string`, Default: `FzfLuaBufId`

Highlight group for buffer id (number) in `lines`.

#### globals.hls.buf_nr

Type: `string`, Default: `FzfLuaBufNr`

Highlight group for buffer number in buffer type pickers, i.e. `buffers`, `tabs`, `lines`.
Highlight group for buffer number in `buffers`, `tabs`.

#### globals.hls.buf_linenr

Type: `string`, Default: `FzfLuaBufLineNr`

Highlight group for buffer line number in `lines`, `blines` and `treesitter`.

#### globals.hls.buf_flag_cur

Expand Down
58 changes: 24 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@ require'fzf-lua'.setup {
-- title = "Title",
-- title_pos = "center", -- 'left', 'center' or 'right'
fullscreen = false, -- start fullscreen?
-- enable treesitter highlighting for the main fzf window will only have
-- effect when grep like results are present, i.e. "file:line:col:text"
-- due to highlight color collisions will also override `fzf_colors`
-- set `fzf_colors=false` or `fzf_colors.hl=...` to override
treesitter = {
enable = false,
fzf_colors = { ["hl"] = "-1:reverse", ["hl+"] = "-1:reverse" }
},
preview = {
-- default = 'bat', -- override the default previewer?
-- default uses the 'builtin' previewer
Expand Down Expand Up @@ -1106,45 +1114,25 @@ require'fzf-lua'.setup {
["--with-nth"] = '2..',
},
},
-- `blines` has the same defaults as `lines` aside from prompt and `show_bufname`
lines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'Lines❯ ',
file_icons = true,
show_bufname = true, -- display buffer name
show_unloaded = true, -- show unloaded buffers
show_unlisted = false, -- exclude 'help' buffers
no_term_buffers = true, -- exclude 'term' buffers
sort_lastused = true, -- sort by most recent
winopts = { treesitter = true }, -- enable TS highlights
fzf_opts = {
-- do not include bufnr in fuzzy matching
-- tiebreak by line no.
["--delimiter"] = "[\\]:]",
["--nth"] = '2..',
["--tiebreak"] = 'index',
["--tabstop"] = "1",
},
-- actions inherit from 'actions.files' and merge
actions = {
["enter"] = actions.buf_edit_or_qf,
["alt-q"] = actions.buf_sel_to_qf,
["alt-l"] = actions.buf_sel_to_ll
},
},
blines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'BLines❯ ',
show_unlisted = true, -- include 'help' buffers
no_term_buffers = false, -- include 'term' buffers
-- start = "cursor" -- start display from cursor?
fzf_opts = {
-- hide filename, tiebreak by line no.
["--delimiter"] = "[:]",
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
["--multi"] = true,
["--delimiter"] = "[\t]",
["--tabstop"] = "1",
},
-- actions inherit from 'actions.files' and merge
actions = {
["enter"] = actions.buf_edit_or_qf,
["alt-q"] = actions.buf_sel_to_qf,
["alt-l"] = actions.buf_sel_to_ll
["--tiebreak"] = "index",
["--with-nth"] = "2..",
["--nth"] = "4..",
},
},
tags = {
Expand Down Expand Up @@ -1418,10 +1406,12 @@ temporarily overridden by its corresponding `winopts` option:
|FzfLuaHelpBorder |FzfLuaBorder |`hls.help_border` |Help win border|
|FzfLuaHeaderBind |*BlanchedAlmond |`hls.header_bind` |Header keybind|
|FzfLuaHeaderText |*Brown1 |`hls.header_text` |Header text|
|FzfLuaPathColNr |*CadetBlue1 |`hls.path_colnr` |Path col nr (`lines,qf,lsp,diag`)|
|FzfLuaPathLineNr |*LightGreen |`hls.path_linenr` |Path line nr (`lines,qf,lsp,diag`)|
|FzfLuaBufName |*LightMagenta |`hls.buf_name` |Buffer name (`lines`)|
|FzfLuaBufNr |*BlanchedAlmond |`hls.buf_nr` |Buffer number (all buffers)|
|FzfLuaPathColNr |*CadetBlue1 |`hls.path_colnr` |Path col nr (`qf,lsp,diag`)|
|FzfLuaPathLineNr |*LightGreen |`hls.path_linenr` |Path line nr (`qf,lsp,diag`)|
|FzfLuaBufName |Directory |`hls.buf_name` |Buffer name (`lines`)|
|FzfLuaBufId |TabLine |`hls.buf_id` |Buffer ID (`lines`)|
|FzfLuaBufNr |*BlanchedAlmond |`hls.buf_nr` |Buffer number (`buffers,tabs`)|
|FzfLuaBufLineNr |LineNr |`hls.buf_linenr` |Buffer line nr (`lines,blines`)|
|FzfLuaBufFlagCur |*Brown1 |`hls.buf_flag_cur` |Buffer line (`buffers`)|
|FzfLuaBufFlagAlt |*CadetBlue1 |`hls.buf_flag_alt` |Buffer line (`buffers`)|
|FzfLuaTabTitle |*LightSkyBlue1 |`hls.tab_title` |Tab title (`tabs`)|
Expand Down
27 changes: 21 additions & 6 deletions doc/fzf-lua-opts.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 November 18
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 10

==============================================================================
Table of Contents *fzf-lua-opts-table-of-contents*
Expand Down Expand Up @@ -736,7 +736,7 @@ globals.hls.path_linenr *fzf-lua-opts-globals.hls.path_linenr*
Type: `string`, Default: `FzfLuaPathLineNr`

Highlight group for the line part of paths, e.g. `file:<line>:<col>:`, used in
pickers such as `buffers`, `lines`, `quickfix`, `lsp`, `diagnostics`, etc.
pickers such as `buffers`, `quickfix`, `lsp`, `diagnostics`, etc.



Expand All @@ -745,24 +745,39 @@ globals.hls.path_colnr *fzf-lua-opts-globals.hls.path_colnr*
Type: `string`, Default: `FzfLuaPathColNr`

Highlight group for the column part of paths, e.g. `file:<line>:<col>:`, used
in pickers such as `buffers`, `lines`, `quickfix`, `lsp`, `diagnostics`, etc.
in pickers such as `buffers`, `quickfix`, `lsp`, `diagnostics`, etc.



globals.hls.buf_name *fzf-lua-opts-globals.hls.buf_name*

Type: `string`, Default: `FzfLuaBufName`

Highlight group for buffer name in `lines`.
Highlight group for buffer name (filepath) in `lines`.



globals.hls.buf_id *fzf-lua-opts-globals.hls.buf_id*

Type: `string`, Default: `FzfLuaBufId`

Highlight group for buffer id (number) in `lines`.



globals.hls.buf_nr *fzf-lua-opts-globals.hls.buf_nr*

Type: `string`, Default: `FzfLuaBufNr`

Highlight group for buffer number in buffer type pickers, i.e. `buffers`,
`tabs`, `lines`.
Highlight group for buffer number in `buffers`, `tabs`.



globals.hls.buf_linenr *fzf-lua-opts-globals.hls.buf_linenr*

Type: `string`, Default: `FzfLuaBufLineNr`

Highlight group for buffer line number in `lines`, `blines` and `treesitter`.



Expand Down
39 changes: 37 additions & 2 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,53 @@ function M.normalize_opts(opts, globals, __resume_key)
-- merge with provider defaults from globals (defaults + setup options)
opts = vim.tbl_deep_extend("keep", opts, utils.tbl_deep_clone(globals))

-- Running a command and setting `treesitter` sub-values will imply
-- `enable=true`, e.g:
-- `:FzfLua blines winopts.treesitter.fzf_colors=false`
-- `:FzfLua blines winopts.treesitter.fzf_colors={hl="-1:underline"}`
if opts.winopts
and type(opts.winopts.treesitter) == "table"
and opts.winopts.treesitter.enable ~= false
then
opts.winopts.treesitter.enable = true
end

-- Merge required tables from globals
for _, k in ipairs({
"winopts", "keymap", "fzf_opts", "fzf_tmux_opts", "hls"
"winopts", "keymap", "fzf_opts", "fzf_colors", "fzf_tmux_opts", "hls"
}) do
opts[k] = vim.tbl_deep_extend("keep",
-- must clone or map will be saved as reference
-- and then overwritten if found in 'backward_compat'
type(opts[k]) == "function" and opts[k]() or opts[k] or {},
type(M.globals[k]) == "function" and M.globals[k]() or
type(M.globals[k]) == "function" and M.globals[k](opts) or
type(M.globals[k]) == "table" and utils.tbl_deep_clone(M.globals[k]) or {})
end

-- Adjust main fzf window treesitter settings
-- Disabled unless the picker is TS enabled with `_treesitter=true`
-- Unless `enable=false` is specifically set `true` is asssumed
if not opts._treesitter then opts.winopts.treesitter = nil end
if opts.winopts.treesitter and type(opts.winopts.treesitter) ~= "table" then
opts.winopts.treesitter = {}
end
if not opts.winopts.treesitter or opts.winopts.treesitter.enable == false then
opts.winopts.treesitter = nil
else
assert(type(opts.winopts.treesitter) == "table")
-- Unless the caller specifically disables `fzf_colors` fuzzy matching
-- colors "hl,hl+" will be set to "-1:reverse" which sets the background
-- color for matches to the corresponding original foreground color
-- NOTE: `fzf_colors` inherited from `defaults.winopts.treesitter`
if opts.winopts.treesitter.fzf_colors ~= false then
opts.fzf_colors = vim.tbl_deep_extend("force",
opts.fzf_colors or {},
M.defaults.winopts.treesitter.fzf_colors,
type(opts.winopts.treesitter.fzf_colors) == "table"
and opts.winopts.treesitter.fzf_colors or {})
end
end

-- backward compat: no-value flags should be set to `true`, in the past these
-- would be set to an empty string which would now translate into a shell escaped
-- string as we automatically shell escape all fzf_opts
Expand Down
12 changes: 0 additions & 12 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ end
-- Create fzf --color arguments from a table of vim highlight groups.
M.create_fzf_colors = function(opts)
local colors = opts and opts.fzf_colors
if type(colors) == "function" then
colors = colors(opts)
end
-- auto create `fzf_colors` based on Neovim's current colorscheme
if colors == true then
colors = {
Expand Down Expand Up @@ -622,15 +619,6 @@ end
---@param opts table
---@return string[]
M.build_fzf_cli = function(opts, fzf_win)
opts.fzf_opts = vim.tbl_extend("force", config.globals.fzf_opts, opts.fzf_opts or {})
-- copy/merge from globals
for _, o in ipairs({ "fzf_colors", "keymap" }) do
if opts[o] == nil then
opts[o] = config.globals[o]
elseif type(opts[o]) == "table" and type(config.globals[o]) == "table" then
opts[o] = vim.tbl_deep_extend("keep", opts[o], config.globals[o])
end
end
-- below options can be specified directly in opts and will be
-- prioritized: opts.<name> is prioritized over fzf_opts["--name"]
for _, flag in ipairs({ "query", "prompt", "header", "preview" }) do
Expand Down
Loading

0 comments on commit 17da908

Please sign in to comment.