Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add init support for a user defined PATH/glob cmd #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions autoload/search.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
let s:regexp_keyword_word = 'KEYWORD'
let s:engines = ['rg', 'ag']

let s:rg_base_cmd = "rg -n --auto-hybrid-regex --json"
" let s:rg_base_cmd = "rg -n --auto-hybrid-regex --json"
let s:rg_base_cmd = "rg --auto-hybrid-regex --json"
let s:ag_base_cmd = "ag --nogroup --noheading"

let s:rg_filetype_convertion_map = {
Expand Down Expand Up @@ -127,7 +128,7 @@ fu! search#GetSearchEngineFileTypeSpecifier(engine, language) abort
if a:engine == 'rg'
let file_lists_cmd = 'rg --files | rg ' . s:non_standard_ft_extensions_map_compiled[a:language]
let files = split(system(file_lists_cmd), "\n")
let cmd = join(map(files, {_,fname -> ('-f ' . fname)}), ' ')
let cmd = join(map(files, {_,fname -> ('-f ' . fname)}), ' ')
elseif a:engine == 'ag'
let cmd = '-G ' . s:non_standard_ft_extensions_map_compiled[a:language]
endif
Expand All @@ -150,7 +151,8 @@ fu! s:GetRgIgnoreSpecifier() abort
endif

for glob in g:any_jump_ignored_files
let result = result . ' -g !' . string(glob)
" let result = result . " -g '!" . string(glob) . "'"
let result = result . " -g !" . string(glob)
endfor

return result
Expand Down Expand Up @@ -227,6 +229,7 @@ fu! search#SearchDefinitions(lang, keyword) abort

if search_engine == 'rg'
let grep_results = s:RunRgDefinitionSearch(a:lang, regexp)
" let resp = confirm('results: ' . join(grep_results))
elseif search_engine == 'ag'
let grep_results = s:RunAgDefinitionSearch(a:lang, regexp)
end
Expand Down Expand Up @@ -325,10 +328,32 @@ endfu
fu! s:RunRgDefinitionSearch(language, patterns) abort
let rg_ft = s:GetRgFiletype(a:language)

let cmd = s:rg_base_cmd . ' -t ' . rg_ft
" TODO: instead of disabling the .gitignore filtering
" is there some way to just null out any `scan_results`
" patterns which match current `.gitignore` patterns?
let cmd = s:rg_base_cmd . ' -u' . ' -t ' . rg_ft
" let cmd = s:rg_base_cmd . ' -t ' . rg_ft
let cmd = cmd . s:GetRgIgnoreSpecifier()
let cmd = cmd . ' ' . a:patterns

" NOTE: the `-e` is ok here to be explicit right?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it was better then being implicit?

let cmd = cmd . ' -e ' . a:patterns

let scan_cmd = g:any_jump_glob_scanner
if strlen(scan_cmd)
let scan_results = systemlist(scan_cmd)
" echo 'Additional ' a:language . ' PATHs to scan: ' . join(scan_results)
" let cmd = cmd . ' ' . scan_results
" TODO: is it more correct to pass `-g <glob>` flags here?
for glob in scan_results
" TODO: apparently this flag doesn't work a <PATH> arg?!?
" let cmd = cmd . " -g " . string(glob) . "/*"
let cmd = cmd . " " . string(glob)
endfor
endif

" XXX: always include the cwd!
let cmd = cmd . ' ./'
" echo 'RG CMD: ' . cmd
let raw_results = system(cmd)
let grep_results = s:ParseRgResults(raw_results)
let grep_results = s:FilterGrepResults(a:language, grep_results)
Expand Down Expand Up @@ -361,7 +386,7 @@ fu! s:RunRgUsagesSearch(language, keyword) abort
\ && type(a:language) == v:t_string

let rg_ft = s:GetRgFiletype(a:language)
let cmd = cmd . ' -t ' . rg_ft
let cmd = cmd . ' -t ' . rg_ft
endif

let raw_results = system(cmd)
Expand All @@ -382,7 +407,7 @@ fu! s:RunAgUsagesSearch(language, keyword) abort
let cmd = cmd . ' --' . ag_ft
endif

let raw_results = system(cmd)
let raw_results = system(cmd)

let grep_results = s:ParseAgResults(raw_results)
let grep_results = s:FilterGrepResults(a:language, grep_results)
Expand Down
4 changes: 4 additions & 0 deletions plugin/any-jump.vim
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ call s:set_plugin_global_option('any_jump_disable_vcs_ignore', v:false)
" default is: ['*.tmp', '*.temp']
call s:set_plugin_global_option('any_jump_ignored_files', ['*.tmp', '*.temp'])

" Custom glob scanning command used to dynamically
" produce PATHs fed into `rg`/`ag`
call s:set_plugin_global_option('any_jump_glob_scanner', '')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sold on this name yet either 😂

suggestions welcome!


" ----------------------------------------------
" Public customization methods
" ----------------------------------------------
Expand Down