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

Conversation

goodboy
Copy link

@goodboy goodboy commented Nov 23, 2023

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?
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 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
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.

let cmd = cmd . ' ' . scan_results
endif

" TODO: is it more correct to pass `-g <glob>` flags here?
Copy link
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.

@@ -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!

@goodboy
Copy link
Author

goodboy commented Nov 25, 2023

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