/autoload/esearch/adapter/rg.vim

https://github.com/eugen0329/vim-esearch · Vim Script · 54 lines · 44 code · 4 blank · 6 comment · 7 complexity · 6d5ccdf426306de50ff3f5ed6aae4bb0 MD5 · raw file

  1. fu! esearch#adapter#rg#new() abort
  2. return copy(s:Rg)
  3. endfu
  4. let s:Rg = esearch#adapter#base#import()
  5. if exists('g:esearch#adapter#rg#bin')
  6. " TODO warn deprecated
  7. let s:Rg.bin = g:esearch#adapter#rg#bin
  8. else
  9. let s:Rg.bin = 'rg'
  10. endif
  11. if exists('g:esearch#adapter#rg#options')
  12. " TODO warn deprecated
  13. let s:Rg.options = g:esearch#adapter#rg#options
  14. else
  15. " --text: Search binary files as if they were text
  16. let s:Rg.options = '--follow'
  17. endif
  18. let s:Rg.mandatory_options = '--no-heading --color=never --line-number --with-filename'
  19. " https://docs.rs/regex/1.3.6/regex/#syntax
  20. call extend(s:Rg, {
  21. \ 'bool2regex': ['literal', 'default'],
  22. \ 'regex': {
  23. \ 'literal': {'icon': '', 'option': '--fixed-strings'},
  24. \ 'default': {'icon': 'r', 'option': ''},
  25. \ 'auto': {'icon': 'A', 'option': '--engine auto'},
  26. \ 'pcre': {'icon': 'P', 'option': '--pcre2'},
  27. \ },
  28. \ 'bool2textobj': ['none', 'word'],
  29. \ 'textobj': {
  30. \ 'none': {'icon': '', 'option': ''},
  31. \ 'word': {'icon': 'w', 'option': '--word-regexp'},
  32. \ 'line': {'icon': 'l', 'option': '--line-regexp'},
  33. \ },
  34. \ 'bool2case': ['ignore', 'sensitive'],
  35. \ 'case': {
  36. \ 'ignore': {'icon': '', 'option': '--ignore-case'},
  37. \ 'sensitive': {'icon': 's', 'option': '--case-sensitive'},
  38. \ 'smart': {'icon': 'S', 'option': '--smart-case'},
  39. \ }
  40. \ })
  41. " rg --type-list | cut -d: -f1 | tr '\n' ' '
  42. let s:Rg.filetypes = split('agda aidl amake asciidoc asm asp ats avro awk bazel bitbake brotli buildstream bzip2 c cabal cbor ceylon clojure cmake coffeescript config coq cpp creole crystal cs csharp cshtml css csv cython d dart dhall diff docker ebuild edn elisp elixir elm erb erlang fidl fish fortran fsharp gap gn go gradle groovy gzip h haml haskell hbs hs html idris java jinja jl js json jsonl julia jupyter k kotlin less license lisp lock log lua lz4 lzma m4 make mako man markdown matlab md mk ml msbuild nim nix objc objcpp ocaml org pascal pdf perl php pod postscript protobuf ps puppet purs py qmake qml r rdoc readme robot rst ruby rust sass scala sh slim smarty sml soy spark spec sql stylus sv svg swift swig systemd taskpaper tcl tex textile tf thrift toml ts twig txt typoscript vala vb verilog vhdl vim vimscript webidl wiki xml xz yacc yaml zig zsh zstd')
  43. fu! s:Rg.filetypes2args(filetypes) abort dict
  44. return substitute(a:filetypes, '\<', '--type ', 'g')
  45. endfu
  46. fu! s:Rg.is_success(request) abort
  47. " https://github.com/BurntSushi/ripgrep/issues/948
  48. return a:request.status == 0
  49. \ || (a:request.status == 1 && empty(a:request.errors) && empty(a:request.data))
  50. endfu