allow to config when will the fuzzy finder prompt to be shown

pull/143/head
ray-x 2 years ago
parent f9af69e4bf
commit 4144024068

@ -564,9 +564,15 @@ You can load a different font size for floating win
![multigrid2](https://user-images.githubusercontent.com/1681295/139196378-bf69ade9-c916-42a9-a91f-cccb39b9c4eb.jpg) ![multigrid2](https://user-images.githubusercontent.com/1681295/139196378-bf69ade9-c916-42a9-a91f-cccb39b9c4eb.jpg)
### Document Symbol ### Document Symbol and navigate through the list
![document symbol](https://github.com/ray-x/files/blob/master/img/navigator/doc_symbol.gif?raw=true) ![doc_symbol_and_navigate](https://user-images.githubusercontent.com/1681295/148642747-1870b1a4-67c2-4a0d-8a41-d462ecdc663e.gif)
The key binding to navigate in the list.
- up and down key
- `<Ctrl-f/b>` for page up and down
- number key 1~9 go to the ith item.
- If there are loads of results, would be good to use fzy search prompt to filter out the result you are interested.
### Workspace Symbol ### Workspace Symbol
@ -667,9 +673,11 @@ Codelens for C++/ccls. Symbol reference
### VS-code style folding with treesitter ### VS-code style folding with treesitter
#### folding function #### folding function
![image](https://user-images.githubusercontent.com/1681295/148491596-6cd6c507-c157-4536-b8c4-dc969436763a.png) ![image](https://user-images.githubusercontent.com/1681295/148491596-6cd6c507-c157-4536-b8c4-dc969436763a.png)
#### folding comments #### folding comments
![image](https://user-images.githubusercontent.com/1681295/148491845-5ffb18ea-f05d-4229-aec3-aa635b3de814.png) ![image](https://user-images.githubusercontent.com/1681295/148491845-5ffb18ea-f05d-4229-aec3-aa635b3de814.png)
# Debug the plugin # Debug the plugin

@ -20,6 +20,8 @@ _NgConfigValues = {
external = nil, -- true: enable for goneovim multigrid otherwise false external = nil, -- true: enable for goneovim multigrid otherwise false
border = 'single', -- border style, can be one of 'none', 'single', 'double', "shadow" border = 'single', -- border style, can be one of 'none', 'single', 'double', "shadow"
lines_show_prompt = 10, -- when the result list items number more than lines_show_prompt,
-- fuzzy finder prompt will be shown
combined_attach = 'both', -- both: use both customized attach and navigator default attach, mine: only use my attach defined in vimrc combined_attach = 'both', -- both: use both customized attach and navigator default attach, mine: only use my attach defined in vimrc
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
-- your on_attach will be called at end of navigator on_attach -- your on_attach will be called at end of navigator on_attach

@ -1,11 +1,10 @@
local log = require"navigator.util".log
-- NOTE: this file is a modified version of fold.lua from nvim-treesitter -- NOTE: this file is a modified version of fold.lua from nvim-treesitter
local log = require('navigator.util').log
local api = vim.api local api = vim.api
local tsutils = require "nvim-treesitter.ts_utils" local tsutils = require('nvim-treesitter.ts_utils')
local query = require "nvim-treesitter.query" local query = require('nvim-treesitter.query')
local parsers = require "nvim-treesitter.parsers" local parsers = require('nvim-treesitter.parsers')
local get_node_at_line = require('navigator.treesitter').get_node_at_line local get_node_at_line = require('navigator.treesitter').get_node_at_line
local M = {} local M = {}
@ -21,27 +20,27 @@ function _G.custom_fold_text()
local line = vim.fn.getline(vim.v.foldstart) local line = vim.fn.getline(vim.v.foldstart)
local line_count = vim.v.foldend - vim.v.foldstart + 1 local line_count = vim.v.foldend - vim.v.foldstart + 1
-- log("" .. line .. " // " .. line_count .. " lines") -- log("" .. line .. " // " .. line_count .. " lines")
return "" .. line .. ": " .. line_count .. " lines" return '' .. line .. ': ' .. line_count .. ' lines'
end end
vim.opt.foldtext = custom_fold_text() vim.opt.foldtext = custom_fold_text()
vim.opt.fillchars = {eob = "-", fold = " "} vim.opt.fillchars = { eob = '-', fold = ' ' }
vim.opt.viewoptions:remove("options") vim.opt.viewoptions:remove('options')
function M.setup_fold() function M.setup_fold()
if not parsers.has_parser() then if not parsers.has_parser() then
vim.notify("treesitter folding not enabled for current file", vim.lsp.log_levels.WARN) vim.notify('treesitter folding not enabled for current file', vim.lsp.log_levels.WARN)
return return
end end
log("setup treesitter folding") log('setup treesitter folding')
api.nvim_command("augroup FoldingCommand") api.nvim_command('augroup FoldingCommand')
api.nvim_command("autocmd! * <buffer>") api.nvim_command('autocmd! * <buffer>')
api.nvim_command("augroup end") api.nvim_command('augroup end')
vim.opt.foldtext = 'v:lua.custom_fold_text()' vim.opt.foldtext = 'v:lua.custom_fold_text()'
vim.opt.fillchars = {eob = "-", fold = " "} vim.opt.fillchars = { eob = '-', fold = ' ' }
vim.opt.viewoptions:remove("options") vim.opt.viewoptions:remove('options')
local current_window = api.nvim_get_current_win() local current_window = api.nvim_get_current_win()
api.nvim_win_set_option(current_window, 'foldmethod', 'expr') api.nvim_win_set_option(current_window, 'foldmethod', 'expr')
@ -51,7 +50,7 @@ end
-- This is cached on buf tick to avoid computing that multiple times -- This is cached on buf tick to avoid computing that multiple times
-- Especially not for every line in the file when `zx` is hit -- Especially not for every line in the file when `zx` is hit
local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr) local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
local max_fold_level = api.nvim_win_get_option(0, "foldnestmax") local max_fold_level = api.nvim_win_get_option(0, 'foldnestmax')
local trim_level = function(level) local trim_level = function(level)
if level > max_fold_level then if level > max_fold_level then
return max_fold_level return max_fold_level
@ -62,15 +61,15 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
local parser = parsers.get_parser(bufnr) local parser = parsers.get_parser(bufnr)
if not parser then if not parser then
warn("treesitter parser not loaded") warn('treesitter parser not loaded')
return {} return {}
end end
local matches = query.get_capture_matches_recursively(bufnr, function(lang) local matches = query.get_capture_matches_recursively(bufnr, function(lang)
if query.has_folds(lang) then if query.has_folds(lang) then
return "@fold", "folds" return '@fold', 'folds'
elseif query.has_locals(lang) then elseif query.has_locals(lang) then
return "@scope", "locals" return '@scope', 'locals'
end end
end) end)
@ -81,7 +80,7 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
local prev_start = -1 local prev_start = -1
local prev_stop = -1 local prev_stop = -1
local min_fold_lines = api.nvim_win_get_option(0, "foldminlines") local min_fold_lines = api.nvim_win_get_option(0, 'foldminlines')
for _, node in ipairs(matches) do for _, node in ipairs(matches) do
local start, _, stop, stop_col = node.node:range() local start, _, stop, stop_col = node.node:range()
@ -112,52 +111,57 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
local node, _ = get_node_at_line(lnum + 1) local node, _ = get_node_at_line(lnum + 1)
-- log(lnum, node:type()) -- log(lnum, node:type())
local comment = node:type() == 'comment' local comment = node:type() == 'comment'
local last_trimmed_level = trim_level(current_level) local last_trimmed_level = trim_level(current_level)
current_level = current_level + (start_counts[lnum] or 0) current_level = current_level + (start_counts[lnum] or 0)
local trimmed_level = trim_level(current_level) local trimmed_level = trim_level(current_level)
current_level = current_level - (stop_counts[lnum] or 0) current_level = current_level - (stop_counts[lnum] or 0)
local next_trimmed_level = trim_level(current_level) local next_trimmed_level = trim_level(current_level)
-- Determine if it's the start/end of a fold
-- NB: vim's fold-expr interface does not have a mechanism to indicate that
-- two (or more) folds start at this line, so it cannot distinguish between
-- ( \n ( \n )) \n (( \n ) \n )
-- versus
-- ( \n ( \n ) \n ( \n ) \n )
-- If it did have such a mechansim, (trimmed_level - last_trimmed_level)
-- would be the correct number of starts to pass on.
if comment then if comment then
if lnum == 0 or levels[lnum] == tostring(trimmed_level) then if lnum == 0 or levels[lnum] == tostring(trimmed_level) then
levels[lnum + 1] = ">" .. tostring(trimmed_level + 1) -- allow comment fold independtly levels[lnum + 1] = '>' .. tostring(trimmed_level + 1) -- allow comment fold independtly
else else
levels[lnum + 1] = tostring(trimmed_level + 1) -- allow comment fold independtly levels[lnum + 1] = tostring(trimmed_level + 1) -- allow comment fold independtly
end end
else else
-- Determine if it's the start/end of a fold
-- NB: vim's fold-expr interface does not have a mechanism to indicate that
-- two (or more) folds start at this line, so it cannot distinguish between
-- ( \n ( \n )) \n (( \n ) \n )
-- versus
-- ( \n ( \n ) \n ( \n ) \n )
-- If it did have such a mechansim, (trimmed_level - last_trimmed_level)
-- would be the correct number of starts to pass on.
levels[lnum + 1] = tostring(trimmed_level)
if trimmed_level - last_trimmed_level > 0 then if trimmed_level - last_trimmed_level > 0 then
levels[lnum + 1] = tostring(trimmed_level - 1) -- hack levels[lnum + 1] = tostring(trimmed_level) -- hack
levels[lnum + 2] = ">" .. tostring(trimmed_level) -- dirty hack levels[lnum + 2] = '>' .. tostring(trimmed_level + 1) -- dirty hack
elseif trimmed_level - next_trimmed_level > 0 then elseif trimmed_level - next_trimmed_level > 0 then
-- Ending marks tend to confuse vim more than it helps, particularly when -- Ending marks tend to confuse vim more than it helps, particularly when
-- the fold level changes by at least 2; we can uncomment this if -- the fold level changes by at least 2; we can uncomment this if
-- vim's behavior gets fixed. -- vim's behavior gets fixed.
if lnum ~= 0 then if lnum ~= 0 then
levels[lnum] = "<" .. tostring(trimmed_level) levels[lnum] = tostring(trimmed_level + 1)
end end
levels[lnum + 1] = tostring(trimmed_level - 1) levels[lnum + 1] = tostring(trimmed_level)
else else
if levels[lnum + 1] == nil then -- if levels[lnum + 1] == nil then
levels[lnum + 1] = tostring(trimmed_level) levels[lnum + 1] = tostring(trimmed_level + 1)
end -- end
end end
end end
end end
-- log(levels) log(levels)
return levels return levels
end) end)
function M.get_fold_indic(lnum) function M.get_fold_indic(lnum)
if not parsers.has_parser() or not lnum then
return '0'
end
local buf = api.nvim_get_current_buf() local buf = api.nvim_get_current_buf()
local shown = false local shown = false
for i = 1, vim.fn.tabpagenr('$') do for i = 1, vim.fn.tabpagenr('$') do
@ -168,12 +172,12 @@ function M.get_fold_indic(lnum)
end end
end end
if not shown then if not shown then
return "0" return '0'
end end
local levels = folds_levels(buf) or {} local levels = folds_levels(buf) or {}
-- log(lnum, levels[lnum]) -- TODO: comment it out in master -- log(lnum, levels[lnum]) -- TODO: comment it out in master
return levels[lnum] or "0" return levels[lnum] or '0'
end end
return M return M

@ -42,6 +42,10 @@ function M.new_list_view(opts)
end end
opts.transparency = _NgConfigValues.transparency opts.transparency = _NgConfigValues.transparency
if #items >= _NgConfigValues.lines_show_prompt then
opts.prompt = true
end
opts.external = _NgConfigValues.external opts.external = _NgConfigValues.external
opts.preview_lines_before = 3 opts.preview_lines_before = 3
log(opts) log(opts)

Loading…
Cancel
Save