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

Specs engine updates; search language/ft updates #17

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
search engines specs updates
  • Loading branch information
pechorin committed Mar 3, 2020
commit 37fd638bb866ebf06ec6a4429d2bce16e4f63e6e
5 changes: 1 addition & 4 deletions autoload/internal_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ fu! s:InternalBuffer.RenderLine(items, line) dict abort

let next_start_col = item.end_col
let idx += 1
" echo "r -> " . item.hl_group . ' l:' . a:line
" \ . ' ' . item.start_col . ':' . item.end_col
" \ . ' — ' . string(item.text)
endfor

" write final text to buffer
Expand Down Expand Up @@ -578,7 +575,7 @@ fu! s:InternalBuffer.RenderUi() dict abort

call self.AddLine([ self.CreateItem("help_text", "", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[enter/o] open file [tab/p] preview file [esc/q] close ", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[t] toggle grouping [a] show all results [b] back to first result in list", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[T] toggle grouping [a] show all results [b] back to first result in list", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[u] show usages", "Comment") ])
endfu

Expand Down
114 changes: 94 additions & 20 deletions autoload/search.vim
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
" Search methods definitions

"
" --- Public api ---
"
" Search methods

let s:regexp_keyword_word = 'KEYWORD'
let s:engines = ['rg', 'ag']

let s:rg_base_cmd = "rg -n --pcre2 --json"
let s:ag_base_cmd = "ag --nogroup --noheading"

let s:rg_filetype_convertion_map = {
\"python": "py",
\"javascript": "js",
\"typescript": "ts",
\"commonlisp": "lisp",
\}

let s:ag_filetype_convertion_map = {
\"javascript": "js",
\"typescript": "ts",
\"commonlisp": "lisp",
\}

let s:non_standard_ft_extensions_map = {
\"coffeescript": [ '\.cjs\$', '\.coffee\$', 'Cakefile', '\._coffee\$', '\.coffeekup$', '\.ck\$' ],
\"coq": [ '\.v\$' ],
\"scad": [ '\.scad\$' ],
\"protobuf": [ '\.proto\$' ],
\"scss": [ '\.scss\$' ],
\"systemverilog": [ '\.sv\$', '\.svh\$' ],
\"racket": [ '\.rkt\$' ],
\"scheme": [ '\.scm\$', '\.ss\$', '\.sld\$' ],
\"faust": [ '\.dsp\$', '\.lib\$' ],
\"pascal": [ '\.pas\$', '\.dpr\$', '\.int\$', '\.dfm\$' ],
\"shell": [ '\.sh\$', '\.bash\$', '\.csh\$', '\.ksh\$', '\.tcsh\$' ],
\"haskell": [ '\.hs\$', '\.lhs\$' ],
\"dart": [ '\.dart\$' ]
\}

let s:non_standard_ft_extensions_map_compiled = {}
for lang in keys(s:non_standard_ft_extensions_map)
let rules = s:non_standard_ft_extensions_map[lang]
let regexp = map(rules, { _, pattern -> '(' . pattern . ')' })
let regexp = join(regexp, '|')
let regexp = "\"(" . regexp . ")\""

let s:non_standard_ft_extensions_map_compiled[lang] = regexp
endfor

fu! s:GetRgFiletype(lang) abort
if has_key(s:rg_filetype_convertion_map, a:lang)
return s:rg_filetype_convertion_map[a:lang]
Expand All @@ -21,6 +53,36 @@ fu! s:GetRgFiletype(lang) abort
endif
endfu

fu! s:GetAgFiletype(lang) abort
if has_key(s:ag_filetype_convertion_map, a:lang)
return s:ag_filetype_convertion_map[a:lang]
else
return a:lang
endif
endfu

fu! search#GetSearchEngineFileTypeSpecifier(engine, language) abort
let cmd = 0

if has_key(s:non_standard_ft_extensions_map_compiled, a:language)
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)}), ' ')
elseif a:engine == 'ag'
let cmd = '-G ' . s:non_standard_ft_extensions_map_compiled[a:language]
endif
else
if a:engine == 'rg'
let cmd = '-t ' . s:GetRgFiletype(a:language)
elseif a:engine == 'ag'
let cmd = '--' . s:GetAgFiletype(a:language)
endif
endif

return cmd
endfu

fu! search#SearchUsages(internal_buffer) abort
if g:any_jump_search_prefered_engine == 'rg'
let grep_results = s:RunRgUsagesSearch(a:internal_buffer.language, a:internal_buffer.keyword)
Expand Down Expand Up @@ -58,7 +120,7 @@ fu! search#SearchDefinitions(lang, keyword) abort
return grep_results
endfu

fu! search#RunSearchEnginesSpecs()
fu! search#RunSearchEnginesSpecs() abort
let errors = []

let has_rg = executable('rg')
Expand All @@ -74,42 +136,55 @@ fu! search#RunSearchEnginesSpecs()
return errors
endfu

fu! search#RunRegexpSpecs()
fu! search#RunRegexpSpecs() abort
let errors = []
let passed = 0
let failed = 0

