Skip to content

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

Open
goodboy wants to merge 2 commits into
pechorin:masterfrom
goodboy:custom_glob_scanner
Open

goodboy wants to merge 2 commits into
pechorin:masterfrom
goodboy:custom_glob_scanner

Conversation

@goodboy

@goodboy goodboy commented Nov 23, 2023

Copy link
Copy Markdown

An attempt to resolve #112.

I'm not sure if this kinda thing will make all that much sense for AOT compiled langs (since often getting lib symbols isn't so straight forward as running some command to produce source-code-file-containing directories) but, it definitely is a thing in a language like python which users often dev / deploy in "isolated" runtime environments ("virtual envs"). In this case I have defined my custom glob scanner as:

let g:any_jump_glob_scanner = join([
    \'python',
    \'-c',
    \'"import os, site;',
    \"print(' '.join('{}'.format(d)",
    \'for d in site.getsitepackages()))',
    \'"',
    \])

which allows searching symbol defs in the user's locally activated python runtime env and thus the env specific ../site-packages/*.


Also included are some slight formatting tweaks in a couple of spots that seemed to have extra whitespace and a couple tweaks to the rg -g '!<globpatt>' quoting to work better when echoing the full cmd from vim for manuall copy/pasta debugging.


Still TODO

  • the new global g:any_jump_glob_scanner and its value is only conditionally used inside RunRgDefinitionSearch() (for now, not sure if in side RunRgUsagesSearch() is also useful/warranted?)
    -[ ] currently only implemented thus far for rg backend
    • not sure if it's "smarter" to avoid use of rg -u filter removal and instead use -g <PATH> or some other >.gitignore override thingy?
  • ag support!
    • wtv similar optimizations as done in rg

Can be user defined as the new global `g:any_jump_glob_scanner`
and its value is only conditionally used inside `RunRgDefinitionSearch()`
(for now, not sure if in side `RunRgUsagesSearch()` is also
useful/warranted?)

Notes:
- only implemented thus far for `rg` backend
- not sure if it's "smarter" to avoid use of `rg -u` filter removal and
  instead use `-g <PATH>` or some other `.gitignore` override thingy?
Comment thread autoload/search.vim
let cmd = cmd . s:GetRgIgnoreSpecifier()
let cmd = cmd . ' ' . a:patterns

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

Copy link
Copy Markdown
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?

Comment thread autoload/search.vim Outdated
let scan_cmd = g:any_jump_glob_scanner
if strlen(scan_cmd)
let scan_results = system(scan_cmd)
" echo 'Additional ' a:language . ' PATHs to scan: ' . scan_results

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

was just left in for debugging, obviously can be removed.

Comment thread autoload/search.vim Outdated
let cmd = cmd . ' ' . scan_results
endif

" TODO: is it more correct to pass `-g <glob>` flags here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Would like feedback on whether this (or something else) is a better approach?

Also see the TODOs in the description.

Comment thread plugin/any-jump.vim

" 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
Copy Markdown
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!

@goodboy

goodboy commented Nov 25, 2023

Copy link
Copy Markdown
Author

Huh interestingly I seem to be getting some weird relative path thing when trying to "preview" the context of a given match?

screenshot-2023-11-25_17-25-37

it seems to be slapping the home-dir path in twice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamically extend the grep-bin scan paths?

1 participant