petertriho / nvim-scrollbar

Extensible Neovim Scrollbar
MIT License
844 stars 18 forks source link

nvim-scrollbar does not show Search marks no matter the configs. #83

Open phongvcao opened 1 year ago

phongvcao commented 1 year ago

Describe the bug I cannot get nvim-scrollbar to show Search marks using hlslens no matter which way I configure it.

To Reproduce Here is my entire configuration:

lua <<EOF

local ensure_packer = function()
    local fn = vim.fn
    local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
    if fn.empty(fn.glob(install_path)) > 0 then
        fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
        vim.cmd [[packadd packer.nvim]]
        return true
    end
    return false
end

local packer_bootstrap = ensure_packer()

-- Setup packer
local use = require('packer').use
require('packer').startup(function()
    use 'wbthomason/packer.nvim' -- Package manager
    use {
        'kevinhwang91/nvim-hlslens',
        config = function()
            -- require('hlslens').setup() is not required
            require("scrollbar.handlers.search").setup()
        end,
    }
    use {
        "petertriho/nvim-scrollbar",
        requires = { "kevinhwang91/nvim-hlslens" },
        config = function()
            require("scrollbar").setup({
                set_highlights = false,
                handlers = {
                    cursor = true,
                    diagnostic = true,
                    gitsigns = false, -- Requires gitsigns
                    handle = true,
                    search = true, -- Requires hlslens
                    ale = false, -- Requires ALE
                },
            })

            require("scrollbar.handlers.search").setup()
            -- require("hlslens").setup({
            --     build_position_cb = function(plist, _, _, _)
            --         require("scrollbar.handlers.search").handler.show(plist.start_pos)
            --     end,
            -- })
            vim.cmd([[
            augroup scrollbar_search_hide
                autocmd!
                autocmd CmdlineLeave : lua require('scrollbar.handlers.search').handler.hide()
            augroup END
            ]])

        end,
    }

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

-- nvim-hlslens settings
require('hlslens').setup({
    override_lens = function(render, posList, nearest, idx, relIdx)
        local sfw = vim.v.searchforward == 1
        local indicator, text, chunks
        local absRelIdx = math.abs(relIdx)
        if absRelIdx > 1 then
            indicator = ('%d%s'):format(absRelIdx, sfw ~= (relIdx > 1) and ' N ▲' or ' n ▼')
        elseif absRelIdx == 1 then
            indicator = sfw ~= (relIdx == 1) and ' N ▲' or ' n ▼'
        else
            indicator = ''
        end

        local lnum, col = unpack(posList[idx])
        if nearest then
            local cnt = #posList
            if indicator ~= '' then
                text = (' %s %d / %d '):format(indicator, idx, cnt)
            else
                text = (' %d / %d '):format(idx, cnt)
            end
            chunks = {{' ', 'Ignore'}, {text, 'HlSearchLensNear'}}
        else
            local cnt = #posList
            text = (' %s %d / %d '):format(indicator, idx, cnt)
            chunks = {{' ', 'Ignore'}, {text, 'HlSearchLens'}}
        end
        render.setVirt(0, lnum - 1, col - 1, chunks, nearest)
    end,
})

local kopts = {noremap = true, silent = true}

vim.api.nvim_set_keymap('n', 'n',
    [[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', 'N',
    [[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)

vim.api.nvim_set_keymap('n', '<Leader>l', '<Cmd>noh<CR>', kopts)

-- -- nvim-scrollbar settings
-- require("scrollbar").setup()

-- require("scrollbar.handlers.search").setup()
--

EOF

Expected behavior Search marks should have been shown.

Screenshots Screenshot at Jan 26 11-26-01

Version Info (please complete the following information):

$ nvim --version
NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.8.2/share/nvim"

Run :checkhealth for more info
petertriho commented 1 year ago

Can you try set_highlights = true,?

phongvcao commented 1 year ago

yeah that still doesn't work.

phongvcao commented 1 year ago

@petertriho ok I finally got it to work with the following config. However, when I press key <CR> and then n or N of hlslens to navigate to the next / prev search results, the entire ScrollbarSearchHandle & ScrollbarSearch disappear (screenshots attached below):

lua <<EOF

local ensure_packer = function()
    local fn = vim.fn
    local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
    if fn.empty(fn.glob(install_path)) > 0 then
        fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
        vim.cmd [[packadd packer.nvim]]
        return true
    end
    return false
end

local packer_bootstrap = ensure_packer()

-- Setup packer
local use = require('packer').use
require('packer').startup(function()
    use 'wbthomason/packer.nvim' -- Package manager
    use {
        'kevinhwang91/nvim-hlslens',
        config = function()
            -- require('hlslens').setup() is not required
            require("scrollbar.handlers.search").setup({
                override_lens = function(render, posList, nearest, idx, relIdx)
                    local sfw = vim.v.searchforward == 1
                    local indicator, text, chunks
                    local absRelIdx = math.abs(relIdx)
                    if absRelIdx > 1 then
                        indicator = ('%d%s'):format(absRelIdx, sfw ~= (relIdx > 1) and ' N ▲' or ' n ▼')
                    elseif absRelIdx == 1 then
                        indicator = sfw ~= (relIdx == 1) and ' N ▲' or ' n ▼'
                    else
                        indicator = ''
                    end

                    local lnum, col = unpack(posList[idx])
                    if nearest then
                        local cnt = #posList
                        if indicator ~= '' then
                            text = (' %s %d / %d '):format(indicator, idx, cnt)
                        else
                            text = (' %d / %d '):format(idx, cnt)
                        end
                        chunks = {{' ', 'Ignore'}, {text, 'HlSearchLensNear'}}
                    else
                        local cnt = #posList
                        text = (' %s %d / %d '):format(indicator, idx, cnt)
                        chunks = {{' ', 'Ignore'}, {text, 'HlSearchLens'}}
                    end
                    render.setVirt(0, lnum - 1, col - 1, chunks, nearest)
                end,
                -- override_lens = function() end,
                build_position_cb = function(plist, _, _, _)
                    require("scrollbar.handlers.search").handler.show(plist.start_pos)
                end,
            })
        end,
    }
    use {
        "petertriho/nvim-scrollbar",
        requires = { "kevinhwang91/nvim-hlslens" },
        config = function()
            vim.cmd([[
            augroup scrollbar_search_hide
                autocmd!
                autocmd CmdlineLeave : lua require('scrollbar.handlers.search').handler.hide()
                autocmd BufEnter * :hi ScrollbarHandle ctermfg=1 guifg=#222222
                autocmd BufEnter * :hi ScrollbarSearch ctermfg=1 guifg=#222222
                autocmd BufEnter * :hi ScrollbarSearchHandle ctermfg=1 guifg=#222222
            augroup END
            ]])

        end,
    }

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

local kopts = {noremap = true, silent = true}

vim.api.nvim_set_keymap('n', 'n',
    [[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', 'N',
    [[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)

vim.api.nvim_set_keymap('n', '<Leader>l', '<Cmd>noh<CR>', kopts)

-- nvim-scrollbar settings
require("scrollbar").setup({
    set_highlights = true,
})

Screenshots:

Before Pressing <CR> and then n or N:

Screenshot at Jan 26 20-30-59

After Pressing <CR> and then n or N (it actually disappears sometimes right after <CR>):

Screenshot at Jan 26 20-37-47

petertriho commented 1 year ago

In this block

vim.cmd([[
            augroup scrollbar_search_hide
                autocmd!
                autocmd CmdlineLeave : lua require('scrollbar.handlers.search').handler.hide()
                autocmd BufEnter * :hi ScrollbarHandle ctermfg=1 guifg=#222222
                autocmd BufEnter * :hi ScrollbarSearch ctermfg=1 guifg=#222222
                autocmd BufEnter * :hi ScrollbarSearchHandle ctermfg=1 guifg=#222222
            augroup END
            ]])

Remove autocmd CmdlineLeave : lua require('scrollbar.handlers.search').handler.hide()

phongvcao commented 1 year ago

Ok I might have found a hint. So if I disable dense-analysis/ale it works. It looks like it only disappears when ALE is on. I tried disabling coc.nvim too but it didn't make a difference. I also tried disabling ale's virtualtext using let g:ale_virtualtext_cursor = 0 but it doesn't help. Here is my ale settings in .vimrc:

" ale settings
if exists('g:custom_ale_linters')
    let g:ale_linters = g:custom_ale_linters
endif
let g:ale_virtualenv_dir_names = []
let g:ale_cache_executable_check_failures = 1
let g:ale_completion_enabled = 0
let g:ale_completion_delay = 300
let g:ale_completion_max_suggestions = 0
let g:ale_lint_delay = 300
let g:ale_lint_on_text_changed = 'always'
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_update_tagstack = 0
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_set_highlights = 0
let g:ale_open_list = 0
if exists('g:custom_ale_sign_error')
  let g:ale_sign_error = g:custom_ale_sign_error
endif
if exists('g:custom_ale_sign_warning')
  let g:ale_sign_warning = g:custom_ale_sign_warning
endif
if exists('g:custom_ale_sign_info')
  let g:ale_sign_info = g:custom_ale_sign_info
endif
if exists('g:custom_ale_sign_style_error')
  let g:ale_sign_style_error = g:custom_ale_sign_style_error
endif
if exists('g:custom_ale_sign_style_warning')
  let g:ale_sign_style_warning = g:custom_ale_sign_style_warning
endif
" Set this if you want to.
" This can be useful if you are combining ALE with
" some other plugin which sets quickfix errors, etc.
let g:ale_keep_list_window_open = 0
let g:ale_use_global_executables = 1

Since nvim-scrollbar has ale integration, I'm guessing lots of people using nvim-scrollbar with ALE enabled? Can you share your ALE config here - I wonder what ALE config I did wrong that led to this.

phongvcao commented 1 year ago

ok even if I disabled all of my ALE configs, nvim-scrollbar still disappears as above. I also disabled all other Vim plugins & my entire .vimrc & init.lua except nvim-scrollbar and hlslens. Hence it looks like nvim-scrollbar's Search doesn't play well with default config of ALE?

AndreaHasani commented 1 year ago

It happens to me also, I'm not using ale (is that required?). lsp neovim + nvim-scrollbar + nvim-hlslens and search does not show.

TxHawks commented 1 year ago

Same here

vwlau commented 1 year ago

@AndreaHasani @TxHawks

I had the same problem and figured out how to turn on search marks (with virtualtext at the same time like in the demo gif).

Add the option handlers = { search = true }, to the example configuration in the readme. I think this handler is false by default.

use {
  "kevinhwang91/nvim-hlslens",
  config = function()
    -- require('hlslens').setup() is not required
    require("scrollbar.handlers.search").setup({
        handlers = { search = true },
    })
  end,
}