for lang in keys(lang_map#definitions())
let lang_passed = 0
let lang_failed = 0

for entry in lang_map#definitions()[lang]
let re = entry.pcre2_regexp
let keyword = 'test'

if len(re) > 0
let test_re = substitute(re, 'KEYWORD', keyword, 'g')
let error_exit_codes = {"spec_success": [1,2], "spec_failed": [0,2]}
let invalid_exist_statues = {"spec_success": [1,2], "spec_failed": [0,2]}
let spec_types = keys(invalid_exist_statues)

for spec_type in keys(error_exit_codes)
for spec_type in spec_types
for spec_string in entry[spec_type]
for engine in s:engines
if index(entry.supports, engine) == -1
continue
endif

let cmd = 0
let ft_args = search#GetSearchEngineFileTypeSpecifier(engine, lang)

if engine == 'rg'
let cmd = "echo \"" . spec_string . "\" | rg --pcre2 --no-filename \"" . test_re . "\""
let rg_ft = s:GetRgFiletype(lang)
let cmd = "echo \"" . spec_string . "\" | "
\ . s:rg_base_cmd . " --no-filename "
\ . ft_args . " \"" . test_re . "\""
end

if engine == 'ag'
let cmd = "echo \"" . spec_string . "\" | ag \"" . test_re . "\""
let ag_ft = s:GetAgFiletype(lang)
let cmd = "echo \"" . spec_string . "\" | "
\ . s:ag_base_cmd . " " . ft_args . " \""
\ . test_re . "\""
endif

let raw_results = system(cmd)

if index(error_exit_codes[spec_type], v:shell_error) >= 0
call add(errors, "FAILED -- " . spec_type . ' ' . string(raw_results) . ' -- ' . lang . " -- " . spec_string . ' -- ' . test_re)
if index(invalid_exist_statues[spec_type], v:shell_error) != -1
call add(errors, 'FAILED ' . engine . ' ' . lang . ' ' . spec_type . ' -- result: ' . string(raw_results) . "; spec: " . string(spec_string) . '; re: ' . string(test_re))
let lang_failed += 1
else
let passed += 1
let lang_passed += 1
endif

endfor
Expand All @@ -119,10 +194,9 @@ fu! search#RunRegexpSpecs()

endfor

echo "lang " . lang . ' finished tests ' . passed
echo "lang " . lang . ' finished success:' . lang_passed . ' failed: ' . lang_failed
endfor

echo "passed tests: " . passed
return errors
endfu

Expand All @@ -137,7 +211,7 @@ endfu
fu! s:RunRgUsagesSearch(language, keyword) abort
let rg_ft = s:GetRgFiletype(a:language)

let cmd = "rg -n --pcre2 --json -t " . rg_ft . ' -w ' . a:keyword
let cmd = s:rg_base_cmd . ' -t ' . rg_ft . ' -w ' . a:keyword
let raw_results = system(cmd)
let grep_results = s:ParseRgResults(raw_results)

Expand All @@ -147,23 +221,23 @@ endfu
fu! s:RunRgDefinitionSearch(language, patterns) abort
let rg_ft = s:GetRgFiletype(a:language)

let cmd = "rg -n --pcre2 --json -t " . rg_ft . ' ' . a:patterns
let cmd = s:rg_base_cmd . ' -t ' . rg_ft . ' ' . a:patterns
let raw_results = system(cmd)
let grep_results = s:ParseRgResults(raw_results)

return grep_results
endfu

fu! s:RunAgUsagesSearch(language, keyword) abort
let cmd = "ag --nogroup --noheading --" . a:language . ' -w ' . a:keyword
let cmd = s:ag_base_cmd . ' --' . a:language . ' -w ' . a:leyword
let raw_results = system(cmd)
let grep_results = s:ParseAgResults(raw_results)

return grep_results
endfu

fu! s:RunAgDefinitionSearch(language, patterns) abort
let cmd = "ag --nogroup --noheading --" . a:language . ' ' . a:patterns
let cmd = s:ag_base_cmd . ' --' . a:language . ' ' . a:patterns
let raw_results = system(cmd)
let grep_results = s:ParseAgResults(raw_results)

Expand Down
24 changes: 13 additions & 11 deletions plugin/any-jump.vim
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
" TODO:
" - фильтрация результатов ( - search definitions ) для определений не
" работает как надо
" - добавить возможность открывать окно не только в текущем window, но и
" делать vsplit/split относительного него
" - create doc
" - ignore language comments
" - add specs for all search engines
"
" - >> если нажать [a] show all results потом промотать потом снова [a] то приходится назад мотать долго - мб как то в начало списка кидать в таком кейсе?
"
" - if no language found -> run definitions search in current, unless current
" is home directory
"
" - hl keyword line in preview
" - profile vim popup menu k/j move (slow for now)
"
" - [nvim] >> Once a focus to the floating window is lost, the window should disappear. Like many other plugins with floating window.
" - добавить возможность открывать окно не только в текущем window, но и
" делать vsplit/split относительного него
"
" - add ag conversion for js also
" - add ag convertion for js
" - [nvim] >> Once a focus to the floating window is lost, the window should disappear. Like many other plugins with floating window.
"
" - add ability to provide ft aliases for rg/ag and solve problem with new ft
" - >> it is a good practice to augroup your aucmds
" - add namespace id for nvim hl
"
" - add ability to change list styles by keybind
" - create doc
"
" - paths priorities for better search results
"
" TODO_THINK:
" - rg and ag results sometimes very differenet
" - after pressing p jump to next result
" - add auto preview option
" - impl VimL rules
" - fzf
"
" TODO_FUTURE_RELEASES:
" - paths priorities for better search results
" - AnyJumpPreview
" - AnyJumpFirst
" - jumps history & jumps work flow
Expand Down Expand Up @@ -621,7 +623,7 @@ fu! s:RunSpecs() abort

if len(errors) > 0
for error in errors
echo error
echoe error
endfor
endif

Expand Down