Shougo / ddu.vim

Dark deno-powered UI framework for Vim/NeoVim
MIT License
295 stars 24 forks source link

Filter ordering changed? #85

Closed dmfay closed 11 months ago

dmfay commented 11 months ago

Problems summary

I upgraded recently and noticed a behavior change with grep. I had configured converter_display_word and ddu-filter-fzf in order to filter on both the filename and the matched line. Now only the matched line is filtered.

I found a commit newly specifying that filters are applied matcher -> sorter -> converter, and adding logs in converter_display_word and ddu-filter-fzf confirmed this. filter-fzf logged first, then converter_display_word. So both the matcherKey and word for fzf only contain the matched line instead of "$filename: $matchedLine". How can I filter on both?

Environment Information

Provide a minimal init.vim/vimrc without plugin managers (Required!)

if has('vim_starting')
  let s:config_path = stdpath('cache')
  for s:repo in [
    \ 'vim-denops/denops.vim',
    \ 'Shougo/ddu.vim',
    \ 'Shougo/ddu-ui-ff',
    \ 'Shougo/ddu-kind-file',
    \ 'shun/ddu-source-rg',
    \ 'Shougo/ddu-filter-converter_display_word',
    \ 'yuki-yano/ddu-filter-fzf'
  \ ]
    let s:path = s:config_path . '/../dein/repos/github.com/' . s:repo
    let &g:rtp .= ',' . s:path
  endfor
endif

call ddu#custom#patch_global(#{
  \   ui: 'ff',
  \   uiParams: #{
  \     ff: #{
  \       startFilter: v:true,
  \       ignoreEmpty: v:false,
  \       autoResize: v:false,
  \       filterSplitDirection: 'botright',
  \       cursorPos: 0,
  \     }
  \   },
  \   kindOptions: #{
  \     file: #{
  \       defaultAction: 'open',
  \     },
  \   },
  \   filterParams: #{
  \     matcher_fzf: #{
  \       highlightMatched: 'Search',
  \     },
  \   },
  \   sources: [
  \     #{ name: 'rg', },
  \   ],
  \   sourceOptions: #{
  \     _: #{
  \       converters: [
  \         'converter_display_word',
  \       ],
  \       sorters: ['sorter_fzf'],
  \       matchers: ['matcher_fzf'],
  \     },
  \   },
  \   sourceParams: #{
  \     rg: #{
  \       args: ['--column', '--no-heading', '--smart-case', '--color', 'never'],
  \       highlights: #{path: 'Url'},
  \     },
  \   },
  \ })

autocmd FileType ddu-ff-filter call s:ddu_filter_my_settings()
function! s:ddu_filter_my_settings() abort
  inoremap <buffer> <CR>
    \ <Esc><Cmd>call ddu#ui#ff#do_action('itemAction')<CR>
  inoremap <buffer> <Esc>
    \ <Esc><Cmd>call ddu#ui#ff#do_action('quit')<CR>
  inoremap <buffer> <C-j>
    \ <Cmd>call ddu#ui#ff#execute(
    \ "call cursor(line('.')+1,0)<Bar>redraw")<CR>
  inoremap <buffer> <C-k>
    \ <Cmd>call ddu#ui#ff#execute(
    \ "call cursor(line('.')-1,0)<Bar>redraw")<CR>
endfunction

nnoremap <space>/
  \ :call ddu#start(#{
  \   sources: [#{name: 'rg', params: #{input: input('pattern-')}}],
  \ })<CR>

How to reproduce the problem from neovim/Vim startup (Required!)

  1. <space>/ to open grep prompt
  2. type search string and press enter
  3. try to filter results by filename; you will only match characters in the grep output

Screenshot (if possible)

1700668636

Before I upgraded, this fzf filter string types would have matched all results in types.ts first since that's the earliest matching text in $filename $matchedLine.

Shougo commented 11 months ago

Your configuration is wrong. The filter order is not changed.

If you want to change match, you need to change matchers like this. converter_display_word must be executed before matcher_fzf.

  \   sourceOptions: #{
  \     _: #{
  \       converters: [],
  \       sorters: [ 'sorter_fzf'],
  \       matchers: ['converter_display_word','matcher_fzf'],
  \     },
  \   },
dmfay commented 11 months ago

I didn't realize the filters could go anywhere in the pipeline, thank you!

Shougo commented 11 months ago

All filters has same interface.

matchers, sorters, converters is just applied order.