From 969820c3dbf45497bd4ecdfab1821114e52b055e Mon Sep 17 00:00:00 2001 From: devjoe Date: Fri, 29 Jul 2016 03:01:58 +0800 Subject: [PATCH 01/81] add demo gif / update readme --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c1c6fdd..99e88ac 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,57 @@ # vim-codequery -This plugin is build on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: +This Vim plugin is build on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: -1. Do CodeQuery-liked queries. (70% Done, Need to fix some bugs) +1. Do CodeQuery-liked queries. (80% Done, Need to fix some bugs) 2. Manage your database. (TBD, Release Date: Mid-August) 3. "Know" your code instantly. (TBD, Release Date: September) -## Status: Don't Install Me ! +Supporting languages are: +* Python +* C, C++ +* Java +* Ruby +* Go +* Javascript + +## Status: ~ Don't Install Me Now ! Please Wait ~ **This project is still under development.** -Completeness: 30% +Completeness: 40% ## Demo +#### Search Symbol +![](https://dl.dropboxusercontent.com/u/7414946/github/symbol.gif) + +#### Search Definition (+ fuzzy option) +![](https://dl.dropboxusercontent.com/u/7414946/github/definition.gif) + +#### Search Call/Caller/Callee +![](https://dl.dropboxusercontent.com/u/7414946/github/call.gif) + +#### Search Parent/Children +![](https://dl.dropboxusercontent.com/u/7414946/github/pc.gif) + +#### Search Class/Member +![](https://dl.dropboxusercontent.com/u/7414946/github/cm.gif) + +#### Search FileImporter +![](https://dl.dropboxusercontent.com/u/7414946/github/fi.gif) + +#### Search FunctionList +![](https://dl.dropboxusercontent.com/u/7414946/github/fl.gif) + +#### [Not Implemented] Search DefinitionGroup + +#### [Not Implemented] Search Tag + +#### [Not Implemented] Menu + +#### [Not Implemented] LoadDB/BuildDB + +#### [Not Implemented] Analyze + ## Usage ## Installation From 92586ff61c6b9de3f439ef3b20fd56417d90cba7 Mon Sep 17 00:00:00 2001 From: devjoe Date: Fri, 29 Jul 2016 11:34:44 +0800 Subject: [PATCH 02/81] use compressed gif --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 99e88ac..c64c3dd 100644 --- a/README.md +++ b/README.md @@ -22,25 +22,25 @@ Completeness: 40% ## Demo #### Search Symbol -![](https://dl.dropboxusercontent.com/u/7414946/github/symbol.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/symbol-c.gif) #### Search Definition (+ fuzzy option) -![](https://dl.dropboxusercontent.com/u/7414946/github/definition.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/def-c.gif) #### Search Call/Caller/Callee -![](https://dl.dropboxusercontent.com/u/7414946/github/call.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/call-c.gif) #### Search Parent/Children -![](https://dl.dropboxusercontent.com/u/7414946/github/pc.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/pc-c.gif) #### Search Class/Member -![](https://dl.dropboxusercontent.com/u/7414946/github/cm.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/cm-c.gif) #### Search FileImporter -![](https://dl.dropboxusercontent.com/u/7414946/github/fi.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/fi-c.gif) #### Search FunctionList -![](https://dl.dropboxusercontent.com/u/7414946/github/fl.gif) +![](https://dl.dropboxusercontent.com/u/7414946/github/fl-c.gif) #### [Not Implemented] Search DefinitionGroup From 9d9ecf3ea84fdffaa67372b7d27a03daf4a24cda Mon Sep 17 00:00:00 2001 From: devjoe Date: Fri, 29 Jul 2016 12:47:01 +0800 Subject: [PATCH 03/81] Update README.md --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c64c3dd..d6815b0 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,22 @@ This Vim plugin is build on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: 1. Do CodeQuery-liked queries. (80% Done, Need to fix some bugs) -2. Manage your database. (TBD, Release Date: Mid-August) -3. "Know" your code instantly. (TBD, Release Date: September) +2. Manage your database. (TBD, Finished Date: Mid-August) +3. "Know" your code instantly. (TBD, Finished Date: September) -Supporting languages are: +## Supporting languages * Python +* Javascript +* Ruby * C, C++ * Java -* Ruby * Go -* Javascript - + ## Status: ~ Don't Install Me Now ! Please Wait ~ -**This project is still under development.** -Completeness: 40% +> **This project is still under development.** +> +> *Completeness: 40%* ## Demo @@ -48,6 +49,8 @@ Completeness: 40% #### [Not Implemented] Menu +#### [Not Implemented] Switch + #### [Not Implemented] LoadDB/BuildDB #### [Not Implemented] Analyze From 9429bb8e68c2704a829d9f391dde8b6f097b4bd8 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 1 Aug 2016 01:19:01 +0800 Subject: [PATCH 04/81] load db (30%) --- plugin/codequery.vim | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 5dd8f83..ebf3e53 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -39,6 +39,38 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'DefinitionGroup' : 20 } +function! s:find_db_path() + if &filetype ==# 'python' + echom 'good ~ it is python !' + else + echom 'not python ~ bye bye ~' + return + endif + + let db_name = &filetype . '.db' + let lookup_path = findfile(expand('%:h') . '/' . db_name, '.') + + if !empty(lookup_path) + echom 'found DB in ' . lookup_path + return lookup_path + endif + +endfunction + + +function! s:set_db() + let path = s:find_db_path() + if empty(path) + echom 'Can not find DB' + return 0 + else + let s:db_path = path + echom 'Get DB ~ Oh Ya ~' + return 1 + endif +endfunction + + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v[a-z|A-Z|0-9|_]+')) > 0 endfunction @@ -76,19 +108,19 @@ function! s:do_grep(word) let pipeline_script_option = ' \| cut -f 2,3' let grepformat = '%f:%l%m' - let grepprg = 'cqsearch -s myproject.db -p ' . s:querytype . ' -t ' . + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . \ a:word . ' ' . fuzzy_option . pipeline_script_option if s:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s myproject.db -p ' . s:querytype . ' -t ' . + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . \ a:word . ' ' . fuzzy_option elseif s:querytype == s:subcmd_map['Callee'] || \ s:querytype == s:subcmd_map['Caller'] || \ s:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s myproject.db -p ' . s:querytype . ' -t ' . + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . \ a:word . ' ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' elseif s:querytype == s:subcmd_map['DefinitionGroup'] @@ -131,9 +163,13 @@ endfunction function! s:run_codequery(args) + " do init let s:fuzzy = 0 let s:append_to_quickfix = 0 let s:querytype = 1 + let s:db_path = '' + call s:set_db() + let args = split(a:args, ' ') let args_num = len(args) From 7357922a73aacf0a97aadb05c6890fc95346928d Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Aug 2016 00:06:15 +0800 Subject: [PATCH 05/81] find db file automatically --- plugin/codequery.vim | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index a04cbbc..252696a 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -40,10 +40,10 @@ let s:subcmd_map = { 'Symbol' : 1, function! s:find_db_path() - if &filetype ==# 'python' - echom 'good ~ it is python !' - else - echom 'not python ~ bye bye ~' + let supported_filetypes = + \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] + if index(supported_filetypes, &filetype) == -1 + echom 'Not Supported Filetype: ' . &filetype return endif @@ -51,9 +51,26 @@ function! s:find_db_path() let lookup_path = findfile(expand('%:h') . '/' . db_name, '.') if !empty(lookup_path) - echom 'found DB in ' . lookup_path + lcd %:h return lookup_path endif + + lcd %:h + let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] + if !v:shell_error + let lookup_path = findfile(git_root_dir . '/' . db_name, '.') + if !empty(lookup_path) + execute 'lcd ' . git_root_dir + return lookup_path + else + let lookup_path = findfile(git_root_dir . '/.git/codequery/' . + \ db_name, '.') + if !empty(lookup_path) + execute 'lcd ' . git_root_dir + return lookup_path + endif + endif + endif endfunction @@ -61,13 +78,12 @@ endfunction function! s:set_db() let path = s:find_db_path() if empty(path) - echom 'Can not find DB' + echom 'CodeQuery DB Not Found' return 0 - else - let s:db_path = path - echom 'Get DB ~ Oh Ya ~' - return 1 endif + + let s:db_path = path + return 1 endfunction @@ -168,7 +184,9 @@ function! s:run_codequery(args) let s:append_to_quickfix = 0 let s:querytype = 1 let s:db_path = '' - call s:set_db() + if !s:set_db() + return + endif let args = split(a:args, ' ') From cc496b58aa9deedcd9cb99f62d2665019fb6b52b Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Aug 2016 00:46:25 +0800 Subject: [PATCH 06/81] clean comment --- plugin/codequery.vim | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 252696a..abd9f7c 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -71,7 +71,6 @@ function! s:find_db_path() endif endif endif - endfunction @@ -179,7 +178,6 @@ endfunction function! s:run_codequery(args) - " do init let s:fuzzy = 0 let s:append_to_quickfix = 0 let s:querytype = 1 @@ -188,21 +186,14 @@ function! s:run_codequery(args) return endif - let args = split(a:args, ' ') let args_num = len(args) let cword = s:get_valid_cursor_word() if args_num == 0 - " Example: - " :CodeQuery call s:do_grep(cword) elseif index(s:subcommands, args[0]) != -1 - " Examples: - " :CodeQuery Symbol - " :CodeQuery Symbol -f -a - " :CodeQuery Symbol search_term -f -a call s:set_options(args) let iword = s:get_valid_input_word(args) @@ -229,4 +220,4 @@ endfunction " Debugging -"nnoremap c :CodeQuery +"nnoremap c :CodeQuery From 61cce904b9e3a16db14cd6b20bee4d7dd10ba570 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 6 Aug 2016 00:14:57 +0800 Subject: [PATCH 07/81] add CodeQueryMakeDB command to create DB (python only now) --- plugin/codequery.vim | 52 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index abd9f7c..e97f07c 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -6,6 +6,7 @@ command! -nargs=* -complete=customlist,s:complete_function CodeQuery call s:run_codequery() +command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() let s:subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', @@ -39,14 +40,18 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'DefinitionGroup' : 20 } -function! s:find_db_path() +function! s:check_filetype() let supported_filetypes = \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] if index(supported_filetypes, &filetype) == -1 - echom 'Not Supported Filetype: ' . &filetype - return + return 0 endif + return 1 +endfunction + +" `lcd` brings side effect !! +function! s:find_db_path() let db_name = &filetype . '.db' let lookup_path = findfile(expand('%:h') . '/' . db_name, '.') @@ -178,6 +183,11 @@ endfunction function! s:run_codequery(args) + if !s:check_filetype() + echom 'Not Supported Filetype: ' . &filetype + return + endif + let s:fuzzy = 0 let s:append_to_quickfix = 0 let s:querytype = 1 @@ -215,6 +225,42 @@ function! s:run_codequery(args) endfunction +function! s:make_codequery_db() + if !s:check_filetype() + echom 'Not Supported Filetype: ' . &filetype + return + endif + + let db_path = s:find_db_path() + if empty(db_path) + let db_path = &filetype . '.db' + endif + + " TODO: refactor later --------------- + let cscope_file = &filetype . '_cscope.files' + let cscopeout_file = &filetype . '_cscope.out' + let tags_file = &filetype . '_tags' + + let find_cmd = 'find . -iname "*.py" > ' . cscope_file + let pycscope_cmd = 'pycscope -f "' . cscopeout_file . '" -i ' . cscope_file + let ctags_cmd = 'ctags --fields=+i -n -R -f "' . + \ tags_file . '" -L ' . cscope_file + let cqmakedb_cmd = 'cqmakedb -s "' . db_path . '" -c ' . cscopeout_file . + \ ' -t ' . tags_file . ' -p' + let shell_cmd = find_cmd . ' && ' . + \ pycscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + " ------------------------------------ + + if exists(':Start') + execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd + else + silent execute '!' . shell_cmd + redraw! + endif +endfunction + " ============================================================================= " Debugging From c9d5e389c4c6c9e7b48a98ed650d7886c9de9742 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 6 Aug 2016 16:23:33 +0800 Subject: [PATCH 08/81] show # of results properly --- plugin/codequery.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index e97f07c..bcf5272 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -156,7 +156,14 @@ function! s:do_grep(word) let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' silent execute grepcmd redraw! - copen + + let results = getqflist() + if !empty(results) + echo 'Found ' . len(results) . ' results' + copen + else + echo 'Result Not Found' + endif finally let &l:grepprg = l:grepprg_bak let &grepformat = l:grepformat_bak From 11eafb85fba598ecca55e4640cece3b7a0f5344a Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 6 Aug 2016 20:30:15 +0800 Subject: [PATCH 09/81] add CodeQueryViewDB command to list db file --- plugin/codequery.vim | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index bcf5272..c287985 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -7,6 +7,7 @@ command! -nargs=* -complete=customlist,s:complete_function CodeQuery call s:run_codequery() command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() +command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() let s:subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', @@ -261,7 +262,9 @@ function! s:make_codequery_db() " ------------------------------------ if exists(':Start') - execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd + silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd + redraw! + echo 'Run :CodeQueryViewDB to Check Status' else silent execute '!' . shell_cmd redraw! @@ -269,6 +272,23 @@ function! s:make_codequery_db() endfunction +function! s:view_codequery_db() + " TODO: remove duplicated filetype checking code + if !s:check_filetype() + echom 'Not Supported Filetype: ' . &filetype + return + endif + + let db_path = s:find_db_path() + if empty(db_path) + echom 'DB not Found' + endif + + execute '!echo "\nYour DB: (check modified_time)" && ls -alh ' . db_path +endfunction + + + " ============================================================================= " Debugging From 983f2e3c25617be775a56eeb0fe9a7ff4cc048fa Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 6 Aug 2016 21:56:29 +0800 Subject: [PATCH 10/81] add CodeQueryMoveDBToGitDir command --- plugin/codequery.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index c287985..f513a08 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -5,9 +5,12 @@ " Menu -command! -nargs=* -complete=customlist,s:complete_function CodeQuery call s:run_codequery() +command! -nargs=* -complete=customlist,s:complete_function CodeQuery + \ call s:run_codequery() command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() +command! -nargs=0 CodeQueryMoveDBToGitDir + \ call s:move_codequery_db_to_git_hidden_dir() let s:subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', @@ -284,7 +287,23 @@ function! s:view_codequery_db() echom 'DB not Found' endif - execute '!echo "\nYour DB: (check modified_time)" && ls -alh ' . db_path + execute '!echo "\nYour DB is update at: " && stat -f "\%Sm" ' . db_path +endfunction + + +function! s:move_codequery_db_to_git_hidden_dir() + let db_name = &filetype . '.db' + let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] + let db_path = s:find_db_path() + + if !v:shell_error && !empty(db_path) + let new_db_path = git_root_dir . '/.git/codequery/' . db_name + call system('mkdir -p ' . git_root_dir . '/.git/codequery/') + call system('mv ' . db_path . ' ' . new_db_path) + echom 'Done' + else + echo 'Git Dir Not Found or DB Not Found' + endif endfunction From ace88e4b174b1e0d3753e53f7f36f3a5e3b855b4 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 10 Aug 2016 23:02:53 +0800 Subject: [PATCH 11/81] use echom instead of echo --- plugin/codequery.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index f513a08..104b7f0 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -163,10 +163,10 @@ function! s:do_grep(word) let results = getqflist() if !empty(results) - echo 'Found ' . len(results) . ' results' + echom 'Found ' . len(results) . ' results' copen else - echo 'Result Not Found' + echom 'Result Not Found' endif finally let &l:grepprg = l:grepprg_bak @@ -231,7 +231,7 @@ function! s:run_codequery(args) call s:do_grep(iword) else - echo 'Wrong Subcommand !' + echom 'Wrong Subcommand !' endif endfunction @@ -267,7 +267,7 @@ function! s:make_codequery_db() if exists(':Start') silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd redraw! - echo 'Run :CodeQueryViewDB to Check Status' + echom 'Run :CodeQueryViewDB to Check Status' else silent execute '!' . shell_cmd redraw! @@ -302,7 +302,7 @@ function! s:move_codequery_db_to_git_hidden_dir() call system('mv ' . db_path . ' ' . new_db_path) echom 'Done' else - echo 'Git Dir Not Found or DB Not Found' + echom 'Git Dir Not Found or DB Not Found' endif endfunction From dd59dbff4a218d5bd61c8f016ff0d71759124edd Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 10 Aug 2016 23:42:46 +0800 Subject: [PATCH 12/81] correct regular expr --- plugin/codequery.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 104b7f0..da3bf62 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -96,7 +96,7 @@ endfunction function! s:is_valid_word(word) - return strlen(matchstr(a:word, '\v[a-z|A-Z|0-9|_]+')) > 0 + return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_]+$')) > 0 endfunction From 251366b89bc04e7579d4fae957c3fee944d2a8ba Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 10 Aug 2016 23:48:45 +0800 Subject: [PATCH 13/81] add CodeQueryMenu command & basic unite menu --- plugin/codequery.vim | 46 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index da3bf62..d3149e3 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -11,17 +11,19 @@ command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() command! -nargs=0 CodeQueryMoveDBToGitDir \ call s:move_codequery_db_to_git_hidden_dir() +command! -nargs=* CodeQueryMenu call s:show_menu() -let s:subcommands = [ 'Symbol', +let s:query_subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', \ 'Caller', 'Callee', 'Call', \ 'Class', 'Member', 'Parent', 'Child', \ 'FunctionList', \ 'FileImporter', \ ] +let s:menu_subcommands = [ 'Unite' ] function! s:complete_function(arg_lead, cmd_line, cursor_pos) - return s:subcommands + return s:query_subcommands endfunction @@ -214,7 +216,7 @@ function! s:run_codequery(args) if args_num == 0 call s:do_grep(cword) - elseif index(s:subcommands, args[0]) != -1 + elseif index(s:query_subcommands, args[0]) != -1 call s:set_options(args) let iword = s:get_valid_input_word(args) @@ -307,6 +309,44 @@ function! s:move_codequery_db_to_git_hidden_dir() endfunction +function! s:show_menu(args) + let args = split(a:args, ' ') + let args_num = len(args) + + if args_num > 0 && index(s:menu_subcommands, args[0]) != -1 + if args[0] ==# 'Unite' + let g:unite_source_menu_menus.codequery = { + \ 'description' : 'CQ Smart Menu', + \} + let g:unite_source_menu_menus.codequery.command_candidates = [ + \['▷ Find Symbol', 'CodeQuery'], + \['# ----------------- #', ''], + \['▷ Find Function Def.', 'CodeQuery Definition'], + \['▷ Find Call', 'CodeQuery Call'], + \['▷ Find Caller', 'CodeQuery Caller'], + \['▷ Find Callee', 'CodeQuery Callee'], + \['# ----------------- #', ''], + \['▷ Find Class Def.', 'CodeQuery Class'], + \['▷ Find Class Member', 'CodeQuery Member'], + \['▷ Find Parent', 'CodeQuery Parent'], + \['▷ Find Child', 'CodeQuery Child'], + \['# ----------------- #', ''], + \['▷ List Function', 'CodeQuery FunctionList'], + \['▷ List Imports', 'CodeQuery FileImporter'], + \['# ----------------- #', ''], + \['▷ Make DB', 'CodeQueryMakeDB'], + \['▷ View DB', 'CodeQueryViewDB'], + \['▷ Move DB', 'CodeQueryMoveDBToGitDir'], + \] + execute 'Unite -start-insert -silent -prompt=::CQ:: menu:codequery' + return + endif + endif + + echom 'Wrong Subcommands! Try: ' . join(s:menu_subcommands, ', ') +endfunction + + " ============================================================================= " Debugging From ef831fcc0b0824ef524daf88aab0d59e158dbfc8 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 11 Aug 2016 12:40:49 +0800 Subject: [PATCH 14/81] fix display result bug --- plugin/codequery.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index d3149e3..c08e1b7 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -167,6 +167,7 @@ function! s:do_grep(word) if !empty(results) echom 'Found ' . len(results) . ' results' copen + echom 'Found ' . len(results) . ' results' else echom 'Result Not Found' endif From a1daa5839253b8082879af0784120e4328cd7a78 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 11 Aug 2016 13:02:57 +0800 Subject: [PATCH 15/81] finish unite full/magic menu --- plugin/codequery.vim | 85 +++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index c08e1b7..7b501be 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -165,7 +165,6 @@ function! s:do_grep(word) let results = getqflist() if !empty(results) - echom 'Found ' . len(results) . ' results' copen echom 'Found ' . len(results) . ' results' else @@ -191,6 +190,60 @@ function! s:set_options(args) endfunction +function! s:use_unite_menu(magic) + let cword = s:get_valid_cursor_word() + let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery']] + let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], + \['▷ Find Call [F]', 'CodeQuery Call'], + \['▷ Find Caller [F]', 'CodeQuery Caller'], + \['▷ Find Callee [F]', 'CodeQuery Callee']] + let menu_class_cmds = [['▷ Find Class Def. [C]', 'CodeQuery Class'], + \['▷ Find Class Member [C]', 'CodeQuery Member'], + \['▷ Find Parent [C]', 'CodeQuery Parent'], + \['▷ Find Child [C]', 'CodeQuery Child']] + let menu_other_cmds = [['▷ List Function', 'CodeQuery FunctionList'], + \['▷ List Imports', 'CodeQuery FileImporter']] + let menu_delimiter = [['* ------------------------- *', '']] + let menu_db_cmds = [['▷ Make DB', 'CodeQueryMakeDB'], + \['▷ View DB', 'CodeQueryViewDB'], + \['▷ Move DB', 'CodeQueryMoveDBToGitDir']] + let menu_goto_magic = [['▷ ', 'CodeQueryMenu Unite Magic']] + let menu_goto_full = [['▷ ', 'CodeQueryMenu Unite Full']] + + if a:magic + let menu_description = 'CodeQuery Smart Menu' + if cword =~ '\C^[A-Z].*' + let cmd_candidates = menu_frequent_cmds + \ + menu_class_cmds + \ + menu_other_cmds + \ + menu_goto_full + else + let cmd_candidates = menu_frequent_cmds + \ + menu_function_cmds + \ + menu_other_cmds + \ + menu_goto_full + endif + else + let menu_description = 'CodeQuery Full Menu' + let cmd_candidates = menu_frequent_cmds + \ + menu_function_cmds + \ + menu_class_cmds + \ + menu_other_cmds + \ + menu_delimiter + \ + menu_db_cmds + \ + menu_delimiter + \ + menu_goto_magic + endif + + let g:unite_source_menu_menus.codequery = { + \ 'description' : menu_description, + \} + let g:unite_source_menu_menus.codequery.command_candidates = cmd_candidates + execute 'Unite -start-insert -silent -prompt=::' . cword + \ . ':: menu:codequery' +endfunction + + " ============================================================================= " Entries @@ -316,30 +369,12 @@ function! s:show_menu(args) if args_num > 0 && index(s:menu_subcommands, args[0]) != -1 if args[0] ==# 'Unite' - let g:unite_source_menu_menus.codequery = { - \ 'description' : 'CQ Smart Menu', - \} - let g:unite_source_menu_menus.codequery.command_candidates = [ - \['▷ Find Symbol', 'CodeQuery'], - \['# ----------------- #', ''], - \['▷ Find Function Def.', 'CodeQuery Definition'], - \['▷ Find Call', 'CodeQuery Call'], - \['▷ Find Caller', 'CodeQuery Caller'], - \['▷ Find Callee', 'CodeQuery Callee'], - \['# ----------------- #', ''], - \['▷ Find Class Def.', 'CodeQuery Class'], - \['▷ Find Class Member', 'CodeQuery Member'], - \['▷ Find Parent', 'CodeQuery Parent'], - \['▷ Find Child', 'CodeQuery Child'], - \['# ----------------- #', ''], - \['▷ List Function', 'CodeQuery FunctionList'], - \['▷ List Imports', 'CodeQuery FileImporter'], - \['# ----------------- #', ''], - \['▷ Make DB', 'CodeQueryMakeDB'], - \['▷ View DB', 'CodeQueryViewDB'], - \['▷ Move DB', 'CodeQueryMoveDBToGitDir'], - \] - execute 'Unite -start-insert -silent -prompt=::CQ:: menu:codequery' + if args_num > 1 && args[1] ==# 'Magic' + let magic_menu = 1 + else + let magic_menu = 0 + endif + call s:use_unite_menu(magic_menu) return endif endif From bb87ec98f8c4e6be795533cfc8661339b17e69d8 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 12 Aug 2016 17:47:20 +0800 Subject: [PATCH 16/81] fix fuzzy bug --- plugin/codequery.vim | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 7b501be..9f5b98e 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -98,7 +98,7 @@ endfunction function! s:is_valid_word(word) - return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_]+$')) > 0 + return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -130,24 +130,31 @@ function! s:do_grep(word) return endif - let fuzzy_option = s:fuzzy ? '-f' : '-e' + if s:fuzzy + let fuzzy_option = '-f' + let word = '"' . a:word . '"' + else + let fuzzy_option = '-e' + let word = a:word + endif + let pipeline_script_option = ' \| cut -f 2,3' let grepformat = '%f:%l%m' let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ a:word . ' -u ' . fuzzy_option . pipeline_script_option + \ word . ' -u ' . fuzzy_option . pipeline_script_option if s:querytype == s:subcmd_map['FileImporter'] let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ a:word . ' -u ' . fuzzy_option + \ word . ' -u ' . fuzzy_option elseif s:querytype == s:subcmd_map['Callee'] || \ s:querytype == s:subcmd_map['Caller'] || \ s:querytype == s:subcmd_map['Member'] let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ a:word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' + \ word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' elseif s:querytype == s:subcmd_map['DefinitionGroup'] echom 'Not Implement !' @@ -239,7 +246,7 @@ function! s:use_unite_menu(magic) \ 'description' : menu_description, \} let g:unite_source_menu_menus.codequery.command_candidates = cmd_candidates - execute 'Unite -start-insert -silent -prompt=::' . cword + execute 'Unite -silent -prompt-visible -prompt=::' . cword \ . ':: menu:codequery' endfunction From 3465ad63ecd8547d5f3a67c5ecf2564d60d098cb Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 13 Aug 2016 00:05:46 +0800 Subject: [PATCH 17/81] add CodeQueryAgain cmd & custom unite magic menu for qf type --- plugin/codequery.vim | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 9f5b98e..682ba49 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -7,6 +7,8 @@ command! -nargs=* -complete=customlist,s:complete_function CodeQuery \ call s:run_codequery() +command! -nargs=* -complete=customlist,s:complete_function CodeQueryAgain + \ call s:run_codequery_again_with_different_subcmd() command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() command! -nargs=0 CodeQueryMoveDBToGitDir @@ -180,6 +182,8 @@ function! s:do_grep(word) finally let &l:grepprg = l:grepprg_bak let &grepformat = l:grepformat_bak + let s:last_query_word = a:word + let s:last_query_fuzzy = s:fuzzy endtry endfunction @@ -197,6 +201,16 @@ function! s:set_options(args) endfunction +function! s:patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) + call map(a:fre_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:fun_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:cla_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:fre_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call map(a:fun_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call map(a:cla_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') +endfunction + + function! s:use_unite_menu(magic) let cword = s:get_valid_cursor_word() let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery']] @@ -218,8 +232,17 @@ function! s:use_unite_menu(magic) let menu_goto_full = [['▷ ', 'CodeQueryMenu Unite Full']] if a:magic + if &filetype ==# 'qf' + call s:patch_unite_magic_menu_from_qf(menu_frequent_cmds, + \ menu_function_cmds, + \ menu_class_cmds) + let menu_other_cmds = [] + let menu_goto_full = [] + let cword = s:last_query_word + endif + let menu_description = 'CodeQuery Smart Menu' - if cword =~ '\C^[A-Z].*' + if cword =~# '\C^[A-Z].*' let cmd_candidates = menu_frequent_cmds \ + menu_class_cmds \ + menu_other_cmds @@ -262,6 +285,7 @@ function! s:run_codequery(args) return endif + let s:last_query_word = '' let s:fuzzy = 0 let s:append_to_quickfix = 0 let s:querytype = 1 @@ -390,6 +414,19 @@ function! s:show_menu(args) endfunction +function! s:run_codequery_again_with_different_subcmd(args) + let args = split(a:args, ' ') + let args_num = len(args) + if !empty(s:last_query_word) && args_num > 0 + cclose + let again_cmd = 'CodeQuery ' . args[0] . ' ' . s:last_query_word . ' ' + \ . (s:last_query_fuzzy ? '-f' : '') + execute again_cmd + else + echom 'Wrong Subcommands!' + endif +endfunction + " ============================================================================= " Debugging From 100ad4317f6d64b9ce429e15c0e05234f0625e5b Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 13 Aug 2016 00:14:09 +0800 Subject: [PATCH 18/81] fix unite menu init bug --- plugin/codequery.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 682ba49..d12778d 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -265,6 +265,9 @@ function! s:use_unite_menu(magic) \ + menu_goto_magic endif + if !exists('g:unite_source_menu_menus') + let g:unite_source_menu_menus = {} + endif let g:unite_source_menu_menus.codequery = { \ 'description' : menu_description, \} From 34f6281e50226ed10b5e3fe3f5f605e94fd7c119 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 13 Aug 2016 00:18:50 +0800 Subject: [PATCH 19/81] fix CodeQueryAgain bug --- plugin/codequery.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index d12778d..041ad98 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -213,7 +213,7 @@ endfunction function! s:use_unite_menu(magic) let cword = s:get_valid_cursor_word() - let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery']] + let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol']] let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], \['▷ Find Call [F]', 'CodeQuery Call'], \['▷ Find Caller [F]', 'CodeQuery Caller'], From 4b733f1bc41681d7330b2b148a3618838fdb9963 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 14 Aug 2016 19:43:20 +0800 Subject: [PATCH 20/81] add CodeQueryFilter command --- plugin/codequery.vim | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 041ad98..9e8f4d0 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -9,6 +9,7 @@ command! -nargs=* -complete=customlist,s:complete_function CodeQuery \ call s:run_codequery() command! -nargs=* -complete=customlist,s:complete_function CodeQueryAgain \ call s:run_codequery_again_with_different_subcmd() +command! -nargs=* CodeQueryFilter call s:filter_qf_results() command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() command! -nargs=0 CodeQueryMoveDBToGitDir @@ -126,6 +127,59 @@ function! s:get_valid_input_word(args) endfunction +function! s:prettify_qf_layout_and_map_keys(results) + if &filetype !=# 'qf' + copen + endif + + " unlock qf to make changes + setlocal modifiable + setlocal nolist + setlocal nowrap + + " delete all the text in qf + silent %delete + + " insert new text with pretty layout + let max_filename_len = 0 + let max_lnum_len = 0 + for d in a:results + let d['filename'] = bufname(d['bufnr']) + let max_filename_len = max([max_filename_len, len(d['filename'])]) + let max_lnum_len = max([max_lnum_len, len(d['lnum'])]) + endfor + let max_filename_len = min([max_filename_len, 70]) + call append('0', map(copy(a:results), 'printf("%-' . max_filename_len . 'S | %' . max_lnum_len . 'S | %s", v:val["filename"], v:val["lnum"], v:val["text"])')) + + " delete empty line + global/^$/delete + + " put the cursor back + normal! gg + + " map shortcuts + nnoremap s :CodeQueryAgain Symbol + nnoremap c :CodeQueryAgain Call + nnoremap r :CodeQueryAgain Caller + nnoremap i :CodeQueryAgain Callee + nnoremap d :CodeQueryAgain Definition + nnoremap C :CodeQueryAgain Class + nnoremap M :CodeQueryAgain Member + nnoremap P :CodeQueryAgain Parent + nnoremap I :CodeQueryAgain Child + nnoremap \ :CodeQueryFilter + + nnoremap p p + nnoremap u :colder \| CodeQueryShowQF + nnoremap :cnewer \| CodeQueryShowQF + + + " lock qf again + setlocal nomodifiable + setlocal nomodified +endfunction + + function! s:do_grep(word) if empty(a:word) echom 'Invalid Search Term: ' . a:word @@ -431,6 +485,20 @@ function! s:run_codequery_again_with_different_subcmd(args) endfunction +" modify from someone's .vimrc +function! s:filter_qf_results(query) + let results = getqflist() + for d in results + if bufname(d['bufnr']) !~ a:query && d['text'] !~ a:query + call remove(results, index(results, d)) + endif + endfor + call setqflist(results) + call s:prettify_qf_layout_and_map_keys(results) +endfunction + + + " ============================================================================= " Debugging From 9d99720a7b444ec06210e882ea587ab9e6a19575 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 14 Aug 2016 19:47:07 +0800 Subject: [PATCH 21/81] add CodeQueryShowQF command & update unite magic menu --- plugin/codequery.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 9e8f4d0..80279f8 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -15,6 +15,7 @@ command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() command! -nargs=0 CodeQueryMoveDBToGitDir \ call s:move_codequery_db_to_git_hidden_dir() command! -nargs=* CodeQueryMenu call s:show_menu() +command! -nargs=0 CodeQueryShowQF call s:prettify_qf_layout_and_map_keys(getqflist()) let s:query_subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', @@ -229,6 +230,7 @@ function! s:do_grep(word) let results = getqflist() if !empty(results) copen + call s:prettify_qf_layout_and_map_keys(results) echom 'Found ' . len(results) . ' results' else echom 'Result Not Found' @@ -262,6 +264,7 @@ function! s:patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) call map(a:fre_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') call map(a:fun_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') call map(a:cla_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call insert(a:fre_cmds, ['▷ Filter', 'call feedkeys(":CodeQueryFilter ")'], -1) endfunction From 0a7f7afcf35495b47f4279c9fb1ba5aa8a5ef6bc Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 14 Aug 2016 21:00:15 +0800 Subject: [PATCH 22/81] keep qf open even no result & refactor --- plugin/codequery.vim | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 80279f8..3c142bb 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -15,7 +15,8 @@ command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() command! -nargs=0 CodeQueryMoveDBToGitDir \ call s:move_codequery_db_to_git_hidden_dir() command! -nargs=* CodeQueryMenu call s:show_menu() -command! -nargs=0 CodeQueryShowQF call s:prettify_qf_layout_and_map_keys(getqflist()) +command! -nargs=0 CodeQueryShowQF call + \ s:prettify_qf_layout_and_map_keys(getqflist()) let s:query_subcommands = [ 'Symbol', \ 'Definition', 'DefinitionGroup', @@ -128,6 +129,7 @@ function! s:get_valid_input_word(args) endfunction +" Ref: MarcWeber's vim-addon-qf-layout function! s:prettify_qf_layout_and_map_keys(results) if &filetype !=# 'qf' copen @@ -142,15 +144,19 @@ function! s:prettify_qf_layout_and_map_keys(results) silent %delete " insert new text with pretty layout - let max_filename_len = 0 + let max_fn_len = 0 let max_lnum_len = 0 for d in a:results let d['filename'] = bufname(d['bufnr']) - let max_filename_len = max([max_filename_len, len(d['filename'])]) + let max_fn_len = max([max_fn_len, len(d['filename'])]) let max_lnum_len = max([max_lnum_len, len(d['lnum'])]) endfor - let max_filename_len = min([max_filename_len, 70]) - call append('0', map(copy(a:results), 'printf("%-' . max_filename_len . 'S | %' . max_lnum_len . 'S | %s", v:val["filename"], v:val["lnum"], v:val["text"])')) + let reasonable_max_len = 60 + let max_fn_len = min([max_fn_len, reasonable_max_len]) + let qf_format = '"%-' . max_fn_len . 'S | %' . max_lnum_len . 'S | %s"' + let evaluating_str = 'printf(' . qf_format . + \ ', v:val["filename"], v:val["lnum"], v:val["text"])' + call append('0', map(a:results, evaluating_str)) " delete empty line global/^$/delete @@ -162,19 +168,18 @@ function! s:prettify_qf_layout_and_map_keys(results) nnoremap s :CodeQueryAgain Symbol nnoremap c :CodeQueryAgain Call nnoremap r :CodeQueryAgain Caller - nnoremap i :CodeQueryAgain Callee + nnoremap y :CodeQueryAgain Callee nnoremap d :CodeQueryAgain Definition nnoremap C :CodeQueryAgain Class nnoremap M :CodeQueryAgain Member nnoremap P :CodeQueryAgain Parent - nnoremap I :CodeQueryAgain Child + nnoremap D :CodeQueryAgain Child nnoremap \ :CodeQueryFilter nnoremap p p nnoremap u :colder \| CodeQueryShowQF nnoremap :cnewer \| CodeQueryShowQF - " lock qf again setlocal nomodifiable setlocal nomodified @@ -198,20 +203,20 @@ function! s:do_grep(word) let pipeline_script_option = ' \| cut -f 2,3' let grepformat = '%f:%l%m' - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ word . ' -u ' . fuzzy_option . pipeline_script_option + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . pipeline_script_option if s:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ word . ' -u ' . fuzzy_option + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option elseif s:querytype == s:subcmd_map['Callee'] || \ s:querytype == s:subcmd_map['Caller'] || \ s:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' . - \ word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' elseif s:querytype == s:subcmd_map['DefinitionGroup'] echom 'Not Implement !' @@ -228,9 +233,8 @@ function! s:do_grep(word) redraw! let results = getqflist() + call s:prettify_qf_layout_and_map_keys(results) if !empty(results) - copen - call s:prettify_qf_layout_and_map_keys(results) echom 'Found ' . len(results) . ' results' else echom 'Result Not Found' @@ -499,11 +503,3 @@ function! s:filter_qf_results(query) call setqflist(results) call s:prettify_qf_layout_and_map_keys(results) endfunction - - - -" ============================================================================= -" Debugging - - -"nnoremap c :CodeQuery From 18dc96a05d7b9f68b7528f1d57cea8dc7a246295 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Sun, 14 Aug 2016 23:44:19 +0800 Subject: [PATCH 23/81] Update README.md --- README.md | 71 +++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index d6815b0..cfb3122 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,45 @@ +![](https://github.com/ruben2020/codequery/raw/master/doc/logotitle.png) + # vim-codequery This Vim plugin is build on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: -1. Do CodeQuery-liked queries. (80% Done, Need to fix some bugs) -2. Manage your database. (TBD, Finished Date: Mid-August) -3. "Know" your code instantly. (TBD, Finished Date: September) - -## Supporting languages -* Python -* Javascript -* Ruby -* C, C++ -* Java -* Go +1. Do CodeQuery-liked queries gracefully whithin Vim. +2. Manage your database easily. +3. "Know" your code instantly. -## Status: ~ Don't Install Me Now ! Please Wait ~ - -> **This project is still under development.** -> -> *Completeness: 40%* - -## Demo - -#### Search Symbol -![](https://dl.dropboxusercontent.com/u/7414946/github/symbol-c.gif) - -#### Search Definition (+ fuzzy option) -![](https://dl.dropboxusercontent.com/u/7414946/github/def-c.gif) - -#### Search Call/Caller/Callee -![](https://dl.dropboxusercontent.com/u/7414946/github/call-c.gif) +## Demo -#### Search Parent/Children -![](https://dl.dropboxusercontent.com/u/7414946/github/pc-c.gif) +Choose a query from menu => Get results -#### Search Class/Member -![](https://dl.dropboxusercontent.com/u/7414946/github/cm-c.gif) +![](https://db.tt/rf6fO2eJ) -#### Search FileImporter -![](https://dl.dropboxusercontent.com/u/7414946/github/fi-c.gif) +Switch to different query => Get results => Filter them => Get Results => Undo/ReDo ... -#### Search FunctionList -![](https://dl.dropboxusercontent.com/u/7414946/github/fl-c.gif) +![](https://db.tt/KoZORec3) + +(more demo and screenshots) -#### [Not Implemented] Search DefinitionGroup +## Supported languages -#### [Not Implemented] Search Tag +> **This project is still under development.** +> Completeness: 70% -#### [Not Implemented] Menu +* [X] Python (in beta, give it a try!) +* [ ] Javascript (coming soon) +* [ ] Ruby (coming soon) +* [ ] Go (coming soon) +* [ ] Java (coming later) +* [ ] C, C++ (coming very later) -#### [Not Implemented] Switch +## Installation -#### [Not Implemented] LoadDB/BuildDB +## Usage -#### [Not Implemented] Analyze +## Tips -## Usage +## FAQ -## Installation +## How can I contribute? -## Tips +## Credits From 36b9d65c6f4a3688a0101731698b6287018634a3 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Wed, 17 Aug 2016 19:54:28 +0800 Subject: [PATCH 24/81] Update README.md --- README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cfb3122..63757d9 100644 --- a/README.md +++ b/README.md @@ -2,35 +2,44 @@ # vim-codequery -This Vim plugin is build on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: +This Vim plugin is built on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: -1. Do CodeQuery-liked queries gracefully whithin Vim. -2. Manage your database easily. -3. "Know" your code instantly. +1. **Search source code gracefully within Vim**. + * You can find: `definition, call, caller, callee, symbol, class, parent, child` and more. + * Well-formated results are shown in a custom Quickfix window. (usable key bindings are also ready!) + * Supported languages + * [X] `Python` (in beta: **give it a try!**) + * [ ] `Javascript` (coming soon) + * [ ] `Ruby` (coming soon) + * [ ] `Go` (coming soon) + * [ ] `Java` (coming later) + * [ ] `C, C++` (coming very later) +2. **Manage your database easily**. + * Load, make and move your database file by custom Vim commands. + * `Note: CodeQuery's SQLite database file is built on top of ctags and cscope.` +3. **Know your code instantly**. + * (This killer feature will be implemented in September) ## Demo -Choose a query from menu => Get results +`Choose a query from menu ➙ Get results` ![](https://db.tt/rf6fO2eJ) -Switch to different query => Get results => Filter them => Get Results => Undo/ReDo ... +`... ➙Switch to different query ➙ Get results ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` ![](https://db.tt/KoZORec3) (more demo and screenshots) -## Supported languages +## Schedule -> **This project is still under development.** +> **This project is still under development.** > Completeness: 70% - -* [X] Python (in beta, give it a try!) -* [ ] Javascript (coming soon) -* [ ] Ruby (coming soon) -* [ ] Go (coming soon) -* [ ] Java (coming later) -* [ ] C, C++ (coming very later) +> Release Date of First Version: Mid-September +> +> If you are a pythoner, it is ready for you to use. Try it! +> This plugin will support javascript/ruby/go ASAP. ## Installation From 9db6ed9f186ff30072a2c3ceff024c9a12c1e3a9 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Thu, 18 Aug 2016 11:22:48 +0800 Subject: [PATCH 25/81] Update README.md --- README.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 63757d9..f207c17 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,29 @@ ![](https://github.com/ruben2020/codequery/raw/master/doc/logotitle.png) - + + + +> Just choose what you want to know! 😼 + # vim-codequery - + This Vim plugin is built on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: 1. **Search source code gracefully within Vim**. - * You can find: `definition, call, caller, callee, symbol, class, parent, child` and more. - * Well-formated results are shown in a custom Quickfix window. (usable key bindings are also ready!) - * Supported languages - * [X] `Python` (in beta: **give it a try!**) - * [ ] `Javascript` (coming soon) - * [ ] `Ruby` (coming soon) - * [ ] `Go` (coming soon) - * [ ] `Java` (coming later) - * [ ] `C, C++` (coming very later) + * You can find: `definition, call, caller, callee, symbol, class, parent, child` and more for a string. + * Well-formated results are shown in a custom Quickfix window with usable key bindings. 2. **Manage your database easily**. * Load, make and move your database file by custom Vim commands. - * `Note: CodeQuery's SQLite database file is built on top of ctags and cscope.` -3. **Know your code instantly**. - * (This killer feature will be implemented in September) + * `Note: CodeQuery's SQLite database is built on top of ctags and cscope.` +3. **Know your code more instantly**. + * (TBD) + +## Supported languages + * [X] `Python` (in beta: **give it a try! 😎**) + * [ ] `Javascript` (coming soon) + * [ ] `Ruby` (coming soon) + * [ ] `Go` (coming soon) + * [ ] `Java` (coming later) + * [ ] `C, C++` (coming very later) ## Demo @@ -26,19 +31,20 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ![](https://db.tt/rf6fO2eJ) -`... ➙Switch to different query ➙ Get results ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` +`... ➙ Switch to different query ➙ Get results ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` ![](https://db.tt/KoZORec3) -(more demo and screenshots) +[more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) ## Schedule > **This project is still under development.** +> > Completeness: 70% > Release Date of First Version: Mid-September > -> If you are a pythoner, it is ready for you to use. Try it! +> If you are a pythoner, it is ready for you to use. Try it! > This plugin will support javascript/ruby/go ASAP. ## Installation From 4a865a09420343b69d9999156e05660c9962cdba Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Thu, 18 Aug 2016 16:40:29 +0800 Subject: [PATCH 26/81] Update README.md --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f207c17..70c3367 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ -> Just choose what you want to know! 😼 +> Choose what you want to know! 😼 +   # vim-codequery This Vim plugin is built on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: @@ -31,7 +32,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ![](https://db.tt/rf6fO2eJ) -`... ➙ Switch to different query ➙ Get results ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` +`... ➙ Switch to different query ➙ Get results ... ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` ![](https://db.tt/KoZORec3) @@ -42,13 +43,51 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > **This project is still under development.** > > Completeness: 70% -> Release Date of First Version: Mid-September +> v1.0 Release Date: Mid-September > > If you are a pythoner, it is ready for you to use. Try it! > This plugin will support javascript/ruby/go ASAP. ## Installation +### 1. Make sure these commands are in your system +
+echo mkdir mv cut find awk stat git(optional)
+
+ +### 2. Install CodeQuery +* Follow installation guide in [CodeQuery project](https://github.com/ruben2020/codequery#how-to-install-it). +* Enter `cqsearch -h` in your terminal and view the result. Make sure `cqsearch` accepts `-u` option. + +> If not, you will have to pull latest CodeQuery code and then [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md) yourself. + + +### 3. Install additional ctags/cscope tools for your languages +| Language | Tools | How to install | +| --- | --- | --- | +| Python | [PyCscope](https://github.com/portante/pycscope) | `sudo pip install pycscope` | +| Javascript | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | +| Ruby | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | +| Go | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | +| Java | N/A | +| C | N/A | +| C++ | N/A | + +> Starscope has been [packaged for Arch Linux](https://aur.archlinux.org/packages/ruby-starscope/) + +### 4. Install Vim plugins +* Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim) ... +* Take Plug as an example: + +
+" Highly Recommemded => it helps Vim-CodeQuery to build DB  asynchrously without blocking Vim
+Plug 'tpope/vim-dispatch'  
+" Highly Recommemded => if you want to use built-in Unite menu
+Plug 'Shougo/unite.vim'  
+" The Must Have One
+Plug 'devjoe/vim-codequery'
+
+ ## Usage ## Tips From dadc0d442741a5a1277ad96c1b591df1981381f3 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Thu, 18 Aug 2016 20:16:39 +0800 Subject: [PATCH 27/81] Update README.md --- README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 70c3367..99dc5d1 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,10 @@ > Choose what you want to know! 😼 - -   + +
+
+ # vim-codequery This Vim plugin is built on top of the great tool [CodeQuery](https://github.com/ruben2020/codequery) created by ruben2020, and aims at providing three primary functions to help you to: @@ -50,19 +52,19 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ## Installation -### 1. Make sure these commands are in your system +#### 1. Make sure these commands are in your system
 echo mkdir mv cut find awk stat git(optional)
 
-### 2. Install CodeQuery +#### 2. Install CodeQuery * Follow installation guide in [CodeQuery project](https://github.com/ruben2020/codequery#how-to-install-it). * Enter `cqsearch -h` in your terminal and view the result. Make sure `cqsearch` accepts `-u` option. > If not, you will have to pull latest CodeQuery code and then [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md) yourself. -### 3. Install additional ctags/cscope tools for your languages +#### 3. Install additional ctags/cscope tools for your languages | Language | Tools | How to install | | --- | --- | --- | | Python | [PyCscope](https://github.com/portante/pycscope) | `sudo pip install pycscope` | @@ -75,20 +77,22 @@ echo mkdir mv cut find awk stat git(optional) > Starscope has been [packaged for Arch Linux](https://aur.archlinux.org/packages/ruby-starscope/) -### 4. Install Vim plugins +#### 4. Install Vim plugins * Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim) ... * Take Plug as an example: -
-" Highly Recommemded => it helps Vim-CodeQuery to build DB  asynchrously without blocking Vim
+```vim
+" Highly Recommemded => it helps Vim-CodeQuery to build DB asynchrously without blocking Vim
 Plug 'tpope/vim-dispatch'  
 " Highly Recommemded => if you want to use built-in Unite menu
 Plug 'Shougo/unite.vim'  
 " The Must Have One
 Plug 'devjoe/vim-codequery'
-
+``` -## Usage +## Basic Usage + +## Commnads ## Tips From fd2d8e16c5b330f6a83e4e13df015d1614673d8c Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 19 Aug 2016 00:23:30 +0800 Subject: [PATCH 28/81] Update README.md --- README.md | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 144 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 99dc5d1..2cebb0e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com 1. **Search source code gracefully within Vim**. * You can find: `definition, call, caller, callee, symbol, class, parent, child` and more for a string. + * Convenient menus are created for you. * Well-formated results are shown in a custom Quickfix window with usable key bindings. 2. **Manage your database easily**. * Load, make and move your database file by custom Vim commands. @@ -20,6 +21,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com 3. **Know your code more instantly**. * (TBD) +
+ ## Supported languages * [X] `Python` (in beta: **give it a try! 😎**) * [ ] `Javascript` (coming soon) @@ -28,6 +31,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com * [ ] `Java` (coming later) * [ ] `C, C++` (coming very later) +
+ ## Demo `Choose a query from menu ➙ Get results` @@ -39,7 +44,9 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ![](https://db.tt/KoZORec3) [more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) - + +
+ ## Schedule > **This project is still under development.** @@ -48,8 +55,10 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > v1.0 Release Date: Mid-September > > If you are a pythoner, it is ready for you to use. Try it! -> This plugin will support javascript/ruby/go ASAP. - +> This plugin will support Javascript/Ruby/Go ASAP. + +
+ ## Installation #### 1. Make sure these commands are in your system @@ -77,27 +86,151 @@ echo mkdir mv cut find awk stat git(optional) > Starscope has been [packaged for Arch Linux](https://aur.archlinux.org/packages/ruby-starscope/) -#### 4. Install Vim plugins -* Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim) ... +### 4. Install Vim plugins +* Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim), ... * Take Plug as an example: - ```vim -" Highly Recommemded => it helps Vim-CodeQuery to build DB asynchrously without blocking Vim +" Highly Recommemded => it helps Vim-CodeQuery to build DBasynchrously without blocking Vim Plug 'tpope/vim-dispatch' -" Highly Recommemded => if you want to use built-in Unite menu + +" Highly Recommemded => if you want to use Unite menu Plug 'Shougo/unite.vim' + " The Must Have One Plug 'devjoe/vim-codequery' ``` -## Basic Usage +
+ +## Usage + +#### 1. Setup + +* Go to the (git) root directory of your project. Then open an arbitrary file with the same file type you want to index under the current directory. For example: +
+readme.md
+setup.py
+foldA
+├── a.py
+├── b.py 
+└── c.py
+
+In this Python project, you can use `vim setup.py` to open a Python file and then call `:CodeQueryMakeDB` to make CodeQuery DB. If there is no Python file in root directory, you can temporarily open a new one. (like `vim tmp.py`) +* When the DB file `python.db` (or xxxx.db) and related ctags and cscope files are created, it's ready for you to do searching! + * Call `:CodeQueryMakeDB` again to update the DB file if you need. + * Vim-CodeQuery will not clean ctags and cscope files, you can use them if you need. +* Furthermore, if you are also under a git repository, it's recommended you to use `:CodeQueryMoveDBToGitDir` to hide the DB file under `.git/codequery/` directory. If you do so, next time you can call `:CodeQueryMakeDB` in any Python file under the repository to update the DB file. + +#### 2. Search +* **Find symbol under cursor** + +```vim +:CodeQuery +``` + +* **Find `?` under cursor** + +```vim +:CodeQuery [SubCommand] + +" Supported SubCommands are: `Symbol, Call, Caller, Callee, Class, Parent, Child, Member, FunctionList, FileImporter`. +``` + +* **Find arbitrary word** + +```vim +:CodeQuery [SubCommand] [word] +``` + +* **Find `?` again with the same word** + +```vim +:CodeQueryAgain [SubCommand] +``` + +* **With fuzzy Option** + +```vim +:CodeQuery [SubCommand] [word] -f + +" [word] can be: get_* or *user_info or find_*_by_id +``` + +* **With append Option** (results will be added to current Quickfix) -## Commnads +```vim +:CodeQuery [SubCommand] [word] -a +``` +* **Filter Search Results** + +```vim +:CodeQueryFilter [string] + +" [string] can be a regex +``` + +#### 3. Use Quickfix +* **Move inside Quickfix window to use these key bindings** + +| Key | Action | Note | +| --- | --- | --- | +| s | `:CodeQueryAgain Symbol` | +| c | `:CodeQueryAgain Call` | +| r | `:CodeQueryAgain Caller` | +| y | `:CodeQueryAgain Callee` | +| d | `:CodeQueryAgain Definition` | +| C | `:CodeQueryAgain Class` | +| M | `:CodeQueryAgain Member` | +| P | `:CodeQueryAgain Parent` | +| D | `:CodeQueryAgain Child` | +| \ | `:CodeQueryFilter` | +| p | `p` | Preview +| u | `:colder \| CodeQueryShowQF` | Older Quickfix Result +| \ | `:cnewer \| CodeQueryShowQF` | Newer Quickfix Result + + +* **Show Quickfix with above key bindings** + +```vim +:CodeQueryShowQF + +" This command also works for standard Quickfix result +``` + +#### 4. Open Menu + +Currently, Vim-CodeQuery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot. There are two types of menu: + +* **Open a complete Unite menu** + +```vim +:CodeQueryMenu Unite Full + +" The string between :: and :: is the word under cursor +" [F] means this action is for 'function variable only' +" [C] is for 'class variable only' +``` + + +* **Open a necessary Unite menu** + +```vim +:CodeQueryMenu Unite Magic + +" This menu changes dynamically: +" 1. Word under cursor is capital (possible be class): remove [F] actions +" 2. Word under cursor is non-capital (possible be function): remove [C] actions +" 3. Show reasonable actions only within Quickfix +``` + + +
+ ## Tips ## FAQ -## How can I contribute? +## How to Contribute ## Credits From 483c180ae543962b940af8d4e9634e046822f2a4 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 28 Aug 2016 20:20:30 +0800 Subject: [PATCH 29/81] change and add qf keybindings --- plugin/codequery.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 3c142bb..2d3d489 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -168,12 +168,15 @@ function! s:prettify_qf_layout_and_map_keys(results) nnoremap s :CodeQueryAgain Symbol nnoremap c :CodeQueryAgain Call nnoremap r :CodeQueryAgain Caller - nnoremap y :CodeQueryAgain Callee + nnoremap e :CodeQueryAgain Callee nnoremap d :CodeQueryAgain Definition nnoremap C :CodeQueryAgain Class nnoremap M :CodeQueryAgain Member nnoremap P :CodeQueryAgain Parent nnoremap D :CodeQueryAgain Child + + nnoremap m :CodeQueryMenu Unite Magic + nnoremap q :cclose nnoremap \ :CodeQueryFilter nnoremap p p From 287143c638e49f578f197db952fc03b9caffa053 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 28 Aug 2016 20:37:01 +0800 Subject: [PATCH 30/81] correct readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2cebb0e..363f2d5 100644 --- a/README.md +++ b/README.md @@ -86,11 +86,11 @@ echo mkdir mv cut find awk stat git(optional) > Starscope has been [packaged for Arch Linux](https://aur.archlinux.org/packages/ruby-starscope/) -### 4. Install Vim plugins +#### 4. Install Vim plugins * Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim), ... * Take Plug as an example: ```vim -" Highly Recommemded => it helps Vim-CodeQuery to build DBasynchrously without blocking Vim +" Highly Recommemded => it helps Vim-CodeQuery to build DB asynchrously without blocking Vim Plug 'tpope/vim-dispatch' " Highly Recommemded => if you want to use Unite menu From 7e0d2a41f7f2f3868d285c5dd4a7f6fc788f7857 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 28 Aug 2016 20:39:11 +0800 Subject: [PATCH 31/81] add Show QF in menu --- plugin/codequery.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 2d3d489..95dfde3 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -292,6 +292,7 @@ function! s:use_unite_menu(magic) let menu_db_cmds = [['▷ Make DB', 'CodeQueryMakeDB'], \['▷ View DB', 'CodeQueryViewDB'], \['▷ Move DB', 'CodeQueryMoveDBToGitDir']] + let menu_show_qf = [['▷ Show QF', 'CodeQueryShowQF']] let menu_goto_magic = [['▷ ', 'CodeQueryMenu Unite Magic']] let menu_goto_full = [['▷ ', 'CodeQueryMenu Unite Full']] @@ -305,16 +306,18 @@ function! s:use_unite_menu(magic) let cword = s:last_query_word endif - let menu_description = 'CodeQuery Smart Menu' + let menu_description = 'CodeQuery Magic Menu' if cword =~# '\C^[A-Z].*' let cmd_candidates = menu_frequent_cmds \ + menu_class_cmds \ + menu_other_cmds + \ + menu_show_qf \ + menu_goto_full else let cmd_candidates = menu_frequent_cmds \ + menu_function_cmds \ + menu_other_cmds + \ + menu_show_qf \ + menu_goto_full endif else @@ -326,6 +329,7 @@ function! s:use_unite_menu(magic) \ + menu_delimiter \ + menu_db_cmds \ + menu_delimiter + \ + menu_show_qf \ + menu_goto_magic endif From a3146e7ecda63a1a4d93e34b58c0aa734fc7b1a1 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 29 Aug 2016 01:40:08 +0800 Subject: [PATCH 32/81] make DB related commands simpler --- plugin/codequery.vim | 162 +++++++++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 66 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 95dfde3..0a2a624 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -10,10 +10,10 @@ command! -nargs=* -complete=customlist,s:complete_function CodeQuery command! -nargs=* -complete=customlist,s:complete_function CodeQueryAgain \ call s:run_codequery_again_with_different_subcmd() command! -nargs=* CodeQueryFilter call s:filter_qf_results() -command! -nargs=0 CodeQueryMakeDB call s:make_codequery_db() -command! -nargs=0 CodeQueryViewDB call s:view_codequery_db() -command! -nargs=0 CodeQueryMoveDBToGitDir - \ call s:move_codequery_db_to_git_hidden_dir() +command! -nargs=* CodeQueryMakeDB call s:make_codequery_db() +command! -nargs=* CodeQueryViewDB call s:view_codequery_db() +command! -nargs=* CodeQueryMoveDBToGitDir + \ call s:move_codequery_db_to_git_hidden_dir() command! -nargs=* CodeQueryMenu call s:show_menu() command! -nargs=0 CodeQueryShowQF call \ s:prettify_qf_layout_and_map_keys(getqflist()) @@ -51,10 +51,10 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'DefinitionGroup' : 20 } -function! s:check_filetype() +function! s:check_filetype(filetype) let supported_filetypes = \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] - if index(supported_filetypes, &filetype) == -1 + if index(supported_filetypes, a:filetype) == -1 return 0 endif return 1 @@ -62,8 +62,8 @@ endfunction " `lcd` brings side effect !! -function! s:find_db_path() - let db_name = &filetype . '.db' +function! s:find_db_path(filetype) + let db_name = a:filetype . '.db' let lookup_path = findfile(expand('%:h') . '/' . db_name, '.') if !empty(lookup_path) @@ -91,7 +91,7 @@ endfunction function! s:set_db() - let path = s:find_db_path() + let path = s:find_db_path(&filetype) if empty(path) echom 'CodeQuery DB Not Found' return 0 @@ -102,6 +102,25 @@ function! s:set_db() endfunction +function! s:construct_python_db_build_cmd(db_path) + let cscope_file = 'python_cscope.files' + let cscopeout_file = 'python_cscope.out' + let tags_file = 'python_tags' + + let find_cmd = 'find . -iname "*.py" > ' . cscope_file + let pycscope_cmd = 'pycscope -f "' . cscopeout_file . '" -i ' . cscope_file + let ctags_cmd = 'ctags --fields=+i -n -R -f "' . + \ tags_file . '" -L ' . cscope_file + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c ' . cscopeout_file . + \ ' -t ' . tags_file . ' -p' + let shell_cmd = find_cmd . ' && ' . + \ pycscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + return shell_cmd +endfunction + + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -289,9 +308,9 @@ function! s:use_unite_menu(magic) let menu_other_cmds = [['▷ List Function', 'CodeQuery FunctionList'], \['▷ List Imports', 'CodeQuery FileImporter']] let menu_delimiter = [['* ------------------------- *', '']] - let menu_db_cmds = [['▷ Make DB', 'CodeQueryMakeDB'], - \['▷ View DB', 'CodeQueryViewDB'], - \['▷ Move DB', 'CodeQueryMoveDBToGitDir']] + let menu_db_cmds = [['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ")'], + \['▷ View DB', 'call feedkeys(":CodeQueryViewDB ")'], + \['▷ Move DB', 'call feedkeys(":CodeQueryMoveDBToGitDir ")']] let menu_show_qf = [['▷ Show QF', 'CodeQueryShowQF']] let menu_goto_magic = [['▷ ', 'CodeQueryMenu Unite Magic']] let menu_goto_full = [['▷ ', 'CodeQueryMenu Unite Full']] @@ -351,7 +370,7 @@ endfunction function! s:run_codequery(args) - if !s:check_filetype() + if !s:check_filetype(&filetype) echom 'Not Supported Filetype: ' . &filetype return endif @@ -394,74 +413,85 @@ function! s:run_codequery(args) endfunction -function! s:make_codequery_db() - if !s:check_filetype() - echom 'Not Supported Filetype: ' . &filetype - return +function! s:make_codequery_db(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] endif - let db_path = s:find_db_path() - if empty(db_path) - let db_path = &filetype . '.db' - endif + for ft in args + if !s:check_filetype(ft) + echom 'Not Supported Filetype: ' . ft + continue + endif - " TODO: refactor later --------------- - let cscope_file = &filetype . '_cscope.files' - let cscopeout_file = &filetype . '_cscope.out' - let tags_file = &filetype . '_tags' + let db_path = s:find_db_path(ft) + if empty(db_path) + let db_path = ft . '.db' + endif - let find_cmd = 'find . -iname "*.py" > ' . cscope_file - let pycscope_cmd = 'pycscope -f "' . cscopeout_file . '" -i ' . cscope_file - let ctags_cmd = 'ctags --fields=+i -n -R -f "' . - \ tags_file . '" -L ' . cscope_file - let cqmakedb_cmd = 'cqmakedb -s "' . db_path . '" -c ' . cscopeout_file . - \ ' -t ' . tags_file . ' -p' - let shell_cmd = find_cmd . ' && ' . - \ pycscope_cmd . ' && ' . - \ ctags_cmd . ' && ' . - \ cqmakedb_cmd - " ------------------------------------ + if ft ==? 'python' + let shell_cmd = s:construct_python_db_build_cmd(db_path) + else + echom 'No Command For Building ' . ft . ' DB' + continue + endif - if exists(':Start') - silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd - redraw! - echom 'Run :CodeQueryViewDB to Check Status' - else - silent execute '!' . shell_cmd - redraw! - endif + if exists(':Start') + silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd + redraw! + echom 'Making ' . db_path ' => Run :CodeQueryViewDB to Check Status' + else + silent execute '!' . shell_cmd + redraw! + endif + endfor endfunction -function! s:view_codequery_db() - " TODO: remove duplicated filetype checking code - if !s:check_filetype() - echom 'Not Supported Filetype: ' . &filetype - return +function! s:view_codequery_db(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] endif - let db_path = s:find_db_path() - if empty(db_path) - echom 'DB not Found' - endif + for ft in args + if !s:check_filetype(ft) + echom 'Not Supported Filetype: ' . ft + continue + endif - execute '!echo "\nYour DB is update at: " && stat -f "\%Sm" ' . db_path -endfunction + let db_path = s:find_db_path(ft) + if empty(db_path) + execute '!echo "\n(' . ft . ') DB Not Found"' + continue + endif + execute '!echo "\n(' . db_path . ') is update at: " && stat -f "\%Sm" ' . db_path + endfor +endfunction -function! s:move_codequery_db_to_git_hidden_dir() - let db_name = &filetype . '.db' - let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] - let db_path = s:find_db_path() - if !v:shell_error && !empty(db_path) - let new_db_path = git_root_dir . '/.git/codequery/' . db_name - call system('mkdir -p ' . git_root_dir . '/.git/codequery/') - call system('mv ' . db_path . ' ' . new_db_path) - echom 'Done' - else - echom 'Git Dir Not Found or DB Not Found' +function! s:move_codequery_db_to_git_hidden_dir(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] endif + + for ft in args + let db_name = ft . '.db' + let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] + let db_path = s:find_db_path(ft) + + if !v:shell_error && !empty(db_path) + let new_db_path = git_root_dir . '/.git/codequery/' . db_name + call system('mkdir -p ' . git_root_dir . '/.git/codequery/') + call system('mv ' . db_path . ' ' . new_db_path) + echom '(' . ft . ') DB Done' + else + echom 'Git Dir Not Found or (' . ft . ') DB Not Found' + endif + endfor endfunction From 46ce689d4c32fe71667fc981078bb22e33d529d4 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Aug 2016 13:54:05 +0800 Subject: [PATCH 33/81] update menu --- plugin/codequery.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 0a2a624..0694999 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -311,9 +311,10 @@ function! s:use_unite_menu(magic) let menu_db_cmds = [['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ")'], \['▷ View DB', 'call feedkeys(":CodeQueryViewDB ")'], \['▷ Move DB', 'call feedkeys(":CodeQueryMoveDBToGitDir ")']] - let menu_show_qf = [['▷ Show QF', 'CodeQueryShowQF']] - let menu_goto_magic = [['▷ ', 'CodeQueryMenu Unite Magic']] - let menu_goto_full = [['▷ ', 'CodeQueryMenu Unite Full']] + let menu_show_qf = [['▷ Show QF ▲', 'CodeQueryShowQF'], + \['▷ Hide QF ▼', 'cclose']] + let menu_goto_magic = [['▷ Open Magic Menu ▸', 'CodeQueryMenu Unite Magic']] + let menu_goto_full = [['▷ Open Full Menu ▸', 'CodeQueryMenu Unite Full']] if a:magic if &filetype ==# 'qf' From 388f18799f2286608b241a294ffbb67ceb5580b9 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Aug 2016 18:35:53 +0800 Subject: [PATCH 34/81] fix no last_query_word bug --- plugin/codequery.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 0694999..1ccab69 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -323,7 +323,9 @@ function! s:use_unite_menu(magic) \ menu_class_cmds) let menu_other_cmds = [] let menu_goto_full = [] - let cword = s:last_query_word + if exists('s:last_query_word') + let cword = s:last_query_word + endif endif let menu_description = 'CodeQuery Magic Menu' From ca1253b6fe5802e948b5d8d14f60da2cb2458096 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Aug 2016 19:43:46 +0800 Subject: [PATCH 35/81] add Text subcommand --- plugin/codequery.vim | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 1ccab69..03719e9 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -1,6 +1,13 @@ " Copyright (c) 2016 excusemejoe " MIT License +" ============================================================================= +" Options + +let g:codequery_text_cmd = 'Ack!' + + + " ============================================================================= " Menu @@ -18,7 +25,7 @@ command! -nargs=* CodeQueryMenu call s:show_menu() command! -nargs=0 CodeQueryShowQF call \ s:prettify_qf_layout_and_map_keys(getqflist()) -let s:query_subcommands = [ 'Symbol', +let s:query_subcommands = [ 'Symbol', 'Text', \ 'Definition', 'DefinitionGroup', \ 'Caller', 'Callee', 'Call', \ 'Class', 'Member', 'Parent', 'Child', @@ -47,7 +54,8 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'Parent' : 12, \ 'Child' : 11, \ 'FunctionList' : 13, - \ 'FileImporter' : 4 , + \ 'FileImporter' : 4, + \ 'Text' : 21, \ 'DefinitionGroup' : 20 } @@ -185,6 +193,7 @@ function! s:prettify_qf_layout_and_map_keys(results) " map shortcuts nnoremap s :CodeQueryAgain Symbol + nnoremap x :CodeQueryAgain Text nnoremap c :CodeQueryAgain Call nnoremap r :CodeQueryAgain Caller nnoremap e :CodeQueryAgain Callee @@ -229,17 +238,23 @@ function! s:do_grep(word) \ . word . ' -u ' . fuzzy_option . pipeline_script_option if s:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' \ . word . ' -u ' . fuzzy_option elseif s:querytype == s:subcmd_map['Callee'] || \ s:querytype == s:subcmd_map['Caller'] || \ s:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' + elseif s:querytype == s:subcmd_map['Text'] + silent execute g:codequery_text_cmd . ' ' . a:word + call s:prettify_qf_layout_and_map_keys(getqflist()) + + let s:last_query_word = a:word + let s:last_query_fuzzy = s:fuzzy + return + elseif s:querytype == s:subcmd_map['DefinitionGroup'] echom 'Not Implement !' return @@ -290,13 +305,14 @@ function! s:patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) call map(a:fre_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') call map(a:fun_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') call map(a:cla_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') - call insert(a:fre_cmds, ['▷ Filter', 'call feedkeys(":CodeQueryFilter ")'], -1) + call insert(a:fre_cmds, ['▷ Filter', 'call feedkeys(":CodeQueryFilter ")'], 0) endfunction function! s:use_unite_menu(magic) let cword = s:get_valid_cursor_word() - let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol']] + let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol'], + \['▷ Find Text', 'CodeQuery Text']] let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], \['▷ Find Call [F]', 'CodeQuery Call'], \['▷ Find Caller [F]', 'CodeQuery Caller'], From b2159e235d343dc4b32ae8cd461a9cde63f66bd5 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Aug 2016 20:14:20 +0800 Subject: [PATCH 36/81] avoid opening full menu in QF --- plugin/codequery.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 03719e9..b5c7072 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -359,6 +359,10 @@ function! s:use_unite_menu(magic) \ + menu_goto_full endif else + if &filetype ==# 'qf' + echom 'Can Not Open Full Menu In QF (Use Magic Menu)' + return + endif let menu_description = 'CodeQuery Full Menu' let cmd_candidates = menu_frequent_cmds \ + menu_function_cmds From 895fb21e26d8b83487aee3c981f66da00a140d43 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 1 Sep 2016 12:00:09 +0800 Subject: [PATCH 37/81] support javascript --- plugin/codequery.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index b5c7072..edda233 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -129,6 +129,17 @@ function! s:construct_python_db_build_cmd(db_path) endfunction +function! s:construct_javascript_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.js' + let rename_cmd = 'mv tags javascript_tags && mv cscope.out javascript_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./javascript_cscope.out -t ./javascript_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + return shell_cmd +endfunction + + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -455,6 +466,8 @@ function! s:make_codequery_db(args) if ft ==? 'python' let shell_cmd = s:construct_python_db_build_cmd(db_path) + elseif ft ==? 'javascript' + let shell_cmd = s:construct_javascript_db_build_cmd(db_path) else echom 'No Command For Building ' . ft . ' DB' continue From 003e8c3888bb0c5e74056b6ca7656b945278310a Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 1 Sep 2016 12:15:41 +0800 Subject: [PATCH 38/81] refactor s:construct_python_db_build_cmd() --- plugin/codequery.vim | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index edda233..ed54e48 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -111,16 +111,11 @@ endfunction function! s:construct_python_db_build_cmd(db_path) - let cscope_file = 'python_cscope.files' - let cscopeout_file = 'python_cscope.out' - let tags_file = 'python_tags' - - let find_cmd = 'find . -iname "*.py" > ' . cscope_file - let pycscope_cmd = 'pycscope -f "' . cscopeout_file . '" -i ' . cscope_file - let ctags_cmd = 'ctags --fields=+i -n -R -f "' . - \ tags_file . '" -L ' . cscope_file - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c ' . cscopeout_file . - \ ' -t ' . tags_file . ' -p' + let find_cmd = 'find . -iname "*.py" > python_cscope.files' + let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' + let ctags_cmd = 'ctags --fields=+i -n -R -f "python_tags" -L python_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c python_cscope.out' . + \ ' -t python_tags -p' let shell_cmd = find_cmd . ' && ' . \ pycscope_cmd . ' && ' . \ ctags_cmd . ' && ' . From 8e95a096cccfd1f94af0f8fb5824683d106cfd64 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 1 Sep 2016 12:35:55 +0800 Subject: [PATCH 39/81] support ruby and go --- plugin/codequery.vim | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index ed54e48..deb803e 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -135,6 +135,28 @@ function! s:construct_javascript_db_build_cmd(db_path) endfunction +function! s:construct_ruby_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.rb' + let rename_cmd = 'mv tags ruby_tags && mv cscope.out ruby_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./ruby_cscope.out -t ./ruby_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + return shell_cmd +endfunction + + +function! s:construct_go_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.go' + let rename_cmd = 'mv tags go_tags && mv cscope.out go_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./go_cscope.out -t ./go_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + return shell_cmd +endfunction + + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -463,6 +485,10 @@ function! s:make_codequery_db(args) let shell_cmd = s:construct_python_db_build_cmd(db_path) elseif ft ==? 'javascript' let shell_cmd = s:construct_javascript_db_build_cmd(db_path) + elseif ft ==? 'ruby' + let shell_cmd = s:construct_ruby_db_build_cmd(db_path) + elseif ft ==? 'go' + let shell_cmd = s:construct_go_db_build_cmd(db_path) else echom 'No Command For Building ' . ft . ' DB' continue @@ -518,7 +544,7 @@ function! s:move_codequery_db_to_git_hidden_dir(args) let new_db_path = git_root_dir . '/.git/codequery/' . db_name call system('mkdir -p ' . git_root_dir . '/.git/codequery/') call system('mv ' . db_path . ' ' . new_db_path) - echom '(' . ft . ') DB Done' + echom 'Done (' . ft . ')' else echom 'Git Dir Not Found or (' . ft . ') DB Not Found' endif From c862dbf0eb22c420c945a1847dc0b13642fcea58 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 1 Sep 2016 17:16:18 +0800 Subject: [PATCH 40/81] support custom db building cmds & fix path bug (open vim without file) --- plugin/codequery.vim | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index deb803e..08ce22b 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -4,7 +4,15 @@ " ============================================================================= " Options -let g:codequery_text_cmd = 'Ack!' +" Init with default value +let g:codequery_find_text_cmd = 'Ack!' + + +" No need to init +"let g:codequery_build_python_db_cmd = '' +"let g:codequery_build_javascript_db_cmd = '' +"let g:codequery_build_ruby_db_cmd = '' +"let g:codequery_build_go_db_cmd = '' @@ -72,14 +80,14 @@ endfunction " `lcd` brings side effect !! function! s:find_db_path(filetype) let db_name = a:filetype . '.db' - let lookup_path = findfile(expand('%:h') . '/' . db_name, '.') + let lookup_path = findfile(expand('%:p:h') . '/' . db_name, '.') if !empty(lookup_path) - lcd %:h + lcd %:p:h return lookup_path endif - lcd %:h + lcd %:p:h let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] if !v:shell_error let lookup_path = findfile(git_root_dir . '/' . db_name, '.') @@ -120,7 +128,8 @@ function! s:construct_python_db_build_cmd(db_path) \ pycscope_cmd . ' && ' . \ ctags_cmd . ' && ' . \ cqmakedb_cmd - return shell_cmd + + return exists('g:codequery_build_python_db_cmd') ? g:codequery_build_python_db_cmd : shell_cmd endfunction @@ -131,7 +140,8 @@ function! s:construct_javascript_db_build_cmd(db_path) \ '" -c ./javascript_cscope.out -t ./javascript_tags -p' let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - return shell_cmd + + return exists('g:codequery_build_javascript_db_cmd') ? g:codequery_build_javascript_db_cmd : shell_cmd endfunction @@ -142,7 +152,7 @@ function! s:construct_ruby_db_build_cmd(db_path) \ '" -c ./ruby_cscope.out -t ./ruby_tags -p' let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - return shell_cmd + return exists('g:codequery_build_ruby_db_cmd') ? g:codequery_build_ruby_db_cmd : shell_cmd endfunction @@ -153,7 +163,7 @@ function! s:construct_go_db_build_cmd(db_path) \ '" -c ./go_cscope.out -t ./go_tags -p' let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - return shell_cmd + return exists('g:codequery_build_go_db_cmd') ? g:codequery_build_go_db_cmd : shell_cmd endfunction @@ -276,7 +286,7 @@ function! s:do_grep(word) \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' elseif s:querytype == s:subcmd_map['Text'] - silent execute g:codequery_text_cmd . ' ' . a:word + silent execute g:codequery_find_text_cmd . ' ' . a:word call s:prettify_qf_layout_and_map_keys(getqflist()) let s:last_query_word = a:word From 7cb51791325bd346bd2307562e8de5ba46355578 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 1 Sep 2016 22:37:38 +0800 Subject: [PATCH 41/81] rename do_grep => do_query & extract to create_grep_options --- plugin/codequery.vim | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 08ce22b..e272c6f 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -255,12 +255,7 @@ function! s:prettify_qf_layout_and_map_keys(results) endfunction -function! s:do_grep(word) - if empty(a:word) - echom 'Invalid Search Term: ' . a:word - return - endif - +function! s:create_grep_options(word) if s:fuzzy let fuzzy_option = '-f' let word = '"' . a:word . '"' @@ -298,6 +293,24 @@ function! s:do_grep(word) return endif + return [grepformat, grepprg] +endfunction + + +function! s:do_query(word) + if empty(a:word) + echom 'Invalid Search Term: ' . a:word + return + endif + + let grep_options = s:create_grep_options(a:word) + if empty(grep_options) + return + endif + let [grepformat, grepprg] = grep_options + + " TODO: Rewrite it when Vim8 is coming + " ---------------------------------------------------------------- let grepcmd = s:append_to_quickfix ? 'grepadd!' : 'grep!' let l:grepprg_bak = &l:grepprg let l:grepformat_bak = &grepformat @@ -320,6 +333,7 @@ function! s:do_grep(word) let s:last_query_word = a:word let s:last_query_fuzzy = s:fuzzy endtry + " ---------------------------------------------------------------- endfunction @@ -450,7 +464,7 @@ function! s:run_codequery(args) let cword = s:get_valid_cursor_word() if args_num == 0 - call s:do_grep(cword) + call s:do_query(cword) elseif index(s:query_subcommands, args[0]) != -1 call s:set_options(args) @@ -467,7 +481,7 @@ function! s:run_codequery(args) return endif - call s:do_grep(iword) + call s:do_query(iword) else echom 'Wrong Subcommand !' endif @@ -504,6 +518,8 @@ function! s:make_codequery_db(args) continue endif + " TODO: Rewrite it when Vim8 is coming + " ---------------------------------------------------------------- if exists(':Start') silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd redraw! @@ -512,6 +528,7 @@ function! s:make_codequery_db(args) silent execute '!' . shell_cmd redraw! endif + " ---------------------------------------------------------------- endfor endfunction From 2c9187937254f107d42c47df558ba838e73580b6 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 00:37:22 +0800 Subject: [PATCH 42/81] Update README.md --- README.md | 110 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 363f2d5..2741c7a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,14 @@ > Choose what you want to know! 😼
+```vim +" Open menu +:CodeQueryMenu Unite Full + +" Or query directly +:CodeQuery Definition get_user_id +``` +

# vim-codequery @@ -24,12 +32,12 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com
## Supported languages - * [X] `Python` (in beta: **give it a try! 😎**) - * [ ] `Javascript` (coming soon) - * [ ] `Ruby` (coming soon) - * [ ] `Go` (coming soon) - * [ ] `Java` (coming later) - * [ ] `C, C++` (coming very later) + * [x] `Python` 😎 + * [x] `Javascript` + * [x] `Ruby` + * [x] `Go` + * [ ] `Java` (coming very soon) + * [ ] `C, C++` (coming very soon)
@@ -49,13 +57,15 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ## Schedule -> **This project is still under development.** +> **This project is almost ready to be released.** +> Main TODO: +> * Use Vim8's new features to enhance usability. +> * Do lazy-loading. +> * Support Java, C, C++. > -> Completeness: 70% -> v1.0 Release Date: Mid-September -> -> If you are a pythoner, it is ready for you to use. Try it! -> This plugin will support Javascript/Ruby/Go ASAP. +> Completeness: 90% +> v1.0 Release Date: Mid-September +> It is Ok to try it! 👌
@@ -90,12 +100,15 @@ echo mkdir mv cut find awk stat git(optional) * Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim), ... * Take Plug as an example: ```vim -" Highly Recommemded => it helps Vim-CodeQuery to build DB asynchrously without blocking Vim +" Recommemded => it helps vim-codeQuery to build DB asynchrously without blocking Vim Plug 'tpope/vim-dispatch' - -" Highly Recommemded => if you want to use Unite menu + +" Recommemded => if you don't have an :Ack (or :Ag) liked command => install it ! +Plug 'mileszs/ack.vim' + +" Highly Recommemded => if you want to use my custom Unite menu Plug 'Shougo/unite.vim' - + " The Must Have One Plug 'devjoe/vim-codequery' ``` @@ -106,20 +119,16 @@ Plug 'devjoe/vim-codequery' #### 1. Setup -* Go to the (git) root directory of your project. Then open an arbitrary file with the same file type you want to index under the current directory. For example: -
-readme.md
-setup.py
-foldA
-├── a.py
-├── b.py 
-└── c.py
-
-In this Python project, you can use `vim setup.py` to open a Python file and then call `:CodeQueryMakeDB` to make CodeQuery DB. If there is no Python file in root directory, you can temporarily open a new one. (like `vim tmp.py`) -* When the DB file `python.db` (or xxxx.db) and related ctags and cscope files are created, it's ready for you to do searching! - * Call `:CodeQueryMakeDB` again to update the DB file if you need. - * Vim-CodeQuery will not clean ctags and cscope files, you can use them if you need. -* Furthermore, if you are also under a git repository, it's recommended you to use `:CodeQueryMoveDBToGitDir` to hide the DB file under `.git/codequery/` directory. If you do so, next time you can call `:CodeQueryMakeDB` in any Python file under the repository to update the DB file. +* Go to the (git) root directory of your project. Open vim and type: +```vim +" Indexing Python files +:CodeQueryMakeDB python +" Or indexing Python + Javascript files +:CodeQueryMakeDB python javascript +``` +* That's all! `python.db`, `javascript.db` ... will be created in the root directory. +* It's recommended that you should use `:CodeQueryMoveDBToGitDir python` to hide the DB file to `.git/codequery/` directory. If you do so, next time you can call `:CodeQueryMakeDB` directly in any opened Python buffer to rebuild the DB file. + #### 2. Search * **Find symbol under cursor** @@ -133,7 +142,7 @@ In this Python project, you can use `vim setup.py` to open a Python file and the ```vim :CodeQuery [SubCommand] -" Supported SubCommands are: `Symbol, Call, Caller, Callee, Class, Parent, Child, Member, FunctionList, FileImporter`. +" Supported SubCommands are: `Symbol, Text, Call, Caller, Callee, Class, Parent, Child, Member, FunctionList, FileImporter`. ``` * **Find arbitrary word** @@ -171,23 +180,26 @@ In this Python project, you can use `vim setup.py` to open a Python file and the ``` #### 3. Use Quickfix -* **Move inside Quickfix window to use these key bindings** +* **Move your cursor inside Quickfix window to use these key bindings** | Key | Action | Note | | --- | --- | --- | -| s | `:CodeQueryAgain Symbol` | -| c | `:CodeQueryAgain Call` | -| r | `:CodeQueryAgain Caller` | -| y | `:CodeQueryAgain Callee` | -| d | `:CodeQueryAgain Definition` | -| C | `:CodeQueryAgain Class` | -| M | `:CodeQueryAgain Member` | -| P | `:CodeQueryAgain Parent` | -| D | `:CodeQueryAgain Child` | -| \ | `:CodeQueryFilter` | -| p | `p` | Preview -| u | `:colder \| CodeQueryShowQF` | Older Quickfix Result -| \ | `:cnewer \| CodeQueryShowQF` | Newer Quickfix Result +| s | `:CodeQueryAgain Symbol` | | +| x | `:CodeQueryAgain Text` | use `:Ack!` by default. You can override it by setting `g:codequery_find_text_cmd` | +| c | `:CodeQueryAgain Call` | | +| r | `:CodeQueryAgain Caller` | | +| e | `:CodeQueryAgain Callee` | | +| d | `:CodeQueryAgain Definition` | | +| C | `:CodeQueryAgain Class` | | +| M | `:CodeQueryAgain Member` | | +| P | `:CodeQueryAgain Parent` | | +| D | `:CodeQueryAgain Child` | | +| m | `:CodeQueryMenu Unite Magic` | | +| q | `:cclose` | | +| \ | `:CodeQueryFilter` | | +| p | `p` | Preview | +| u | `:colder \| CodeQueryShowQF` | Older Quickfix Result | +| \ | `:cnewer \| CodeQueryShowQF` | Newer Quickfix Result | * **Show Quickfix with above key bindings** @@ -200,7 +212,7 @@ In this Python project, you can use `vim setup.py` to open a Python file and the #### 4. Open Menu -Currently, Vim-CodeQuery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot. There are two types of menu: +Currently, vim-codeQuery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot. There are two types of menu: * **Open a complete Unite menu** @@ -213,14 +225,14 @@ Currently, Vim-CodeQuery only provides [Unite](https://github.com/Shougo/unite.v ``` -* **Open a necessary Unite menu** +* **Open a magic Unite menu** ```vim :CodeQueryMenu Unite Magic " This menu changes dynamically: -" 1. Word under cursor is capital (possible be class): remove [F] actions -" 2. Word under cursor is non-capital (possible be function): remove [C] actions +" 1. If word under cursor is capital (possible be class): remove [F] actions +" 2. If word under cursor is non-capital (possible be function): remove [C] actions " 3. Show reasonable actions only within Quickfix ``` From 985986e8553dd1f35a9c55e573bf1b1435cfcb62 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 11:28:46 +0800 Subject: [PATCH 43/81] Update README.md --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2741c7a..072f4f3 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ## Schedule > **This project is almost ready to be released.** +> > Main TODO: > * Use Vim8's new features to enhance usability. > * Do lazy-loading. @@ -65,6 +66,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > > Completeness: 90% > v1.0 Release Date: Mid-September +> > It is Ok to try it! 👌
@@ -100,7 +102,7 @@ echo mkdir mv cut find awk stat git(optional) * Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim), ... * Take Plug as an example: ```vim -" Recommemded => it helps vim-codeQuery to build DB asynchrously without blocking Vim +" Recommemded => it helps vim-codequery to build DB asynchrously without blocking Vim Plug 'tpope/vim-dispatch' " Recommemded => if you don't have an :Ack (or :Ag) liked command => install it ! @@ -123,6 +125,7 @@ Plug 'devjoe/vim-codequery' ```vim " Indexing Python files :CodeQueryMakeDB python + " Or indexing Python + Javascript files :CodeQueryMakeDB python javascript ``` @@ -185,7 +188,7 @@ Plug 'devjoe/vim-codequery' | Key | Action | Note | | --- | --- | --- | | s | `:CodeQueryAgain Symbol` | | -| x | `:CodeQueryAgain Text` | use `:Ack!` by default. You can override it by setting `g:codequery_find_text_cmd` | +| x | `:CodeQueryAgain Text` | use `:Ack!` by default. #1 | | c | `:CodeQueryAgain Call` | | | r | `:CodeQueryAgain Caller` | | | e | `:CodeQueryAgain Callee` | | @@ -200,19 +203,21 @@ Plug 'devjoe/vim-codequery' | p | `p` | Preview | | u | `:colder \| CodeQueryShowQF` | Older Quickfix Result | | \ | `:cnewer \| CodeQueryShowQF` | Newer Quickfix Result | - + +> #1 +> You can override `g:codequery_find_text_cmd` to change it. * **Show Quickfix with above key bindings** ```vim :CodeQueryShowQF -" This command also works for standard Quickfix result +" This command can also be used to **patch** standard Quickfix. ``` #### 4. Open Menu -Currently, vim-codeQuery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot. There are two types of menu: +Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot ⭐. There are two types of menu: * **Open a complete Unite menu** From 278d7ed805115ca1e77752a12c1f59a04efb5717 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 2 Sep 2016 12:59:26 +0800 Subject: [PATCH 44/81] add an option: g:codequery_enable_auto_clean_languages --- plugin/codequery.vim | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index e272c6f..57f4298 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -13,7 +13,7 @@ let g:codequery_find_text_cmd = 'Ack!' "let g:codequery_build_javascript_db_cmd = '' "let g:codequery_build_ruby_db_cmd = '' "let g:codequery_build_go_db_cmd = '' - +"let g:codequery_enable_auto_clean_languages = [] " ============================================================================= @@ -129,6 +129,11 @@ function! s:construct_python_db_build_cmd(db_path) \ ctags_cmd . ' && ' . \ cqmakedb_cmd + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'python') != -1 + let shell_cmd .= '&& rm python_cscope.files python_cscope.out python_tags' + endif + return exists('g:codequery_build_python_db_cmd') ? g:codequery_build_python_db_cmd : shell_cmd endfunction @@ -141,6 +146,11 @@ function! s:construct_javascript_db_build_cmd(db_path) let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'javascript') != -1 + let shell_cmd .= ' && rm javascript_cscope.out javascript_tags .starscope.db' + endif + return exists('g:codequery_build_javascript_db_cmd') ? g:codequery_build_javascript_db_cmd : shell_cmd endfunction @@ -152,6 +162,12 @@ function! s:construct_ruby_db_build_cmd(db_path) \ '" -c ./ruby_cscope.out -t ./ruby_tags -p' let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'ruby') != -1 + let shell_cmd .= ' && rm ruby_cscope.out ruby_tags .starscope.db' + endif + return exists('g:codequery_build_ruby_db_cmd') ? g:codequery_build_ruby_db_cmd : shell_cmd endfunction @@ -163,6 +179,12 @@ function! s:construct_go_db_build_cmd(db_path) \ '" -c ./go_cscope.out -t ./go_tags -p' let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'go') != -1 + let shell_cmd .= ' && rm go_cscope.out go_tags .starscope.db' + endif + return exists('g:codequery_build_go_db_cmd') ? g:codequery_build_go_db_cmd : shell_cmd endfunction From 9a2dc3e06803d8d158a7f9a0844f0e2af12c0e26 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 14:48:26 +0800 Subject: [PATCH 45/81] Update README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 072f4f3..b1c656e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ > Choose what you want to know! 😼 -
```vim " Open menu :CodeQueryMenu Unite Full @@ -245,7 +244,49 @@ Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.v
## Tips - +#### Open Menu Smartly +```vim +nnoremap c :CodeQueryMenu Unite Full +nnoremap ; :CodeQueryMenu Unite Magic + +" Or enable typing (to search menu items) by default +nnoremap \ :CodeQueryMenu Unite MagicA +``` + +#### Query Smartly +```vim +nnoremap :CodeQuery Symbol + +" Chain commands! To find possible tests (for python) +nnoremap t :CodeQuery Caller:CodeQueryFilter test_ +``` + +#### Load Ctags File +```vim +" Set tags option +set tags=./javascript_tags;/ +set tags+=./python_tags;/ +set tags+=./ruby_tags;/ +set tags+=./go_tags;/ +``` + +#### Clean Ctags, Cscope ... Files For Your Languages +```vim +" It accpepts a list of your languages written in lowercase +let g:codequery_enable_auto_clean_languages = ['python'] +``` + +#### Custom Database Building +```vim +" Make sure to generate a python.db or xxxx.db file as a result +let g:codequery_build_python_db_cmd = '...' +let g:codequery_build_javascript_db_cmd = '...' +let g:codequery_build_ruby_db_cmd = '...' +let g:codequery_build_go_db_cmd = '...' +``` + +
+ ## FAQ ## How to Contribute From 8d60c2d24bf6ab5ea9fc1b74a1b7d886f1d95b30 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 16:14:21 +0800 Subject: [PATCH 46/81] Update README.md --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index b1c656e..2ab9b3d 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,30 @@ let g:codequery_build_go_db_cmd = '...' ## FAQ +#### Why writing this plugin? + +> Because I need it. +> +> I already shared the story of making this plugin in local Python user groups [Taipei.py](http://www.meetup.com/Taipei-py/) and [Tainan.py](http://www.meetup.com/Tainan-py-Python-Tainan-User-Group/). +> Slides are available here: [Taipei.py](http://www.slideshare.net/excusemejoe/joe-vim-plugin-taipeipy20160825) / [Tainan.py](http://www.slideshare.net/excusemejoe/vim-plugin-20160827) (Language: Traditional Chinese) + +#### Why not using Ctags or Cscope directly? + +> Read what @ruben2020 the author of CodeQuery said: [Link](https://github.com/ruben2020/codequery#how-is-it-different-from-cscope-and-ctags-what-are-the-advantages) +> +> In addittion, vim-codequery provides: +> +> 1. Good interface. +> 2. Separated Database Management Mechanism. +> (You can open as many projects as you wish in a single Vim session without worrying about messing up Ctags or Cscope files or getting wrong result!) +> +> for Vim users. + +#### More Questions + +> Ask [here](https://docs.google.com/document/d/1gIvP9wrp1i3xLPDEKNVy76gUeYt1QkIUoqSvJDEbOfM/edit?usp=sharing) or create an issue. + + ## How to Contribute ## Credits From c47aa3061058cf032ab5ce254aa88bf25a21450d Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 17:48:30 +0800 Subject: [PATCH 47/81] Update README.md --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ab9b3d..7c0e7ec 100644 --- a/README.md +++ b/README.md @@ -311,8 +311,32 @@ let g:codequery_build_go_db_cmd = '...' #### More Questions > Ask [here](https://docs.google.com/document/d/1gIvP9wrp1i3xLPDEKNVy76gUeYt1QkIUoqSvJDEbOfM/edit?usp=sharing) or create an issue. + +
+ +## How to Contribute +#### Use It +> And give me [feedback](https://goo.gl/forms/9r8sOS6xTCBjNQEW2) or [bug report](https://docs.google.com/spreadsheets/d/1eSweAzJKYdzeNdTUVfhujEAOy1RHq1_bEBSX8DQ6xvA/edit?usp=sharing). -## How to Contribute +#### Fork It + +> And give me PR. It would be better if you open an [issue](https://github.com/devjoe/vim-codequery/issues) and discuss with me before sending PR. + +#### Star It +> If you like it. + +
+ ## Credits + +Thank all for working on these great projects! 👏 + +* [CodeQuery](https://github.com/ruben2020/codequery) +* [Starscope](https://github.com/eapache/starscope) +* [PyCscope](https://github.com/portante/pycscope) +* [Unite.vim](https://github.com/Shougo/unite.vim) +* [dispatch.vim](https://github.com/tpope/vim-dispatch) +* [ack.vim](https://github.com/mileszs/ack.vim) +* [vim-addon-qf-layout](https://github.com/MarcWeber/vim-addon-qf-layout) From 2fd0e904499fe5212a7bf779d9a3b9e0529c6739 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 2 Sep 2016 17:51:36 +0800 Subject: [PATCH 48/81] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c0e7ec..ef191af 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,7 @@ let g:codequery_build_go_db_cmd = '...' #### Star It -> If you like it. +> If you like it. 👍
From 6e2d44e17ce1cb8d2c7afd329153b1fbd0ae7ef0 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Sun, 4 Sep 2016 22:43:59 +0800 Subject: [PATCH 49/81] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef191af..e090d92 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ let g:codequery_build_go_db_cmd = '...' ## Credits -Thank all for working on these great projects! 👏 +Thank all for working on these great projects! * [CodeQuery](https://github.com/ruben2020/codequery) * [Starscope](https://github.com/eapache/starscope) From 3df52cdb6ab0b38db9e2d0076b0818dcbf7a91fb Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 7 Sep 2016 15:14:28 +0800 Subject: [PATCH 50/81] support java --- plugin/codequery.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 57f4298..18fbc63 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -189,6 +189,26 @@ function! s:construct_go_db_build_cmd(db_path) endfunction +function! s:construct_java_db_build_cmd(db_path) + let find_cmd = 'find . -iname "*.java" > java_cscope.files' + let cscope_cmd = 'cscope -cbR -i java_cscope.files -f java_cscope.out' + let ctags_cmd = 'ctags --fields=+i -n -R -f "java_tags" -L java_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c java_cscope.out' . + \ ' -t java_tags -p' + let shell_cmd = find_cmd . ' && ' . + \ cscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'java') != -1 + let shell_cmd .= '&& rm java_cscope.files java_cscope.out java_tags' + endif + + return exists('g:codequery_build_java_db_cmd') ? g:codequery_build_java_db_cmd : shell_cmd +endfunction + + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -535,6 +555,8 @@ function! s:make_codequery_db(args) let shell_cmd = s:construct_ruby_db_build_cmd(db_path) elseif ft ==? 'go' let shell_cmd = s:construct_go_db_build_cmd(db_path) + elseif ft ==? 'java' + let shell_cmd = s:construct_java_db_build_cmd(db_path) else echom 'No Command For Building ' . ft . ' DB' continue From ca43eb4e803823e28ef09b68030d50a252542fa1 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 7 Sep 2016 16:05:59 +0800 Subject: [PATCH 51/81] support c family --- plugin/codequery.vim | 71 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 18fbc63..dbd0d6c 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -67,10 +67,16 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'DefinitionGroup' : 20 } +let s:c_family_filetype_list = + \ ['c', 'h', 'cpp', 'cxx', 'cc', 'hpp', 'hxx', 'hh'] + + +let s:supported_filetypes = s:c_family_filetype_list + + \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] + + function! s:check_filetype(filetype) - let supported_filetypes = - \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] - if index(supported_filetypes, a:filetype) == -1 + if index(s:supported_filetypes, a:filetype) == -1 return 0 endif return 1 @@ -79,7 +85,12 @@ endfunction " `lcd` brings side effect !! function! s:find_db_path(filetype) - let db_name = a:filetype . '.db' + if index(s:c_family_filetype_list, a:filetype) != -1 + let db_name = 'c_family.db' + else + let db_name = a:filetype . '.db' + endif + let lookup_path = findfile(expand('%:p:h') . '/' . db_name, '.') if !empty(lookup_path) @@ -209,6 +220,32 @@ function! s:construct_java_db_build_cmd(db_path) endfunction +function! s:construct_c_db_build_cmd(db_path) + let find_cmd = 'find . -iname "*.c" > c_cscope.files && ' . + \ 'find . -iname "*.h" >> c_cscope.files && ' . + \ 'find . -iname "*.cpp" >> c_cscope.files && ' . + \ 'find . -iname "*.cxx" >> c_cscope.files && ' . + \ 'find . -iname "*.cc" >> c_cscope.files && ' . + \ 'find . -iname "*.hpp" >> c_cscope.files && ' . + \ 'find . -iname "*.hxx" >> c_cscope.files && ' . + \ 'find . -iname "*.hh" >> c_cscope.files' + let cscope_cmd = 'cscope -cbk -i c_cscope.files -f c_cscope.out' + let ctags_cmd = 'ctags --fields=+i -n -R -f "c_tags" -L c_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c c_cscope.out' . + \ ' -t c_tags -p' + let shell_cmd = find_cmd . ' && ' . + \ cscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'c') != -1 + let shell_cmd .= '&& rm c_cscope.files c_cscope.out c_tags' + endif + + return exists('g:codequery_build_c_db_cmd') ? g:codequery_build_c_db_cmd : shell_cmd +endfunction + function! s:is_valid_word(word) return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction @@ -544,7 +581,11 @@ function! s:make_codequery_db(args) let db_path = s:find_db_path(ft) if empty(db_path) - let db_path = ft . '.db' + if index(s:c_family_filetype_list, ft) != -1 + let db_path = 'c_family.db' + else + let db_path = ft . '.db' + endif endif if ft ==? 'python' @@ -557,8 +598,10 @@ function! s:make_codequery_db(args) let shell_cmd = s:construct_go_db_build_cmd(db_path) elseif ft ==? 'java' let shell_cmd = s:construct_java_db_build_cmd(db_path) + elseif index(s:c_family_filetype_list, ft) != -1 + let shell_cmd = s:construct_c_db_build_cmd(db_path) else - echom 'No Command For Building ' . ft . ' DB' + echom 'No Command For Building .' . ft . ' file' continue endif @@ -591,7 +634,11 @@ function! s:view_codequery_db(args) let db_path = s:find_db_path(ft) if empty(db_path) - execute '!echo "\n(' . ft . ') DB Not Found"' + if index(s:c_family_filetype_list, ft) != -1 + execute '!echo "\n(c family) DB Not Found"' + else + execute '!echo "\n(' . ft . ') DB Not Found"' + endif continue endif @@ -607,7 +654,11 @@ function! s:move_codequery_db_to_git_hidden_dir(args) endif for ft in args - let db_name = ft . '.db' + if index(s:c_family_filetype_list, ft) != -1 + let db_name = 'c_family.db' + else + let db_name = ft . '.db' + endif let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] let db_path = s:find_db_path(ft) @@ -615,9 +666,9 @@ function! s:move_codequery_db_to_git_hidden_dir(args) let new_db_path = git_root_dir . '/.git/codequery/' . db_name call system('mkdir -p ' . git_root_dir . '/.git/codequery/') call system('mv ' . db_path . ' ' . new_db_path) - echom 'Done (' . ft . ')' + echom 'Done (' . db_name . ')' else - echom 'Git Dir Not Found or (' . ft . ') DB Not Found' + echom 'Git Dir Not Found or (' . db_name . ') Not Found' endif endfor endfunction From 493e4e1dd0b6ee74d7c28c25f9d808d16c2ae7b9 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 7 Sep 2016 16:08:38 +0800 Subject: [PATCH 52/81] add option for java and c --- plugin/codequery.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index dbd0d6c..f785f36 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -13,6 +13,8 @@ let g:codequery_find_text_cmd = 'Ack!' "let g:codequery_build_javascript_db_cmd = '' "let g:codequery_build_ruby_db_cmd = '' "let g:codequery_build_go_db_cmd = '' +"let g:codequery_build_java_db_cmd = '' +"let g:codequery_build_c_db_cmd = '' "let g:codequery_enable_auto_clean_languages = [] From 3b599518a81fadab40f75ea33a7db784467c5667 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Wed, 7 Sep 2016 16:12:47 +0800 Subject: [PATCH 53/81] Update README.md --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e090d92..4e578a7 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com * [x] `Javascript` * [x] `Ruby` * [x] `Go` - * [ ] `Java` (coming very soon) - * [ ] `C, C++` (coming very soon) + * [x] `Java` + * [x] `C, C++`
@@ -61,9 +61,9 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > Main TODO: > * Use Vim8's new features to enhance usability. > * Do lazy-loading. -> * Support Java, C, C++. +> * Fix some bugs > -> Completeness: 90% +> Completeness: 92% > v1.0 Release Date: Mid-September > > It is Ok to try it! 👌 @@ -268,6 +268,8 @@ set tags=./javascript_tags;/ set tags+=./python_tags;/ set tags+=./ruby_tags;/ set tags+=./go_tags;/ +set tags+=./java_tags;/ +set tags+=./c_tags;/ ``` #### Clean Ctags, Cscope ... Files For Your Languages @@ -282,7 +284,9 @@ let g:codequery_enable_auto_clean_languages = ['python'] let g:codequery_build_python_db_cmd = '...' let g:codequery_build_javascript_db_cmd = '...' let g:codequery_build_ruby_db_cmd = '...' -let g:codequery_build_go_db_cmd = '...' +let g:codequery_build_go_db_cmd = '...' +let g:codequery_build_java_db_cmd = '...' +let g:codequery_build_c_db_cmd = '...' ```
From 0dff889711781339faf584a95f346f7b1d069fa7 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 8 Sep 2016 18:43:55 +0800 Subject: [PATCH 54/81] [lazy load] refactor 70% : basic codequery cmd works --- autoload/codequery.vim | 227 ++++++++++++ autoload/codequery/db.vim | 152 ++++++++ autoload/codequery/menu.vim | 95 +++++ autoload/codequery/query.vim | 216 +++++++++++ plugin/codequery.vim | 697 +---------------------------------- 5 files changed, 701 insertions(+), 686 deletions(-) create mode 100644 autoload/codequery.vim create mode 100644 autoload/codequery/db.vim create mode 100644 autoload/codequery/menu.vim create mode 100644 autoload/codequery/query.vim diff --git a/autoload/codequery.vim b/autoload/codequery.vim new file mode 100644 index 0000000..2c5aeb7 --- /dev/null +++ b/autoload/codequery.vim @@ -0,0 +1,227 @@ +" ============================================================================= +" Helpers + + +let g:c_family_filetype_list = + \ ['c', 'h', 'cpp', 'cxx', 'cc', 'hpp', 'hxx', 'hh'] + + +let s:supported_filetypes = g:c_family_filetype_list + + \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] + + +function! s:check_filetype(filetype) + if index(s:supported_filetypes, a:filetype) == -1 + return 0 + endif + return 1 +endfunction + + +function! s:set_db() + let path = codequery#db#find_db_path(&filetype) + if empty(path) + echom 'CodeQuery DB Not Found' + return 0 + endif + + let g:db_path = path + return 1 +endfunction + + + +" ============================================================================= +" Entries + + +function! codequery#run_codequery(args) + if !s:check_filetype(&filetype) + echom 'Not Supported Filetype: ' . &filetype + return + endif + + let g:last_query_word = '' + let g:fuzzy = 0 + let g:append_to_quickfix = 0 + let g:querytype = 1 + let g:db_path = '' + if !s:set_db() + return + endif + + let args = split(a:args, ' ') + let args_num = len(args) + let cword = codequery#query#get_valid_cursor_word() + + if args_num == 0 + call codequery#query#do_query(cword) + + elseif index(g:codequery_subcommands, args[0]) != -1 + call codequery#query#set_options(args) + let iword = codequery#query#get_valid_input_word(args) + let word = codequery#query#get_final_query_word(iword, cword) + if empty(word) + echom 'Invalid Args: ' . a:args + return + endif + + call codequery#query#do_query(word) + else + echom 'Wrong Subcommand !' + endif +endfunction + + +function! s:make_codequery_db(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] + endif + + for ft in args + if !s:check_filetype(ft) + echom 'Not Supported Filetype: ' . ft + continue + endif + + let db_path = codequery#db#find_db_path(ft) + if empty(db_path) + if index(g:c_family_filetype_list, ft) != -1 + let db_path = 'c_family.db' + else + let db_path = ft . '.db' + endif + endif + + if ft ==? 'python' + let shell_cmd = codequery#db#construct_python_db_build_cmd(db_path) + elseif ft ==? 'javascript' + let shell_cmd = codequery#db#construct_javascript_db_build_cmd(db_path) + elseif ft ==? 'ruby' + let shell_cmd = codequery#db#construct_ruby_db_build_cmd(db_path) + elseif ft ==? 'go' + let shell_cmd = codequery#db#construct_go_db_build_cmd(db_path) + elseif ft ==? 'java' + let shell_cmd = codequery#db#construct_java_db_build_cmd(db_path) + elseif index(g:c_family_filetype_list, ft) != -1 + let shell_cmd = codequery#db#construct_c_db_build_cmd(db_path) + else + echom 'No Command For Building .' . ft . ' file' + continue + endif + + " TODO: Rewrite it when Vim8 is coming + " ---------------------------------------------------------------- + if exists(':Start') + silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd + redraw! + echom 'Making ' . db_path ' => Run :CodeQueryViewDB to Check Status' + else + silent execute '!' . shell_cmd + redraw! + endif + " ---------------------------------------------------------------- + endfor +endfunction + + +function! s:view_codequery_db(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] + endif + + for ft in args + if !s:check_filetype(ft) + echom 'Not Supported Filetype: ' . ft + continue + endif + + let db_path = codequery#db#find_db_path(ft) + if empty(db_path) + if index(g:c_family_filetype_list, ft) != -1 + execute '!echo "\n(c family) DB Not Found"' + else + execute '!echo "\n(' . ft . ') DB Not Found"' + endif + continue + endif + + execute '!echo "\n(' . db_path . ') is update at: " && stat -f "\%Sm" ' . db_path + endfor +endfunction + + +function! s:move_codequery_db_to_git_hidden_dir(args) + let args = split(a:args, ' ') + if empty(args) + let args = [&filetype] + endif + + for ft in args + if index(g:c_family_filetype_list, ft) != -1 + let db_name = 'c_family.db' + else + let db_name = ft . '.db' + endif + let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] + let db_path = codequery#db#find_db_path(ft) + + if !v:shell_error && !empty(db_path) + let new_db_path = git_root_dir . '/.git/codequery/' . db_name + call system('mkdir -p ' . git_root_dir . '/.git/codequery/') + call system('mv ' . db_path . ' ' . new_db_path) + echom 'Done (' . db_name . ')' + else + echom 'Git Dir Not Found or (' . db_name . ') Not Found' + endif + endfor +endfunction + + +function! s:show_menu(args) + let args = split(a:args, ' ') + let args_num = len(args) + + if args_num > 0 && index(s:menu_subcommands, args[0]) != -1 + if args[0] ==# 'Unite' + if args_num > 1 && args[1] ==# 'Magic' + let magic_menu = 1 + else + let magic_menu = 0 + endif + call s:use_unite_menu(magic_menu) + return + endif + endif + + echom 'Wrong Subcommands! Try: ' . join(s:menu_subcommands, ', ') +endfunction + + +function! s:run_codequery_again_with_different_subcmd(args) + let args = split(a:args, ' ') + let args_num = len(args) + if !empty(s:last_query_word) && args_num > 0 + cclose + let again_cmd = 'CodeQuery ' . args[0] . ' ' . s:last_query_word . ' ' + \ . (s:last_query_fuzzy ? '-f' : '') + execute again_cmd + else + echom 'Wrong Subcommands!' + endif +endfunction + + +" modify from someone's .vimrc +function! s:filter_qf_results(query) + let results = getqflist() + for d in results + if bufname(d['bufnr']) !~ a:query && d['text'] !~ a:query + call remove(results, index(results, d)) + endif + endfor + call setqflist(results) + call s:prettify_qf_layout_and_map_keys(results) +endfunction diff --git a/autoload/codequery/db.vim b/autoload/codequery/db.vim new file mode 100644 index 0000000..eaaf16f --- /dev/null +++ b/autoload/codequery/db.vim @@ -0,0 +1,152 @@ + +" `lcd` brings side effect !! +function! codequery#db#find_db_path(filetype) + if index(g:c_family_filetype_list, a:filetype) != -1 + let db_name = 'c_family.db' + else + let db_name = a:filetype . '.db' + endif + + let lookup_path = findfile(expand('%:p:h') . '/' . db_name, '.') + + if !empty(lookup_path) + lcd %:p:h + return lookup_path + endif + + lcd %:p:h + let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] + if !v:shell_error + let lookup_path = findfile(git_root_dir . '/' . db_name, '.') + if !empty(lookup_path) + execute 'lcd ' . git_root_dir + return lookup_path + else + let lookup_path = findfile(git_root_dir . '/.git/codequery/' . + \ db_name, '.') + if !empty(lookup_path) + execute 'lcd ' . git_root_dir + return lookup_path + endif + endif + endif +endfunction + + +function! s:construct_python_db_build_cmd(db_path) + let find_cmd = 'find . -iname "*.py" > python_cscope.files' + let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' + let ctags_cmd = 'ctags --fields=+i -n -R -f "python_tags" -L python_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c python_cscope.out' . + \ ' -t python_tags -p' + let shell_cmd = find_cmd . ' && ' . + \ pycscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'python') != -1 + let shell_cmd .= '&& rm python_cscope.files python_cscope.out python_tags' + endif + + return exists('g:codequery_build_python_db_cmd') ? g:codequery_build_python_db_cmd : shell_cmd +endfunction + + +function! s:construct_javascript_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.js' + let rename_cmd = 'mv tags javascript_tags && mv cscope.out javascript_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./javascript_cscope.out -t ./javascript_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'javascript') != -1 + let shell_cmd .= ' && rm javascript_cscope.out javascript_tags .starscope.db' + endif + + return exists('g:codequery_build_javascript_db_cmd') ? g:codequery_build_javascript_db_cmd : shell_cmd +endfunction + + +function! s:construct_ruby_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.rb' + let rename_cmd = 'mv tags ruby_tags && mv cscope.out ruby_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./ruby_cscope.out -t ./ruby_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'ruby') != -1 + let shell_cmd .= ' && rm ruby_cscope.out ruby_tags .starscope.db' + endif + + return exists('g:codequery_build_ruby_db_cmd') ? g:codequery_build_ruby_db_cmd : shell_cmd +endfunction + + +function! s:construct_go_db_build_cmd(db_path) + let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.go' + let rename_cmd = 'mv tags go_tags && mv cscope.out go_cscope.out' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . + \ '" -c ./go_cscope.out -t ./go_tags -p' + + let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'go') != -1 + let shell_cmd .= ' && rm go_cscope.out go_tags .starscope.db' + endif + + return exists('g:codequery_build_go_db_cmd') ? g:codequery_build_go_db_cmd : shell_cmd +endfunction + + +function! s:construct_java_db_build_cmd(db_path) + let find_cmd = 'find . -iname "*.java" > java_cscope.files' + let cscope_cmd = 'cscope -cbR -i java_cscope.files -f java_cscope.out' + let ctags_cmd = 'ctags --fields=+i -n -R -f "java_tags" -L java_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c java_cscope.out' . + \ ' -t java_tags -p' + let shell_cmd = find_cmd . ' && ' . + \ cscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'java') != -1 + let shell_cmd .= '&& rm java_cscope.files java_cscope.out java_tags' + endif + + return exists('g:codequery_build_java_db_cmd') ? g:codequery_build_java_db_cmd : shell_cmd +endfunction + + +function! s:construct_c_db_build_cmd(db_path) + let find_cmd = 'find . -iname "*.c" > c_cscope.files && ' . + \ 'find . -iname "*.h" >> c_cscope.files && ' . + \ 'find . -iname "*.cpp" >> c_cscope.files && ' . + \ 'find . -iname "*.cxx" >> c_cscope.files && ' . + \ 'find . -iname "*.cc" >> c_cscope.files && ' . + \ 'find . -iname "*.hpp" >> c_cscope.files && ' . + \ 'find . -iname "*.hxx" >> c_cscope.files && ' . + \ 'find . -iname "*.hh" >> c_cscope.files' + let cscope_cmd = 'cscope -cbk -i c_cscope.files -f c_cscope.out' + let ctags_cmd = 'ctags --fields=+i -n -R -f "c_tags" -L c_cscope.files' + let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c c_cscope.out' . + \ ' -t c_tags -p' + let shell_cmd = find_cmd . ' && ' . + \ cscope_cmd . ' && ' . + \ ctags_cmd . ' && ' . + \ cqmakedb_cmd + + if exists('g:codequery_enable_auto_clean_languages') && + \ index(g:codequery_enable_auto_clean_languages, 'c') != -1 + let shell_cmd .= '&& rm c_cscope.files c_cscope.out c_tags' + endif + + return exists('g:codequery_build_c_db_cmd') ? g:codequery_build_c_db_cmd : shell_cmd +endfunction + diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim new file mode 100644 index 0000000..ad833dc --- /dev/null +++ b/autoload/codequery/menu.vim @@ -0,0 +1,95 @@ + +let s:menu_subcommands = [ 'Unite' ] + + +function! codequery#patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) + call map(a:fre_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:fun_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:cla_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') + call map(a:fre_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call map(a:fun_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call map(a:cla_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') + call insert(a:fre_cmds, ['▷ Filter', 'call feedkeys(":CodeQueryFilter ")'], 0) +endfunction + + + +function! codequery:use_unite_menu(magic) + let cword = s:get_valid_cursor_word() + let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol'], + \['▷ Find Text', 'CodeQuery Text']] + let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], + \['▷ Find Call [F]', 'CodeQuery Call'], + \['▷ Find Caller [F]', 'CodeQuery Caller'], + \['▷ Find Callee [F]', 'CodeQuery Callee']] + let menu_class_cmds = [['▷ Find Class Def. [C]', 'CodeQuery Class'], + \['▷ Find Class Member [C]', 'CodeQuery Member'], + \['▷ Find Parent [C]', 'CodeQuery Parent'], + \['▷ Find Child [C]', 'CodeQuery Child']] + let menu_other_cmds = [['▷ List Function', 'CodeQuery FunctionList'], + \['▷ List Imports', 'CodeQuery FileImporter']] + let menu_delimiter = [['* ------------------------- *', '']] + let menu_db_cmds = [['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ")'], + \['▷ View DB', 'call feedkeys(":CodeQueryViewDB ")'], + \['▷ Move DB', 'call feedkeys(":CodeQueryMoveDBToGitDir ")']] + let menu_show_qf = [['▷ Show QF ▲', 'CodeQueryShowQF'], + \['▷ Hide QF ▼', 'cclose']] + let menu_goto_magic = [['▷ Open Magic Menu ▸', 'CodeQueryMenu Unite Magic']] + let menu_goto_full = [['▷ Open Full Menu ▸', 'CodeQueryMenu Unite Full']] + + if a:magic + if &filetype ==# 'qf' + call codequery#patch_unite_magic_menu_from_qf(menu_frequent_cmds, + \ menu_function_cmds, + \ menu_class_cmds) + let menu_other_cmds = [] + let menu_goto_full = [] + if exists('s:last_query_word') + let cword = s:last_query_word + endif + endif + + let menu_description = 'CodeQuery Magic Menu' + if cword =~# '\C^[A-Z].*' + let cmd_candidates = menu_frequent_cmds + \ + menu_class_cmds + \ + menu_other_cmds + \ + menu_show_qf + \ + menu_goto_full + else + let cmd_candidates = menu_frequent_cmds + \ + menu_function_cmds + \ + menu_other_cmds + \ + menu_show_qf + \ + menu_goto_full + endif + else + if &filetype ==# 'qf' + echom 'Can Not Open Full Menu In QF (Use Magic Menu)' + return + endif + let menu_description = 'CodeQuery Full Menu' + let cmd_candidates = menu_frequent_cmds + \ + menu_function_cmds + \ + menu_class_cmds + \ + menu_other_cmds + \ + menu_delimiter + \ + menu_db_cmds + \ + menu_delimiter + \ + menu_show_qf + \ + menu_goto_magic + endif + + if !exists('g:unite_source_menu_menus') + let g:unite_source_menu_menus = {} + endif + let g:unite_source_menu_menus.codequery = { + \ 'description' : menu_description, + \} + let g:unite_source_menu_menus.codequery.command_candidates = cmd_candidates + execute 'Unite -silent -prompt-visible -prompt=::' . cword + \ . ':: menu:codequery' +endfunction + + + diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim new file mode 100644 index 0000000..034791d --- /dev/null +++ b/autoload/codequery/query.vim @@ -0,0 +1,216 @@ + +let s:subcmd_map = { 'Symbol' : 1, + \ 'Definition' : 2, + \ 'Caller' : 6, + \ 'Callee' : 7, + \ 'Call' : 8, + \ 'Class' : 3, + \ 'Member' : 9, + \ 'Parent' : 12, + \ 'Child' : 11, + \ 'FunctionList' : 13, + \ 'FileImporter' : 4, + \ 'Text' : 21, + \ 'DefinitionGroup' : 20 } + + +function! codequery#query#is_valid_word(word) + return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 +endfunction + + +function! codequery#query#get_valid_cursor_word() + return codequery#query#is_valid_word(expand('')) ? expand('') : '' +endfunction + + +function! codequery#query#get_valid_input_word(args) + let args = deepcopy(a:args) + if g:fuzzy + call remove(args, index(args, '-f')) + endif + if g:append_to_quickfix + call remove(args, index(args, '-a')) + endif + + if len(args) <= 1 + return '' + endif + + return codequery#query#is_valid_word(args[1]) ? args[1] : '' +endfunction + + +function! codequery#query#get_final_query_word(iword, cword) + if empty(a:iword) && g:querytype == s:subcmd_map['FunctionList'] + return expand('%') + elseif empty(a:iword) && g:querytype == s:subcmd_map['FileImporter'] + return expand('%:r') + elseif empty(a:iword) && !empty(a:cword) + return a:cword + elseif empty(a:iword) + return '' + endif +endfunction + + +" Ref: MarcWeber's vim-addon-qf-layout +function! codequery#query#prettify_qf_layout_and_map_keys(results) + if &filetype !=# 'qf' + copen + endif + + " unlock qf to make changes + setlocal modifiable + setlocal nolist + setlocal nowrap + + " delete all the text in qf + silent %delete + + " insert new text with pretty layout + let max_fn_len = 0 + let max_lnum_len = 0 + for d in a:results + let d['filename'] = bufname(d['bufnr']) + let max_fn_len = max([max_fn_len, len(d['filename'])]) + let max_lnum_len = max([max_lnum_len, len(d['lnum'])]) + endfor + let reasonable_max_len = 60 + let max_fn_len = min([max_fn_len, reasonable_max_len]) + let qf_format = '"%-' . max_fn_len . 'S | %' . max_lnum_len . 'S | %s"' + let evaluating_str = 'printf(' . qf_format . + \ ', v:val["filename"], v:val["lnum"], v:val["text"])' + call append('0', map(a:results, evaluating_str)) + + " delete empty line + global/^$/delete + + " put the cursor back + normal! gg + + " map shortcuts + nnoremap s :CodeQueryAgain Symbol + nnoremap x :CodeQueryAgain Text + nnoremap c :CodeQueryAgain Call + nnoremap r :CodeQueryAgain Caller + nnoremap e :CodeQueryAgain Callee + nnoremap d :CodeQueryAgain Definition + nnoremap C :CodeQueryAgain Class + nnoremap M :CodeQueryAgain Member + nnoremap P :CodeQueryAgain Parent + nnoremap D :CodeQueryAgain Child + + nnoremap m :CodeQueryMenu Unite Magic + nnoremap q :cclose + nnoremap \ :CodeQueryFilter + + nnoremap p p + nnoremap u :colder \| CodeQueryShowQF + nnoremap :cnewer \| CodeQueryShowQF + + " lock qf again + setlocal nomodifiable + setlocal nomodified +endfunction + + +function! s:create_grep_options(word) + if g:fuzzy + let fuzzy_option = '-f' + let word = '"' . a:word . '"' + else + let fuzzy_option = '-e' + let word = a:word + endif + + let pipeline_script_option = ' \| cut -f 2,3' + + let grepformat = '%f:%l%m' + let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . pipeline_script_option + + if g:querytype == s:subcmd_map['FileImporter'] + let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option + + elseif g:querytype == s:subcmd_map['Callee'] || + \ g:querytype == s:subcmd_map['Caller'] || + \ g:querytype == s:subcmd_map['Member'] + let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' + + elseif g:querytype == s:subcmd_map['Text'] + silent execute g:codequery_find_text_cmd . ' ' . a:word + call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) + + let g:last_query_word = a:word + let g:last_query_fuzzy = s:fuzzy + return + + elseif g:querytype == s:subcmd_map['DefinitionGroup'] + echom 'Not Implement !' + return + endif + + return [grepformat, grepprg] +endfunction + + +function! codequery#query#do_query(word) + if empty(a:word) + echom 'Invalid Search Term: ' . a:word + return + endif + + let grep_options = s:create_grep_options(a:word) + if empty(grep_options) + return + endif + let [grepformat, grepprg] = grep_options + + " TODO: Rewrite it when Vim8 is coming + " ---------------------------------------------------------------- + let grepcmd = g:append_to_quickfix ? 'grepadd!' : 'grep!' + let l:grepprg_bak = &l:grepprg + let l:grepformat_bak = &grepformat + try + let &l:grepformat = grepformat + let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' + silent execute grepcmd + redraw! + + let results = getqflist() + call codequery#query#prettify_qf_layout_and_map_keys(results) + if !empty(results) + echom 'Found ' . len(results) . ' results' + else + echom 'Result Not Found' + endif + finally + let &l:grepprg = l:grepprg_bak + let &grepformat = l:grepformat_bak + let g:last_query_word = a:word + let g:last_query_fuzzy = g:fuzzy + endtry + " ---------------------------------------------------------------- +endfunction + + +function! codequery#query#set_options(args) + let g:querytype = get(s:subcmd_map, a:args[0]) + + if index(a:args, '-f') != -1 + let g:fuzzy = 1 + endif + + if index(a:args, '-a') != -1 + let g:append_to_quickfix = 1 + endif +endfunction + + +" ============================================================================= +" Entries + + diff --git a/plugin/codequery.vim b/plugin/codequery.vim index f785f36..1a10e92 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -19,705 +19,30 @@ let g:codequery_find_text_cmd = 'Ack!' " ============================================================================= -" Menu +" Commands command! -nargs=* -complete=customlist,s:complete_function CodeQuery - \ call s:run_codequery() + \ call codequery#run_codequery() command! -nargs=* -complete=customlist,s:complete_function CodeQueryAgain - \ call s:run_codequery_again_with_different_subcmd() -command! -nargs=* CodeQueryFilter call s:filter_qf_results() -command! -nargs=* CodeQueryMakeDB call s:make_codequery_db() -command! -nargs=* CodeQueryViewDB call s:view_codequery_db() + \ call codequery:run_codequery_again_with_different_subcmd() +command! -nargs=* CodeQueryFilter call codequery#filter_qf_results() +command! -nargs=* CodeQueryMakeDB call codequery#make_codequery_db() +command! -nargs=* CodeQueryViewDB call codequery#view_codequery_db() command! -nargs=* CodeQueryMoveDBToGitDir - \ call s:move_codequery_db_to_git_hidden_dir() -command! -nargs=* CodeQueryMenu call s:show_menu() + \ call codequery#move_codequery_db_to_git_hidden_dir() +command! -nargs=* CodeQueryMenu call codequery#show_menu() command! -nargs=0 CodeQueryShowQF call - \ s:prettify_qf_layout_and_map_keys(getqflist()) + \ codequery#query#prettify_qf_layout_and_map_keys(getqflist()) -let s:query_subcommands = [ 'Symbol', 'Text', +let g:codequery_subcommands = [ 'Symbol', 'Text', \ 'Definition', 'DefinitionGroup', \ 'Caller', 'Callee', 'Call', \ 'Class', 'Member', 'Parent', 'Child', \ 'FunctionList', \ 'FileImporter', \ ] -let s:menu_subcommands = [ 'Unite' ] function! s:complete_function(arg_lead, cmd_line, cursor_pos) - return s:query_subcommands -endfunction - - - -" ============================================================================= -" Helpers - - -let s:subcmd_map = { 'Symbol' : 1, - \ 'Definition' : 2, - \ 'Caller' : 6, - \ 'Callee' : 7, - \ 'Call' : 8, - \ 'Class' : 3, - \ 'Member' : 9, - \ 'Parent' : 12, - \ 'Child' : 11, - \ 'FunctionList' : 13, - \ 'FileImporter' : 4, - \ 'Text' : 21, - \ 'DefinitionGroup' : 20 } - - -let s:c_family_filetype_list = - \ ['c', 'h', 'cpp', 'cxx', 'cc', 'hpp', 'hxx', 'hh'] - - -let s:supported_filetypes = s:c_family_filetype_list + - \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] - - -function! s:check_filetype(filetype) - if index(s:supported_filetypes, a:filetype) == -1 - return 0 - endif - return 1 -endfunction - - -" `lcd` brings side effect !! -function! s:find_db_path(filetype) - if index(s:c_family_filetype_list, a:filetype) != -1 - let db_name = 'c_family.db' - else - let db_name = a:filetype . '.db' - endif - - let lookup_path = findfile(expand('%:p:h') . '/' . db_name, '.') - - if !empty(lookup_path) - lcd %:p:h - return lookup_path - endif - - lcd %:p:h - let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] - if !v:shell_error - let lookup_path = findfile(git_root_dir . '/' . db_name, '.') - if !empty(lookup_path) - execute 'lcd ' . git_root_dir - return lookup_path - else - let lookup_path = findfile(git_root_dir . '/.git/codequery/' . - \ db_name, '.') - if !empty(lookup_path) - execute 'lcd ' . git_root_dir - return lookup_path - endif - endif - endif -endfunction - - -function! s:set_db() - let path = s:find_db_path(&filetype) - if empty(path) - echom 'CodeQuery DB Not Found' - return 0 - endif - - let s:db_path = path - return 1 -endfunction - - -function! s:construct_python_db_build_cmd(db_path) - let find_cmd = 'find . -iname "*.py" > python_cscope.files' - let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' - let ctags_cmd = 'ctags --fields=+i -n -R -f "python_tags" -L python_cscope.files' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c python_cscope.out' . - \ ' -t python_tags -p' - let shell_cmd = find_cmd . ' && ' . - \ pycscope_cmd . ' && ' . - \ ctags_cmd . ' && ' . - \ cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'python') != -1 - let shell_cmd .= '&& rm python_cscope.files python_cscope.out python_tags' - endif - - return exists('g:codequery_build_python_db_cmd') ? g:codequery_build_python_db_cmd : shell_cmd -endfunction - - -function! s:construct_javascript_db_build_cmd(db_path) - let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.js' - let rename_cmd = 'mv tags javascript_tags && mv cscope.out javascript_cscope.out' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . - \ '" -c ./javascript_cscope.out -t ./javascript_tags -p' - - let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'javascript') != -1 - let shell_cmd .= ' && rm javascript_cscope.out javascript_tags .starscope.db' - endif - - return exists('g:codequery_build_javascript_db_cmd') ? g:codequery_build_javascript_db_cmd : shell_cmd -endfunction - - -function! s:construct_ruby_db_build_cmd(db_path) - let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.rb' - let rename_cmd = 'mv tags ruby_tags && mv cscope.out ruby_cscope.out' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . - \ '" -c ./ruby_cscope.out -t ./ruby_tags -p' - - let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'ruby') != -1 - let shell_cmd .= ' && rm ruby_cscope.out ruby_tags .starscope.db' - endif - - return exists('g:codequery_build_ruby_db_cmd') ? g:codequery_build_ruby_db_cmd : shell_cmd -endfunction - - -function! s:construct_go_db_build_cmd(db_path) - let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.go' - let rename_cmd = 'mv tags go_tags && mv cscope.out go_cscope.out' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . - \ '" -c ./go_cscope.out -t ./go_tags -p' - - let shell_cmd = starscope_cmd . ' && ' . rename_cmd . ' && ' . cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'go') != -1 - let shell_cmd .= ' && rm go_cscope.out go_tags .starscope.db' - endif - - return exists('g:codequery_build_go_db_cmd') ? g:codequery_build_go_db_cmd : shell_cmd -endfunction - - -function! s:construct_java_db_build_cmd(db_path) - let find_cmd = 'find . -iname "*.java" > java_cscope.files' - let cscope_cmd = 'cscope -cbR -i java_cscope.files -f java_cscope.out' - let ctags_cmd = 'ctags --fields=+i -n -R -f "java_tags" -L java_cscope.files' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c java_cscope.out' . - \ ' -t java_tags -p' - let shell_cmd = find_cmd . ' && ' . - \ cscope_cmd . ' && ' . - \ ctags_cmd . ' && ' . - \ cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'java') != -1 - let shell_cmd .= '&& rm java_cscope.files java_cscope.out java_tags' - endif - - return exists('g:codequery_build_java_db_cmd') ? g:codequery_build_java_db_cmd : shell_cmd -endfunction - - -function! s:construct_c_db_build_cmd(db_path) - let find_cmd = 'find . -iname "*.c" > c_cscope.files && ' . - \ 'find . -iname "*.h" >> c_cscope.files && ' . - \ 'find . -iname "*.cpp" >> c_cscope.files && ' . - \ 'find . -iname "*.cxx" >> c_cscope.files && ' . - \ 'find . -iname "*.cc" >> c_cscope.files && ' . - \ 'find . -iname "*.hpp" >> c_cscope.files && ' . - \ 'find . -iname "*.hxx" >> c_cscope.files && ' . - \ 'find . -iname "*.hh" >> c_cscope.files' - let cscope_cmd = 'cscope -cbk -i c_cscope.files -f c_cscope.out' - let ctags_cmd = 'ctags --fields=+i -n -R -f "c_tags" -L c_cscope.files' - let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . '" -c c_cscope.out' . - \ ' -t c_tags -p' - let shell_cmd = find_cmd . ' && ' . - \ cscope_cmd . ' && ' . - \ ctags_cmd . ' && ' . - \ cqmakedb_cmd - - if exists('g:codequery_enable_auto_clean_languages') && - \ index(g:codequery_enable_auto_clean_languages, 'c') != -1 - let shell_cmd .= '&& rm c_cscope.files c_cscope.out c_tags' - endif - - return exists('g:codequery_build_c_db_cmd') ? g:codequery_build_c_db_cmd : shell_cmd -endfunction - -function! s:is_valid_word(word) - return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 -endfunction - - -function! s:get_valid_cursor_word() - return s:is_valid_word(expand('')) ? expand('') : '' -endfunction - - -function! s:get_valid_input_word(args) - let args = deepcopy(a:args) - if s:fuzzy - call remove(args, index(args, '-f')) - endif - if s:append_to_quickfix - call remove(args, index(args, '-a')) - endif - - if len(args) <= 1 - return '' - endif - - return s:is_valid_word(args[1]) ? args[1] : '' -endfunction - - -" Ref: MarcWeber's vim-addon-qf-layout -function! s:prettify_qf_layout_and_map_keys(results) - if &filetype !=# 'qf' - copen - endif - - " unlock qf to make changes - setlocal modifiable - setlocal nolist - setlocal nowrap - - " delete all the text in qf - silent %delete - - " insert new text with pretty layout - let max_fn_len = 0 - let max_lnum_len = 0 - for d in a:results - let d['filename'] = bufname(d['bufnr']) - let max_fn_len = max([max_fn_len, len(d['filename'])]) - let max_lnum_len = max([max_lnum_len, len(d['lnum'])]) - endfor - let reasonable_max_len = 60 - let max_fn_len = min([max_fn_len, reasonable_max_len]) - let qf_format = '"%-' . max_fn_len . 'S | %' . max_lnum_len . 'S | %s"' - let evaluating_str = 'printf(' . qf_format . - \ ', v:val["filename"], v:val["lnum"], v:val["text"])' - call append('0', map(a:results, evaluating_str)) - - " delete empty line - global/^$/delete - - " put the cursor back - normal! gg - - " map shortcuts - nnoremap s :CodeQueryAgain Symbol - nnoremap x :CodeQueryAgain Text - nnoremap c :CodeQueryAgain Call - nnoremap r :CodeQueryAgain Caller - nnoremap e :CodeQueryAgain Callee - nnoremap d :CodeQueryAgain Definition - nnoremap C :CodeQueryAgain Class - nnoremap M :CodeQueryAgain Member - nnoremap P :CodeQueryAgain Parent - nnoremap D :CodeQueryAgain Child - - nnoremap m :CodeQueryMenu Unite Magic - nnoremap q :cclose - nnoremap \ :CodeQueryFilter - - nnoremap p p - nnoremap u :colder \| CodeQueryShowQF - nnoremap :cnewer \| CodeQueryShowQF - - " lock qf again - setlocal nomodifiable - setlocal nomodified -endfunction - - -function! s:create_grep_options(word) - if s:fuzzy - let fuzzy_option = '-f' - let word = '"' . a:word . '"' - else - let fuzzy_option = '-e' - let word = a:word - endif - - let pipeline_script_option = ' \| cut -f 2,3' - - let grepformat = '%f:%l%m' - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option . pipeline_script_option - - if s:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option - - elseif s:querytype == s:subcmd_map['Callee'] || - \ s:querytype == s:subcmd_map['Caller'] || - \ s:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' - - elseif s:querytype == s:subcmd_map['Text'] - silent execute g:codequery_find_text_cmd . ' ' . a:word - call s:prettify_qf_layout_and_map_keys(getqflist()) - - let s:last_query_word = a:word - let s:last_query_fuzzy = s:fuzzy - return - - elseif s:querytype == s:subcmd_map['DefinitionGroup'] - echom 'Not Implement !' - return - endif - - return [grepformat, grepprg] -endfunction - - -function! s:do_query(word) - if empty(a:word) - echom 'Invalid Search Term: ' . a:word - return - endif - - let grep_options = s:create_grep_options(a:word) - if empty(grep_options) - return - endif - let [grepformat, grepprg] = grep_options - - " TODO: Rewrite it when Vim8 is coming - " ---------------------------------------------------------------- - let grepcmd = s:append_to_quickfix ? 'grepadd!' : 'grep!' - let l:grepprg_bak = &l:grepprg - let l:grepformat_bak = &grepformat - try - let &l:grepformat = grepformat - let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' - silent execute grepcmd - redraw! - - let results = getqflist() - call s:prettify_qf_layout_and_map_keys(results) - if !empty(results) - echom 'Found ' . len(results) . ' results' - else - echom 'Result Not Found' - endif - finally - let &l:grepprg = l:grepprg_bak - let &grepformat = l:grepformat_bak - let s:last_query_word = a:word - let s:last_query_fuzzy = s:fuzzy - endtry - " ---------------------------------------------------------------- -endfunction - - -function! s:set_options(args) - let s:querytype = get(s:subcmd_map, a:args[0]) - - if index(a:args, '-f') != -1 - let s:fuzzy = 1 - endif - - if index(a:args, '-a') != -1 - let s:append_to_quickfix = 1 - endif -endfunction - - -function! s:patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) - call map(a:fre_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') - call map(a:fun_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') - call map(a:cla_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') - call map(a:fre_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') - call map(a:fun_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') - call map(a:cla_cmds, '[v:val[0], substitute(v:val[1], "CodeQuery", "CodeQueryAgain", "")]') - call insert(a:fre_cmds, ['▷ Filter', 'call feedkeys(":CodeQueryFilter ")'], 0) -endfunction - - -function! s:use_unite_menu(magic) - let cword = s:get_valid_cursor_word() - let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol'], - \['▷ Find Text', 'CodeQuery Text']] - let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], - \['▷ Find Call [F]', 'CodeQuery Call'], - \['▷ Find Caller [F]', 'CodeQuery Caller'], - \['▷ Find Callee [F]', 'CodeQuery Callee']] - let menu_class_cmds = [['▷ Find Class Def. [C]', 'CodeQuery Class'], - \['▷ Find Class Member [C]', 'CodeQuery Member'], - \['▷ Find Parent [C]', 'CodeQuery Parent'], - \['▷ Find Child [C]', 'CodeQuery Child']] - let menu_other_cmds = [['▷ List Function', 'CodeQuery FunctionList'], - \['▷ List Imports', 'CodeQuery FileImporter']] - let menu_delimiter = [['* ------------------------- *', '']] - let menu_db_cmds = [['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ")'], - \['▷ View DB', 'call feedkeys(":CodeQueryViewDB ")'], - \['▷ Move DB', 'call feedkeys(":CodeQueryMoveDBToGitDir ")']] - let menu_show_qf = [['▷ Show QF ▲', 'CodeQueryShowQF'], - \['▷ Hide QF ▼', 'cclose']] - let menu_goto_magic = [['▷ Open Magic Menu ▸', 'CodeQueryMenu Unite Magic']] - let menu_goto_full = [['▷ Open Full Menu ▸', 'CodeQueryMenu Unite Full']] - - if a:magic - if &filetype ==# 'qf' - call s:patch_unite_magic_menu_from_qf(menu_frequent_cmds, - \ menu_function_cmds, - \ menu_class_cmds) - let menu_other_cmds = [] - let menu_goto_full = [] - if exists('s:last_query_word') - let cword = s:last_query_word - endif - endif - - let menu_description = 'CodeQuery Magic Menu' - if cword =~# '\C^[A-Z].*' - let cmd_candidates = menu_frequent_cmds - \ + menu_class_cmds - \ + menu_other_cmds - \ + menu_show_qf - \ + menu_goto_full - else - let cmd_candidates = menu_frequent_cmds - \ + menu_function_cmds - \ + menu_other_cmds - \ + menu_show_qf - \ + menu_goto_full - endif - else - if &filetype ==# 'qf' - echom 'Can Not Open Full Menu In QF (Use Magic Menu)' - return - endif - let menu_description = 'CodeQuery Full Menu' - let cmd_candidates = menu_frequent_cmds - \ + menu_function_cmds - \ + menu_class_cmds - \ + menu_other_cmds - \ + menu_delimiter - \ + menu_db_cmds - \ + menu_delimiter - \ + menu_show_qf - \ + menu_goto_magic - endif - - if !exists('g:unite_source_menu_menus') - let g:unite_source_menu_menus = {} - endif - let g:unite_source_menu_menus.codequery = { - \ 'description' : menu_description, - \} - let g:unite_source_menu_menus.codequery.command_candidates = cmd_candidates - execute 'Unite -silent -prompt-visible -prompt=::' . cword - \ . ':: menu:codequery' -endfunction - - - -" ============================================================================= -" Entries - - -function! s:run_codequery(args) - if !s:check_filetype(&filetype) - echom 'Not Supported Filetype: ' . &filetype - return - endif - - let s:last_query_word = '' - let s:fuzzy = 0 - let s:append_to_quickfix = 0 - let s:querytype = 1 - let s:db_path = '' - if !s:set_db() - return - endif - - let args = split(a:args, ' ') - let args_num = len(args) - let cword = s:get_valid_cursor_word() - - if args_num == 0 - call s:do_query(cword) - - elseif index(s:query_subcommands, args[0]) != -1 - call s:set_options(args) - let iword = s:get_valid_input_word(args) - - if empty(iword) && s:querytype == s:subcmd_map['FunctionList'] - let iword = expand('%') - elseif empty(iword) && s:querytype == s:subcmd_map['FileImporter'] - let iword = expand('%:r') - elseif empty(iword) && !empty(cword) - let iword = cword - elseif empty(iword) - echom 'Invalid Args: ' . a:args - return - endif - - call s:do_query(iword) - else - echom 'Wrong Subcommand !' - endif -endfunction - - -function! s:make_codequery_db(args) - let args = split(a:args, ' ') - if empty(args) - let args = [&filetype] - endif - - for ft in args - if !s:check_filetype(ft) - echom 'Not Supported Filetype: ' . ft - continue - endif - - let db_path = s:find_db_path(ft) - if empty(db_path) - if index(s:c_family_filetype_list, ft) != -1 - let db_path = 'c_family.db' - else - let db_path = ft . '.db' - endif - endif - - if ft ==? 'python' - let shell_cmd = s:construct_python_db_build_cmd(db_path) - elseif ft ==? 'javascript' - let shell_cmd = s:construct_javascript_db_build_cmd(db_path) - elseif ft ==? 'ruby' - let shell_cmd = s:construct_ruby_db_build_cmd(db_path) - elseif ft ==? 'go' - let shell_cmd = s:construct_go_db_build_cmd(db_path) - elseif ft ==? 'java' - let shell_cmd = s:construct_java_db_build_cmd(db_path) - elseif index(s:c_family_filetype_list, ft) != -1 - let shell_cmd = s:construct_c_db_build_cmd(db_path) - else - echom 'No Command For Building .' . ft . ' file' - continue - endif - - " TODO: Rewrite it when Vim8 is coming - " ---------------------------------------------------------------- - if exists(':Start') - silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd - redraw! - echom 'Making ' . db_path ' => Run :CodeQueryViewDB to Check Status' - else - silent execute '!' . shell_cmd - redraw! - endif - " ---------------------------------------------------------------- - endfor -endfunction - - -function! s:view_codequery_db(args) - let args = split(a:args, ' ') - if empty(args) - let args = [&filetype] - endif - - for ft in args - if !s:check_filetype(ft) - echom 'Not Supported Filetype: ' . ft - continue - endif - - let db_path = s:find_db_path(ft) - if empty(db_path) - if index(s:c_family_filetype_list, ft) != -1 - execute '!echo "\n(c family) DB Not Found"' - else - execute '!echo "\n(' . ft . ') DB Not Found"' - endif - continue - endif - - execute '!echo "\n(' . db_path . ') is update at: " && stat -f "\%Sm" ' . db_path - endfor -endfunction - - -function! s:move_codequery_db_to_git_hidden_dir(args) - let args = split(a:args, ' ') - if empty(args) - let args = [&filetype] - endif - - for ft in args - if index(s:c_family_filetype_list, ft) != -1 - let db_name = 'c_family.db' - else - let db_name = ft . '.db' - endif - let git_root_dir = systemlist('git rev-parse --show-toplevel')[0] - let db_path = s:find_db_path(ft) - - if !v:shell_error && !empty(db_path) - let new_db_path = git_root_dir . '/.git/codequery/' . db_name - call system('mkdir -p ' . git_root_dir . '/.git/codequery/') - call system('mv ' . db_path . ' ' . new_db_path) - echom 'Done (' . db_name . ')' - else - echom 'Git Dir Not Found or (' . db_name . ') Not Found' - endif - endfor -endfunction - - -function! s:show_menu(args) - let args = split(a:args, ' ') - let args_num = len(args) - - if args_num > 0 && index(s:menu_subcommands, args[0]) != -1 - if args[0] ==# 'Unite' - if args_num > 1 && args[1] ==# 'Magic' - let magic_menu = 1 - else - let magic_menu = 0 - endif - call s:use_unite_menu(magic_menu) - return - endif - endif - - echom 'Wrong Subcommands! Try: ' . join(s:menu_subcommands, ', ') -endfunction - - -function! s:run_codequery_again_with_different_subcmd(args) - let args = split(a:args, ' ') - let args_num = len(args) - if !empty(s:last_query_word) && args_num > 0 - cclose - let again_cmd = 'CodeQuery ' . args[0] . ' ' . s:last_query_word . ' ' - \ . (s:last_query_fuzzy ? '-f' : '') - execute again_cmd - else - echom 'Wrong Subcommands!' - endif -endfunction - - -" modify from someone's .vimrc -function! s:filter_qf_results(query) - let results = getqflist() - for d in results - if bufname(d['bufnr']) !~ a:query && d['text'] !~ a:query - call remove(results, index(results, d)) - endif - endfor - call setqflist(results) - call s:prettify_qf_layout_and_map_keys(results) + return g:codequery_subcommands endfunction From 6c9cea092d81d3f116b080757a2e8c0246d5a003 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 8 Sep 2016 21:04:41 +0800 Subject: [PATCH 55/81] [lazy load] refactor 100% : all cmds works and use abort for functions --- autoload/codequery.vim | 31 +++++----- autoload/codequery/db.vim | 18 +++--- autoload/codequery/menu.vim | 20 +++--- autoload/codequery/query.vim | 114 ++++++++++++++++++----------------- plugin/codequery.vim | 2 +- 5 files changed, 97 insertions(+), 88 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index 2c5aeb7..cff0bb2 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -10,7 +10,10 @@ let s:supported_filetypes = g:c_family_filetype_list + \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] -function! s:check_filetype(filetype) +let s:menu_subcommands = [ 'Unite' ] + + +function! s:check_filetype(filetype) abort if index(s:supported_filetypes, a:filetype) == -1 return 0 endif @@ -18,7 +21,7 @@ function! s:check_filetype(filetype) endfunction -function! s:set_db() +function! s:set_db() abort let path = codequery#db#find_db_path(&filetype) if empty(path) echom 'CodeQuery DB Not Found' @@ -35,7 +38,7 @@ endfunction " Entries -function! codequery#run_codequery(args) +function! codequery#run_codequery(args) abort if !s:check_filetype(&filetype) echom 'Not Supported Filetype: ' . &filetype return @@ -73,7 +76,7 @@ function! codequery#run_codequery(args) endfunction -function! s:make_codequery_db(args) +function! codequery#make_codequery_db(args) abort let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -126,7 +129,7 @@ function! s:make_codequery_db(args) endfunction -function! s:view_codequery_db(args) +function! codequery#view_codequery_db(args) abort let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -153,7 +156,7 @@ function! s:view_codequery_db(args) endfunction -function! s:move_codequery_db_to_git_hidden_dir(args) +function! codequery#move_codequery_db_to_git_hidden_dir(args) abort let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -180,7 +183,7 @@ function! s:move_codequery_db_to_git_hidden_dir(args) endfunction -function! s:show_menu(args) +function! codequery#show_menu(args) abort let args = split(a:args, ' ') let args_num = len(args) @@ -191,7 +194,7 @@ function! s:show_menu(args) else let magic_menu = 0 endif - call s:use_unite_menu(magic_menu) + call codequery#menu#use_unite_menu(magic_menu) return endif endif @@ -200,13 +203,13 @@ function! s:show_menu(args) endfunction -function! s:run_codequery_again_with_different_subcmd(args) +function! codequery#run_codequery_again_with_different_subcmd(args) abort let args = split(a:args, ' ') let args_num = len(args) - if !empty(s:last_query_word) && args_num > 0 + if !empty(g:last_query_word) && args_num > 0 cclose - let again_cmd = 'CodeQuery ' . args[0] . ' ' . s:last_query_word . ' ' - \ . (s:last_query_fuzzy ? '-f' : '') + let again_cmd = 'CodeQuery ' . args[0] . ' ' . g:last_query_word . ' ' + \ . (g:last_query_fuzzy ? '-f' : '') execute again_cmd else echom 'Wrong Subcommands!' @@ -215,7 +218,7 @@ endfunction " modify from someone's .vimrc -function! s:filter_qf_results(query) +function! codequery#filter_qf_results(query) abort let results = getqflist() for d in results if bufname(d['bufnr']) !~ a:query && d['text'] !~ a:query @@ -223,5 +226,5 @@ function! s:filter_qf_results(query) endif endfor call setqflist(results) - call s:prettify_qf_layout_and_map_keys(results) + call codequery#query#prettify_qf_layout_and_map_keys(results) endfunction diff --git a/autoload/codequery/db.vim b/autoload/codequery/db.vim index eaaf16f..341af37 100644 --- a/autoload/codequery/db.vim +++ b/autoload/codequery/db.vim @@ -1,6 +1,9 @@ +" ============================================================================= +" Entries + " `lcd` brings side effect !! -function! codequery#db#find_db_path(filetype) +function! codequery#db#find_db_path(filetype) abort if index(g:c_family_filetype_list, a:filetype) != -1 let db_name = 'c_family.db' else @@ -33,7 +36,7 @@ function! codequery#db#find_db_path(filetype) endfunction -function! s:construct_python_db_build_cmd(db_path) +function! codequery#db#construct_python_db_build_cmd(db_path) abort let find_cmd = 'find . -iname "*.py" > python_cscope.files' let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' let ctags_cmd = 'ctags --fields=+i -n -R -f "python_tags" -L python_cscope.files' @@ -53,7 +56,7 @@ function! s:construct_python_db_build_cmd(db_path) endfunction -function! s:construct_javascript_db_build_cmd(db_path) +function! codequery#db#construct_javascript_db_build_cmd(db_path) abort let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.js' let rename_cmd = 'mv tags javascript_tags && mv cscope.out javascript_cscope.out' let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . @@ -70,7 +73,7 @@ function! s:construct_javascript_db_build_cmd(db_path) endfunction -function! s:construct_ruby_db_build_cmd(db_path) +function! codequery#db#construct_ruby_db_build_cmd(db_path) abort let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.rb' let rename_cmd = 'mv tags ruby_tags && mv cscope.out ruby_cscope.out' let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . @@ -87,7 +90,7 @@ function! s:construct_ruby_db_build_cmd(db_path) endfunction -function! s:construct_go_db_build_cmd(db_path) +function! codequery#db#construct_go_db_build_cmd(db_path) abort let starscope_cmd = 'starscope --force-update -e ctags -e cscope **/*.go' let rename_cmd = 'mv tags go_tags && mv cscope.out go_cscope.out' let cqmakedb_cmd = 'cqmakedb -s "' . a:db_path . @@ -104,7 +107,7 @@ function! s:construct_go_db_build_cmd(db_path) endfunction -function! s:construct_java_db_build_cmd(db_path) +function! codequery#db#construct_java_db_build_cmd(db_path) abort let find_cmd = 'find . -iname "*.java" > java_cscope.files' let cscope_cmd = 'cscope -cbR -i java_cscope.files -f java_cscope.out' let ctags_cmd = 'ctags --fields=+i -n -R -f "java_tags" -L java_cscope.files' @@ -124,7 +127,7 @@ function! s:construct_java_db_build_cmd(db_path) endfunction -function! s:construct_c_db_build_cmd(db_path) +function! codequery#db#construct_c_db_build_cmd(db_path) abort let find_cmd = 'find . -iname "*.c" > c_cscope.files && ' . \ 'find . -iname "*.h" >> c_cscope.files && ' . \ 'find . -iname "*.cpp" >> c_cscope.files && ' . @@ -149,4 +152,3 @@ function! s:construct_c_db_build_cmd(db_path) return exists('g:codequery_build_c_db_cmd') ? g:codequery_build_c_db_cmd : shell_cmd endfunction - diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim index ad833dc..25d2af9 100644 --- a/autoload/codequery/menu.vim +++ b/autoload/codequery/menu.vim @@ -1,8 +1,11 @@ +" ============================================================================= +" Entries -let s:menu_subcommands = [ 'Unite' ] +scriptencoding utf-8 -function! codequery#patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) + +function! codequery#menu#patch_unite_magic_menu_from_qf(fre_cmds, fun_cmds, cla_cmds) abort call map(a:fre_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') call map(a:fun_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') call map(a:cla_cmds, '[substitute(v:val[0], "Find", "Switch To", "g"), v:val[1]]') @@ -14,8 +17,8 @@ endfunction -function! codequery:use_unite_menu(magic) - let cword = s:get_valid_cursor_word() +function! codequery#menu#use_unite_menu(magic) abort + let cword = codequery#query#get_valid_cursor_word() let menu_frequent_cmds = [['▷ Find Symbol', 'CodeQuery Symbol'], \['▷ Find Text', 'CodeQuery Text']] let menu_function_cmds = [['▷ Find Function Def. [F]', 'CodeQuery Definition'], @@ -39,13 +42,13 @@ function! codequery:use_unite_menu(magic) if a:magic if &filetype ==# 'qf' - call codequery#patch_unite_magic_menu_from_qf(menu_frequent_cmds, + call codequery#menu#patch_unite_magic_menu_from_qf(menu_frequent_cmds, \ menu_function_cmds, \ menu_class_cmds) let menu_other_cmds = [] let menu_goto_full = [] - if exists('s:last_query_word') - let cword = s:last_query_word + if exists('g:last_query_word') + let cword = g:last_query_word endif endif @@ -90,6 +93,3 @@ function! codequery:use_unite_menu(magic) execute 'Unite -silent -prompt-visible -prompt=::' . cword \ . ':: menu:codequery' endfunction - - - diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index 034791d..daad8d9 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -1,3 +1,6 @@ +" ============================================================================= +" Helpers + let s:subcmd_map = { 'Symbol' : 1, \ 'Definition' : 2, @@ -14,17 +17,64 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'DefinitionGroup' : 20 } -function! codequery#query#is_valid_word(word) +function! s:create_grep_options(word) abort + if g:fuzzy + let fuzzy_option = '-f' + let word = '"' . a:word . '"' + else + let fuzzy_option = '-e' + let word = a:word + endif + + let pipeline_script_option = ' \| cut -f 2,3' + + let grepformat = '%f:%l%m' + let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . pipeline_script_option + + if g:querytype == s:subcmd_map['FileImporter'] + let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option + + elseif g:querytype == s:subcmd_map['Callee'] || + \ g:querytype == s:subcmd_map['Caller'] || + \ g:querytype == s:subcmd_map['Member'] + let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' + + elseif g:querytype == s:subcmd_map['Text'] + silent execute g:codequery_find_text_cmd . ' ' . a:word + call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) + + let g:last_query_word = a:word + let g:last_query_fuzzy = g:fuzzy + return + + elseif g:querytype == s:subcmd_map['DefinitionGroup'] + echom 'Not Implement !' + return + endif + + return [grepformat, grepprg] +endfunction + + + +" ============================================================================= +" Entries + + +function! codequery#query#is_valid_word(word) abort return strlen(matchstr(a:word, '\v^[a-z|A-Z|0-9|_|*|?]+$')) > 0 endfunction -function! codequery#query#get_valid_cursor_word() +function! codequery#query#get_valid_cursor_word() abort return codequery#query#is_valid_word(expand('')) ? expand('') : '' endfunction -function! codequery#query#get_valid_input_word(args) +function! codequery#query#get_valid_input_word(args) abort let args = deepcopy(a:args) if g:fuzzy call remove(args, index(args, '-f')) @@ -41,7 +91,7 @@ function! codequery#query#get_valid_input_word(args) endfunction -function! codequery#query#get_final_query_word(iword, cword) +function! codequery#query#get_final_query_word(iword, cword) abort if empty(a:iword) && g:querytype == s:subcmd_map['FunctionList'] return expand('%') elseif empty(a:iword) && g:querytype == s:subcmd_map['FileImporter'] @@ -50,12 +100,14 @@ function! codequery#query#get_final_query_word(iword, cword) return a:cword elseif empty(a:iword) return '' + else + return a:iword endif endfunction " Ref: MarcWeber's vim-addon-qf-layout -function! codequery#query#prettify_qf_layout_and_map_keys(results) +function! codequery#query#prettify_qf_layout_and_map_keys(results) abort if &filetype !=# 'qf' copen endif @@ -115,49 +167,7 @@ function! codequery#query#prettify_qf_layout_and_map_keys(results) endfunction -function! s:create_grep_options(word) - if g:fuzzy - let fuzzy_option = '-f' - let word = '"' . a:word . '"' - else - let fuzzy_option = '-e' - let word = a:word - endif - - let pipeline_script_option = ' \| cut -f 2,3' - - let grepformat = '%f:%l%m' - let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option . pipeline_script_option - - if g:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s ' . s:db_path . ' -p ' . s:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option - - elseif g:querytype == s:subcmd_map['Callee'] || - \ g:querytype == s:subcmd_map['Caller'] || - \ g:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' - \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' - - elseif g:querytype == s:subcmd_map['Text'] - silent execute g:codequery_find_text_cmd . ' ' . a:word - call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) - - let g:last_query_word = a:word - let g:last_query_fuzzy = s:fuzzy - return - - elseif g:querytype == s:subcmd_map['DefinitionGroup'] - echom 'Not Implement !' - return - endif - - return [grepformat, grepprg] -endfunction - - -function! codequery#query#do_query(word) +function! codequery#query#do_query(word) abort if empty(a:word) echom 'Invalid Search Term: ' . a:word return @@ -197,7 +207,7 @@ function! codequery#query#do_query(word) endfunction -function! codequery#query#set_options(args) +function! codequery#query#set_options(args) abort let g:querytype = get(s:subcmd_map, a:args[0]) if index(a:args, '-f') != -1 @@ -208,9 +218,3 @@ function! codequery#query#set_options(args) let g:append_to_quickfix = 1 endif endfunction - - -" ============================================================================= -" Entries - - diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 1a10e92..280b23a 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -25,7 +25,7 @@ let g:codequery_find_text_cmd = 'Ack!' command! -nargs=* -complete=customlist,s:complete_function CodeQuery \ call codequery#run_codequery() command! -nargs=* -complete=customlist,s:complete_function CodeQueryAgain - \ call codequery:run_codequery_again_with_different_subcmd() + \ call codequery#run_codequery_again_with_different_subcmd() command! -nargs=* CodeQueryFilter call codequery#filter_qf_results() command! -nargs=* CodeQueryMakeDB call codequery#make_codequery_db() command! -nargs=* CodeQueryViewDB call codequery#view_codequery_db() From 1339caeac559b98bc9d8af6224426236fc34f3b1 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 8 Sep 2016 21:15:06 +0800 Subject: [PATCH 56/81] rename global variables --- autoload/codequery.vim | 16 ++++++------- autoload/codequery/menu.vim | 4 ++-- autoload/codequery/query.vim | 45 ++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index cff0bb2..28f3fe5 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -28,7 +28,7 @@ function! s:set_db() abort return 0 endif - let g:db_path = path + let g:codequery_db_path = path return 1 endfunction @@ -44,11 +44,11 @@ function! codequery#run_codequery(args) abort return endif - let g:last_query_word = '' - let g:fuzzy = 0 - let g:append_to_quickfix = 0 - let g:querytype = 1 - let g:db_path = '' + let g:codequery_last_query_word = '' + let g:codequery_fuzzy = 0 + let g:codequery_append_to_qf = 0 + let g:codequery_querytype = 1 + let g:codequery_db_path = '' if !s:set_db() return endif @@ -206,9 +206,9 @@ endfunction function! codequery#run_codequery_again_with_different_subcmd(args) abort let args = split(a:args, ' ') let args_num = len(args) - if !empty(g:last_query_word) && args_num > 0 + if !empty(g:codequery_last_query_word) && args_num > 0 cclose - let again_cmd = 'CodeQuery ' . args[0] . ' ' . g:last_query_word . ' ' + let again_cmd = 'CodeQuery ' . args[0] . ' ' . g:codequery_last_query_word . ' ' \ . (g:last_query_fuzzy ? '-f' : '') execute again_cmd else diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim index 25d2af9..3601d58 100644 --- a/autoload/codequery/menu.vim +++ b/autoload/codequery/menu.vim @@ -47,8 +47,8 @@ function! codequery#menu#use_unite_menu(magic) abort \ menu_class_cmds) let menu_other_cmds = [] let menu_goto_full = [] - if exists('g:last_query_word') - let cword = g:last_query_word + if exists('g:codequery_last_query_word') + let cword = g:codequery_last_query_word endif endif diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index daad8d9..0d39a48 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -18,7 +18,7 @@ let s:subcmd_map = { 'Symbol' : 1, function! s:create_grep_options(word) abort - if g:fuzzy + if g:codequery_fuzzy let fuzzy_option = '-f' let word = '"' . a:word . '"' else @@ -29,28 +29,28 @@ function! s:create_grep_options(word) abort let pipeline_script_option = ' \| cut -f 2,3' let grepformat = '%f:%l%m' - let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + let grepprg = 'cqsearch -s ' . g:codequery_db_path . ' -p ' . g:codequery_querytype . ' -t ' \ . word . ' -u ' . fuzzy_option . pipeline_script_option - if g:querytype == s:subcmd_map['FileImporter'] - let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + if g:codequery_querytype == s:subcmd_map['FileImporter'] + let grepprg = 'cqsearch -s ' . g:codequery_db_path . ' -p ' . g:codequery_querytype . ' -t ' \ . word . ' -u ' . fuzzy_option - elseif g:querytype == s:subcmd_map['Callee'] || - \ g:querytype == s:subcmd_map['Caller'] || - \ g:querytype == s:subcmd_map['Member'] - let grepprg = 'cqsearch -s ' . g:db_path . ' -p ' . g:querytype . ' -t ' + elseif g:codequery_querytype == s:subcmd_map['Callee'] || + \ g:codequery_querytype == s:subcmd_map['Caller'] || + \ g:codequery_querytype == s:subcmd_map['Member'] + let grepprg = 'cqsearch -s ' . g:codequery_db_path . ' -p ' . g:codequery_querytype . ' -t ' \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' - elseif g:querytype == s:subcmd_map['Text'] + elseif g:codequery_querytype == s:subcmd_map['Text'] silent execute g:codequery_find_text_cmd . ' ' . a:word call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) - let g:last_query_word = a:word - let g:last_query_fuzzy = g:fuzzy + let g:codequery_last_query_word = a:word + let g:last_query_fuzzy = g:codequery_fuzzy return - elseif g:querytype == s:subcmd_map['DefinitionGroup'] + elseif g:codequery_querytype == s:subcmd_map['DefinitionGroup'] echom 'Not Implement !' return endif @@ -76,10 +76,10 @@ endfunction function! codequery#query#get_valid_input_word(args) abort let args = deepcopy(a:args) - if g:fuzzy + if g:codequery_fuzzy call remove(args, index(args, '-f')) endif - if g:append_to_quickfix + if g:codequery_append_to_qf call remove(args, index(args, '-a')) endif @@ -92,9 +92,9 @@ endfunction function! codequery#query#get_final_query_word(iword, cword) abort - if empty(a:iword) && g:querytype == s:subcmd_map['FunctionList'] + if empty(a:iword) && g:codequery_querytype == s:subcmd_map['FunctionList'] return expand('%') - elseif empty(a:iword) && g:querytype == s:subcmd_map['FileImporter'] + elseif empty(a:iword) && g:codequery_querytype == s:subcmd_map['FileImporter'] return expand('%:r') elseif empty(a:iword) && !empty(a:cword) return a:cword @@ -181,7 +181,7 @@ function! codequery#query#do_query(word) abort " TODO: Rewrite it when Vim8 is coming " ---------------------------------------------------------------- - let grepcmd = g:append_to_quickfix ? 'grepadd!' : 'grep!' + let grepcmd = g:codequery_append_to_qf ? 'grepadd!' : 'grep!' let l:grepprg_bak = &l:grepprg let l:grepformat_bak = &grepformat try @@ -200,21 +200,22 @@ function! codequery#query#do_query(word) abort finally let &l:grepprg = l:grepprg_bak let &grepformat = l:grepformat_bak - let g:last_query_word = a:word - let g:last_query_fuzzy = g:fuzzy + let g:codequery_last_query_word = a:word + let g:last_query_fuzzy = g:codequery_fuzzy endtry " ---------------------------------------------------------------- endfunction function! codequery#query#set_options(args) abort - let g:querytype = get(s:subcmd_map, a:args[0]) + let g:codequery_querytype = get(s:subcmd_map, a:args[0]) if index(a:args, '-f') != -1 - let g:fuzzy = 1 + let g:codequery_fuzzy = 1 endif if index(a:args, '-a') != -1 - let g:append_to_quickfix = 1 + let g:codequery_append_to_qf = 1 endif endfunction + From 7d892f92f2ecfe898923045dab9455cf29b1451c Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 8 Sep 2016 23:43:51 +0800 Subject: [PATCH 57/81] handle side effect of using lcd --- autoload/codequery.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index 28f3fe5..a2b8102 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -33,12 +33,23 @@ function! s:set_db() abort endfunction +function! s:save_cwd() abort + let g:codequery_cwd = getcwd() +endfunction + + +function! s:restore_cwd() abort + execute 'lcd ' . g:codequery_cwd +endfunction + + " ============================================================================= " Entries function! codequery#run_codequery(args) abort + call s:save_cwd() if !s:check_filetype(&filetype) echom 'Not Supported Filetype: ' . &filetype return @@ -50,6 +61,7 @@ function! codequery#run_codequery(args) abort let g:codequery_querytype = 1 let g:codequery_db_path = '' if !s:set_db() + call s:restore_cwd() return endif @@ -66,6 +78,7 @@ function! codequery#run_codequery(args) abort let word = codequery#query#get_final_query_word(iword, cword) if empty(word) echom 'Invalid Args: ' . a:args + call s:restore_cwd() return endif @@ -73,10 +86,12 @@ function! codequery#run_codequery(args) abort else echom 'Wrong Subcommand !' endif + call s:restore_cwd() endfunction function! codequery#make_codequery_db(args) abort + call s:save_cwd() let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -126,10 +141,12 @@ function! codequery#make_codequery_db(args) abort endif " ---------------------------------------------------------------- endfor + call s:restore_cwd() endfunction function! codequery#view_codequery_db(args) abort + call s:save_cwd() let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -153,10 +170,12 @@ function! codequery#view_codequery_db(args) abort execute '!echo "\n(' . db_path . ') is update at: " && stat -f "\%Sm" ' . db_path endfor + call s:restore_cwd() endfunction function! codequery#move_codequery_db_to_git_hidden_dir(args) abort + call s:save_cwd() let args = split(a:args, ' ') if empty(args) let args = [&filetype] @@ -180,6 +199,7 @@ function! codequery#move_codequery_db_to_git_hidden_dir(args) abort echom 'Git Dir Not Found or (' . db_name . ') Not Found' endif endfor + call s:restore_cwd() endfunction From db8e30608945398116f7746a4742e73b2e9c9e04 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 8 Sep 2016 23:54:24 +0800 Subject: [PATCH 58/81] remove defnition group (not implement yet) --- autoload/codequery/query.vim | 7 +------ plugin/codequery.vim | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index 0d39a48..d1bef44 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -13,8 +13,7 @@ let s:subcmd_map = { 'Symbol' : 1, \ 'Child' : 11, \ 'FunctionList' : 13, \ 'FileImporter' : 4, - \ 'Text' : 21, - \ 'DefinitionGroup' : 20 } + \ 'Text' : 21 } function! s:create_grep_options(word) abort @@ -49,10 +48,6 @@ function! s:create_grep_options(word) abort let g:codequery_last_query_word = a:word let g:last_query_fuzzy = g:codequery_fuzzy return - - elseif g:codequery_querytype == s:subcmd_map['DefinitionGroup'] - echom 'Not Implement !' - return endif return [grepformat, grepprg] diff --git a/plugin/codequery.vim b/plugin/codequery.vim index 280b23a..c669321 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -36,7 +36,7 @@ command! -nargs=0 CodeQueryShowQF call \ codequery#query#prettify_qf_layout_and_map_keys(getqflist()) let g:codequery_subcommands = [ 'Symbol', 'Text', - \ 'Definition', 'DefinitionGroup', + \ 'Definition', \ 'Caller', 'Callee', 'Call', \ 'Class', 'Member', 'Parent', 'Child', \ 'FunctionList', From 95ea663310ad7b6a55ff594b4cb994b3abcf4ba7 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 9 Sep 2016 03:03:16 +0800 Subject: [PATCH 59/81] fix lcd bug & add a new option --- autoload/codequery.vim | 3 ++- autoload/codequery/query.vim | 25 +++++++++++++++++-------- plugin/codequery.vim | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index a2b8102..ca95057 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -38,8 +38,9 @@ function! s:save_cwd() abort endfunction -function! s:restore_cwd() abort +function! s:restore_cwd() execute 'lcd ' . g:codequery_cwd + let g:codequery_cwd = '' endfunction diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index d1bef44..6a2f4b9 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -42,12 +42,8 @@ function! s:create_grep_options(word) abort \ . word . ' -u ' . fuzzy_option . ' \| awk ''{ print $2 " " $1 }''' elseif g:codequery_querytype == s:subcmd_map['Text'] - silent execute g:codequery_find_text_cmd . ' ' . a:word - call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) - - let g:codequery_last_query_word = a:word - let g:last_query_fuzzy = g:codequery_fuzzy - return + let grepformat = '' + let grepprg = g:codequery_find_text_cmd . ' ' . a:word endif return [grepformat, grepprg] @@ -104,7 +100,11 @@ endfunction " Ref: MarcWeber's vim-addon-qf-layout function! codequery#query#prettify_qf_layout_and_map_keys(results) abort if &filetype !=# 'qf' + if !empty(g:codequery_cwd) + execute 'lcd ' . g:codequery_cwd + endif copen + execute 'lcd ' . g:codequery_cwd endif " unlock qf to make changes @@ -169,10 +169,19 @@ function! codequery#query#do_query(word) abort endif let grep_options = s:create_grep_options(a:word) - if empty(grep_options) + let [grepformat, grepprg] = grep_options + + " Find Text + if empty(grepformat) + if g:codequery_find_text_from_current_file_dir == 1 + lcd %:p:h + endif + silent execute grepprg + call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) + let g:codequery_last_query_word = a:word + let g:last_query_fuzzy = g:codequery_fuzzy return endif - let [grepformat, grepprg] = grep_options " TODO: Rewrite it when Vim8 is coming " ---------------------------------------------------------------- diff --git a/plugin/codequery.vim b/plugin/codequery.vim index c669321..d07e217 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -6,6 +6,7 @@ " Init with default value let g:codequery_find_text_cmd = 'Ack!' +let g:codequery_find_text_from_current_file_dir = 1 " No need to init From 47af1017d89bbe76c183dce2340e747ba7889e25 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 9 Sep 2016 16:36:15 +0800 Subject: [PATCH 60/81] change default value of codequery_find_text_from_current_file_dir setting --- plugin/codequery.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/codequery.vim b/plugin/codequery.vim index d07e217..c19f15c 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -6,7 +6,7 @@ " Init with default value let g:codequery_find_text_cmd = 'Ack!' -let g:codequery_find_text_from_current_file_dir = 1 +let g:codequery_find_text_from_current_file_dir = 0 " No need to init From 23d8c24601ca2b0a93bfa9242482b7959a2d192c Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 9 Sep 2016 16:49:17 +0800 Subject: [PATCH 61/81] Update README.md --- README.md | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4e578a7..1b83132 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,11 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > > Main TODO: > * Use Vim8's new features to enhance usability. -> * Do lazy-loading. -> * Fix some bugs +> * ~~Do lazy-loading.~~ +> * Test it. > > Completeness: 92% -> v1.0 Release Date: Mid-September +> Current Version: v0.8 > > It is Ok to try it! 👌 @@ -78,11 +78,10 @@ echo mkdir mv cut find awk stat git(optional) #### 2. Install CodeQuery -* Follow installation guide in [CodeQuery project](https://github.com/ruben2020/codequery#how-to-install-it). -* Enter `cqsearch -h` in your terminal and view the result. Make sure `cqsearch` accepts `-u` option. - -> If not, you will have to pull latest CodeQuery code and then [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md) yourself. - +* Linux => Follow instructions [here](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md). +* Mac => `brew install qscintilla2 qt5 cmake` and then pull latest CodeQuery code to [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md). + +> You will be able to simply type `brew install codequery` to install a new enough version of codequery in the future. 😑 #### 3. Install additional ctags/cscope tools for your languages | Language | Tools | How to install | @@ -122,13 +121,13 @@ Plug 'devjoe/vim-codequery' * Go to the (git) root directory of your project. Open vim and type: ```vim -" Indexing Python files +" Index Python files :CodeQueryMakeDB python -" Or indexing Python + Javascript files +" Or index Python + Javascript files :CodeQueryMakeDB python javascript ``` -* That's all! `python.db`, `javascript.db` ... will be created in the root directory. +* That's all. `python.db`, `javascript.db` ... will be created in the root directory. * It's recommended that you should use `:CodeQueryMoveDBToGitDir python` to hide the DB file to `.git/codequery/` directory. If you do so, next time you can call `:CodeQueryMakeDB` directly in any opened Python buffer to rebuild the DB file. @@ -218,7 +217,7 @@ Plug 'devjoe/vim-codequery' Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot ⭐. There are two types of menu: -* **Open a complete Unite menu** +* **Open a full Unite menu** ```vim :CodeQueryMenu Unite Full @@ -257,9 +256,19 @@ nnoremap \ :CodeQueryMenu Unite MagicA ```vim nnoremap :CodeQuery Symbol -" Chain commands! To find possible tests (for python) +" Chain commands to find possible tests (for python) nnoremap t :CodeQuery Caller:CodeQueryFilter test_ ``` + +#### Find Text +```vim +" Custom your `CodeQuery Text` commands +let g:codequery_find_text_cmd = 'Ack!' + +let g:codequery_find_text_from_current_file_dir = 0 +" 0 => search from project dir (git root directory / the directory containing xxx.db file) +" 1 => search from the directory containing current file +``` #### Load Ctags File ```vim @@ -272,7 +281,7 @@ set tags+=./java_tags;/ set tags+=./c_tags;/ ``` -#### Clean Ctags, Cscope ... Files For Your Languages +#### Clean Ctags, Cscope ... Files by Languages ```vim " It accpepts a list of your languages written in lowercase let g:codequery_enable_auto_clean_languages = ['python'] From 46f1ea9d13a9a6319a54514e130718cacde76fa7 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 30 Oct 2016 01:49:59 +0800 Subject: [PATCH 62/81] done (priority: vim8 async > dispatch > blocked build) --- autoload/codequery.vim | 17 ++++++++++++----- autoload/codequery/db.vim | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index ca95057..0ad89fb 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -130,17 +130,24 @@ function! codequery#make_codequery_db(args) abort continue endif - " TODO: Rewrite it when Vim8 is coming - " ---------------------------------------------------------------- - if exists(':Start') + if v:version >= 800 + echom 'Making ...' + let mydict = {'db_path': db_path, + \'callback': function("codequery#db#make_db_callback")} + let options = {'out_io': 'null', + \'exit_cb': mydict.callback} + let s:build_job = job_start(['/bin/sh', '-c', shell_cmd], options) + let timer = timer_start(500, + \{-> execute("call job_status(s:build_job)","")}, + \{'repeat': 60}) + elseif exists(':Start') silent execute 'Start! -title=Make_CodeQuery_DB -wait=error ' . shell_cmd redraw! - echom 'Making ' . db_path ' => Run :CodeQueryViewDB to Check Status' + echom 'Making ... ' . db_path ' => Run :CodeQueryViewDB to Check Status' else silent execute '!' . shell_cmd redraw! endif - " ---------------------------------------------------------------- endfor call s:restore_cwd() endfunction diff --git a/autoload/codequery/db.vim b/autoload/codequery/db.vim index 341af37..3801e69 100644 --- a/autoload/codequery/db.vim +++ b/autoload/codequery/db.vim @@ -36,6 +36,11 @@ function! codequery#db#find_db_path(filetype) abort endfunction +function! codequery#db#make_db_callback(job, status) dict + echom 'Done! (' . self.db_path . ')' +endfunction + + function! codequery#db#construct_python_db_build_cmd(db_path) abort let find_cmd = 'find . -iname "*.py" > python_cscope.files' let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' From 0c1f8da6c08ccddf90b1e84b7af3dba639596d1b Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 31 Oct 2016 01:05:51 +0800 Subject: [PATCH 63/81] update readme --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1b83132..aed1af4 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > * Use Vim8's new features to enhance usability. > * ~~Do lazy-loading.~~ > * Test it. +> * Doc it. > > Completeness: 92% > Current Version: v0.8 @@ -100,17 +101,15 @@ echo mkdir mv cut find awk stat git(optional) * Use your favorite plugins manager: [pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [Plug](https://github.com/junegunn/vim-plug), [NeoBundle](https://github.com/Shougo/neobundle.vim), [Dein](https://github.com/Shougo/dein.vim), ... * Take Plug as an example: ```vim -" Recommemded => it helps vim-codequery to build DB asynchrously without blocking Vim -Plug 'tpope/vim-dispatch' - -" Recommemded => if you don't have an :Ack (or :Ag) liked command => install it ! -Plug 'mileszs/ack.vim' - -" Highly Recommemded => if you want to use my custom Unite menu -Plug 'Shougo/unite.vim' - -" The Must Have One +" Required +Plug 'Shougo/unite.vim' Plug 'devjoe/vim-codequery' + +" Optional (if your vim version < 8.0) +Plug 'tpope/vim-dispatch' + +" Optional (if you don't have an :Ack (or :Ag) liked command) +Plug 'mileszs/ack.vim' ```
From 919f7164e91247a56a3747e9f7001c0e8664f987 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 31 Oct 2016 02:05:56 +0800 Subject: [PATCH 64/81] extract and refactor show_result function --- autoload/codequery/query.vim | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index 6a2f4b9..e46bc2e 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -50,6 +50,17 @@ function! s:create_grep_options(word) abort endfunction +function! s:show_result() abort + let results = getqflist() + call codequery#query#prettify_qf_layout_and_map_keys(results) + if !empty(results) + echom 'Found ' . len(results) . ' result' . (len(results) > 1 ? 's' : '') + else + echom 'Result Not Found' + endif +endfunction + + " ============================================================================= " Entries @@ -193,14 +204,7 @@ function! codequery#query#do_query(word) abort let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' silent execute grepcmd redraw! - - let results = getqflist() - call codequery#query#prettify_qf_layout_and_map_keys(results) - if !empty(results) - echom 'Found ' . len(results) . ' results' - else - echom 'Result Not Found' - endif + call s:show_result() finally let &l:grepprg = l:grepprg_bak let &grepformat = l:grepformat_bak From 833e2f33aa6b2f7c7e3f67afadc640bebbce2a7e Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 00:02:04 +0800 Subject: [PATCH 65/81] set 'file' for out_io && delete temp file --- autoload/codequery/query.vim | 64 ++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index e46bc2e..abda58a 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -194,24 +194,61 @@ function! codequery#query#do_query(word) abort return endif - " TODO: Rewrite it when Vim8 is coming - " ---------------------------------------------------------------- - let grepcmd = g:codequery_append_to_qf ? 'grepadd!' : 'grep!' - let l:grepprg_bak = &l:grepprg - let l:grepformat_bak = &grepformat + if v:version >= 800 + echom 'Searching ... [' . a:word . ']' + + let job_dict = {'is_append': g:codequery_append_to_qf ? 1 : 0, + \'target_file': tempname(), + \'backup_ef': &errorformat, + \'word' : a:word, + \'callback': function("codequery#query#do_query_callback")} + let options = {'out_io': 'file', + \'out_name': job_dict.target_file, + \'exit_cb': job_dict.callback} + + let &errorformat = '%f:%l%m' + let grepprg .= ' \| awk "{ sub(/.*\/\.\//,x) }1"' + let shell_cmd = substitute(grepprg, '\\|', '|', "g") + let shell_cmd = substitute(shell_cmd, "''", "'", "g") + + let s:query_job = job_start(['/bin/sh', '-c', shell_cmd], options) + let timer = timer_start(50, + \{-> execute("call job_status(s:query_job)", "")}, + \{'repeat': 200}) + else + let grepcmd = g:codequery_append_to_qf ? 'grepadd!' : 'grep!' + let l:grepprg_bak = &l:grepprg + let l:grepformat_bak = &grepformat + try + let &l:grepformat = grepformat + let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' + silent execute grepcmd + redraw! + call s:show_result() + finally + let &l:grepprg = l:grepprg_bak + let &grepformat = l:grepformat_bak + let g:codequery_last_query_word = a:word + let g:last_query_fuzzy = g:codequery_fuzzy + endtry + endif +endfunction + + +function! codequery#query#do_query_callback(job, status) dict try - let &l:grepformat = grepformat - let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' - silent execute grepcmd - redraw! + if self.is_append + execute "caddfile " . self.target_file + else + execute "cgetfile " . self.target_file + endif call s:show_result() finally - let &l:grepprg = l:grepprg_bak - let &grepformat = l:grepformat_bak - let g:codequery_last_query_word = a:word + let g:codequery_last_query_word = self.word let g:last_query_fuzzy = g:codequery_fuzzy + let &errorformat = self.backup_ef + call delete(self.target_file) endtry - " ---------------------------------------------------------------- endfunction @@ -226,4 +263,3 @@ function! codequery#query#set_options(args) abort let g:codequery_append_to_qf = 1 endif endfunction - From 8c264908a0b992ec2855598efb28cde276f7c091 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 00:27:36 +0800 Subject: [PATCH 66/81] update vim8 async part of readme --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aed1af4..e7bc6ae 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com
-## Demo +## Demo `Choose a query from menu ➙ Get results` @@ -52,6 +52,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com [more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) +> These videos are quite old. +> Now vim-codequery works better than what you see. (by supporting Vim8's async feature)
## Schedule @@ -59,7 +61,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > **This project is almost ready to be released.** > > Main TODO: -> * Use Vim8's new features to enhance usability. +> * ~~Use Vim8's new features to enhance usability.~~ > * ~~Do lazy-loading.~~ > * Test it. > * Doc it. @@ -67,7 +69,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > Completeness: 92% > Current Version: v0.8 > -> It is Ok to try it! 👌 +> Welcome to try it! 👌
@@ -75,7 +77,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com #### 1. Make sure these commands are in your system
-echo mkdir mv cut find awk stat git(optional)
+/bin/sh echo mkdir mv cut find awk stat git(optional)
 
#### 2. Install CodeQuery From ed26a57252470ed13ebec3f3fca5cb49d63be03a Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Tue, 1 Nov 2016 01:21:11 +0800 Subject: [PATCH 67/81] Update README.md --- README.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e7bc6ae..2230229 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,10 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com * You can find: `definition, call, caller, callee, symbol, class, parent, child` and more for a string. * Convenient menus are created for you. * Well-formated results are shown in a custom Quickfix window with usable key bindings. + * Support asynchronous search (Vim version >= 8.0) 2. **Manage your database easily**. * Load, make and move your database file by custom Vim commands. + * Support asynchronous build (Vim version >= 8.0 or by `Dispatch` plugin) * `Note: CodeQuery's SQLite database is built on top of ctags and cscope.` 3. **Know your code more instantly**. * (TBD) @@ -50,10 +52,12 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com ![](https://db.tt/KoZORec3) -[more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) - -> These videos are quite old. -> Now vim-codequery works better than what you see. (by supporting Vim8's async feature) +[more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) + +``` +These videos are quite old. +Now vim-codequery works better than what you see by using Vim8's async feature. +```
## Schedule @@ -63,11 +67,12 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com > Main TODO: > * ~~Use Vim8's new features to enhance usability.~~ > * ~~Do lazy-loading.~~ +> * Enhance usability. > * Test it. > * Doc it. > -> Completeness: 92% -> Current Version: v0.8 +> Completeness: 94% +> Current Version: v0.9 > > Welcome to try it! 👌 @@ -81,10 +86,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com #### 2. Install CodeQuery -* Linux => Follow instructions [here](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md). -* Mac => `brew install qscintilla2 qt5 cmake` and then pull latest CodeQuery code to [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md). - -> You will be able to simply type `brew install codequery` to install a new enough version of codequery in the future. 😑 +* Linux => Install [binaries](https://sourceforge.net/projects/codequery/files/) or [build it](https://github.com/ruben2020/codequery/blob/master/doc/INSTALL-LINUX.md). +* Mac => `brew install codequery` 🍺 (make sure codequery version >= v0.17.0) #### 3. Install additional ctags/cscope tools for your languages | Language | Tools | How to install | @@ -93,10 +96,8 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com | Javascript | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | | Ruby | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | | Go | [Starscope](https://github.com/eapache/starscope) | `sudo gem install starscope` | -| Java | N/A | -| C | N/A | -| C++ | N/A | +> `Java`, `C` and `C++` users do not need to install additional ctags/cscope tools. > Starscope has been [packaged for Arch Linux](https://aur.archlinux.org/packages/ruby-starscope/) #### 4. Install Vim plugins @@ -106,11 +107,11 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com " Required Plug 'Shougo/unite.vim' Plug 'devjoe/vim-codequery' - -" Optional (if your vim version < 8.0) + +" Optional +" if your vim version < 8.0 Plug 'tpope/vim-dispatch' - -" Optional (if you don't have an :Ack (or :Ag) liked command) +" if you don't have an :Ack (or :Ag) liked command Plug 'mileszs/ack.vim' ``` From 23c06ee90bf71e067cb747772ea26ab54a59fad7 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 14:51:46 +0800 Subject: [PATCH 68/81] show proper build option only in menu (if db not found) --- autoload/codequery.vim | 4 ++-- autoload/codequery/menu.vim | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index 0ad89fb..ab22958 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -6,7 +6,7 @@ let g:c_family_filetype_list = \ ['c', 'h', 'cpp', 'cxx', 'cc', 'hpp', 'hxx', 'hh'] -let s:supported_filetypes = g:c_family_filetype_list + +let g:codequery_supported_filetype_list = g:c_family_filetype_list + \ ['python', 'javascript', 'go', 'ruby', 'java', 'c', 'cpp'] @@ -14,7 +14,7 @@ let s:menu_subcommands = [ 'Unite' ] function! s:check_filetype(filetype) abort - if index(s:supported_filetypes, a:filetype) == -1 + if index(g:codequery_supported_filetype_list, a:filetype) == -1 return 0 endif return 1 diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim index 3601d58..43cafe4 100644 --- a/autoload/codequery/menu.vim +++ b/autoload/codequery/menu.vim @@ -40,6 +40,24 @@ function! codequery#menu#use_unite_menu(magic) abort let menu_goto_magic = [['▷ Open Magic Menu ▸', 'CodeQueryMenu Unite Magic']] let menu_goto_full = [['▷ Open Full Menu ▸', 'CodeQueryMenu Unite Full']] + " DB not found => remove unnecessary items from menu + let db_path = codequery#db#find_db_path(&filetype) + if empty(db_path) + let menu_frequent_cmds = + \[['▷ Find Text', g:codequery_find_text_cmd], + \ ['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ' . &filetype . '")']] + let menu_function_cmds = [] + let menu_class_cmds = [] + let menu_other_cmds = [] + let menu_delimiter = [] + let menu_db_cmds = [] + let menu_goto_magic = [] + let menu_goto_full = [] + if index(g:codequery_supported_filetype_list, &filetype) == -1 + let menu_show_qf += [['# Not Supported Filetype: [' . &filetype . ']', '']] + endif + endif + if a:magic if &filetype ==# 'qf' call codequery#menu#patch_unite_magic_menu_from_qf(menu_frequent_cmds, From d2184b74b0d2cceaa35de4bb1fbf8d7a33b90996 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 18:44:19 +0800 Subject: [PATCH 69/81] fix global variable scrope bug & add two options to enhance usability --- autoload/codequery.vim | 9 ++++++++- autoload/codequery/menu.vim | 8 +++----- plugin/codequery.vim | 22 ++++++++++++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index ab22958..998b5fb 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -53,6 +53,10 @@ function! codequery#run_codequery(args) abort call s:save_cwd() if !s:check_filetype(&filetype) echom 'Not Supported Filetype: ' . &filetype + if g:codequery_auto_switch_to_find_text_for_wrong_filetype + silent execute g:codequery_find_text_cmd + call codequery#query#prettify_qf_layout_and_map_keys(getqflist()) + endif return endif @@ -63,6 +67,9 @@ function! codequery#run_codequery(args) abort let g:codequery_db_path = '' if !s:set_db() call s:restore_cwd() + if g:codequery_trigger_build_db_when_db_not_found + execute 'CodeQueryMakeDB ' . &filetype + endif return endif @@ -131,7 +138,7 @@ function! codequery#make_codequery_db(args) abort endif if v:version >= 800 - echom 'Making ...' + echom 'Making DB ...' let mydict = {'db_path': db_path, \'callback': function("codequery#db#make_db_callback")} let options = {'out_io': 'null', diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim index 43cafe4..a4185a0 100644 --- a/autoload/codequery/menu.vim +++ b/autoload/codequery/menu.vim @@ -42,15 +42,13 @@ function! codequery#menu#use_unite_menu(magic) abort " DB not found => remove unnecessary items from menu let db_path = codequery#db#find_db_path(&filetype) - if empty(db_path) - let menu_frequent_cmds = - \[['▷ Find Text', g:codequery_find_text_cmd], - \ ['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ' . &filetype . '")']] + if empty(db_path) && &filetype !=# 'qf' + let menu_frequent_cmds = [['▷ Find Text', g:codequery_find_text_cmd]] let menu_function_cmds = [] let menu_class_cmds = [] let menu_other_cmds = [] let menu_delimiter = [] - let menu_db_cmds = [] + let menu_db_cmds = [['▷ Make DB', 'call feedkeys(":CodeQueryMakeDB ' . &filetype . '")']] let menu_goto_magic = [] let menu_goto_full = [] if index(g:codequery_supported_filetype_list, &filetype) == -1 diff --git a/plugin/codequery.vim b/plugin/codequery.vim index c19f15c..be64cf2 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -1,12 +1,30 @@ " Copyright (c) 2016 excusemejoe " MIT License + +if exists('g:loaded_loaded_codequery') + finish +endif +let g:loaded_codequery = 1 + + " ============================================================================= " Options " Init with default value -let g:codequery_find_text_cmd = 'Ack!' -let g:codequery_find_text_from_current_file_dir = 0 +if !exists('g:codequery_find_text_cmd') + let g:codequery_find_text_cmd = 'Ack!' +endif +if !exists('g:codequery_find_text_from_current_file_dir') + let g:codequery_find_text_from_current_file_dir = 0 +endif +if !exists('g:codequery_auto_switch_to_find_text_for_wrong_filetype') + let g:codequery_auto_switch_to_find_text_for_wrong_filetype = 0 +endif +if !exists('g:codequery_trigger_build_db_when_db_not_found') + let g:codequery_trigger_build_db_when_db_not_found = 0 +endif + " No need to init From e563d8d93ab587966e45a06c4e5fd85644249288 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 22:44:15 +0800 Subject: [PATCH 70/81] add new option => g:codequery_disable_qf_key_bindings --- autoload/codequery/query.vim | 38 +++++++++++++++++++----------------- plugin/codequery.vim | 3 +++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index abda58a..bde8563 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -148,24 +148,26 @@ function! codequery#query#prettify_qf_layout_and_map_keys(results) abort normal! gg " map shortcuts - nnoremap s :CodeQueryAgain Symbol - nnoremap x :CodeQueryAgain Text - nnoremap c :CodeQueryAgain Call - nnoremap r :CodeQueryAgain Caller - nnoremap e :CodeQueryAgain Callee - nnoremap d :CodeQueryAgain Definition - nnoremap C :CodeQueryAgain Class - nnoremap M :CodeQueryAgain Member - nnoremap P :CodeQueryAgain Parent - nnoremap D :CodeQueryAgain Child - - nnoremap m :CodeQueryMenu Unite Magic - nnoremap q :cclose - nnoremap \ :CodeQueryFilter - - nnoremap p p - nnoremap u :colder \| CodeQueryShowQF - nnoremap :cnewer \| CodeQueryShowQF + if !g:codequery_disable_qf_key_bindings + nnoremap s :CodeQueryAgain Symbol + nnoremap x :CodeQueryAgain Text + nnoremap c :CodeQueryAgain Call + nnoremap r :CodeQueryAgain Caller + nnoremap e :CodeQueryAgain Callee + nnoremap d :CodeQueryAgain Definition + nnoremap C :CodeQueryAgain Class + nnoremap M :CodeQueryAgain Member + nnoremap P :CodeQueryAgain Parent + nnoremap D :CodeQueryAgain Child + + nnoremap m :CodeQueryMenu Unite Magic + nnoremap q :cclose + nnoremap \ :CodeQueryFilter + + nnoremap p p + nnoremap u :colder \| CodeQueryShowQF + nnoremap :cnewer \| CodeQueryShowQF + endif " lock qf again setlocal nomodifiable diff --git a/plugin/codequery.vim b/plugin/codequery.vim index be64cf2..c3a7d93 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -24,6 +24,9 @@ endif if !exists('g:codequery_trigger_build_db_when_db_not_found') let g:codequery_trigger_build_db_when_db_not_found = 0 endif +if !exists('g:codequery_disable_qf_key_bindings') + let g:codequery_disable_qf_key_bindings = 0 +endif From 7f6cd9422566bee38a61b6721a31651c401cb782 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 23:20:29 +0800 Subject: [PATCH 71/81] enhance codequery#filter_qf_results (implement reverse filter) --- autoload/codequery.vim | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index 998b5fb..973c6ff 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -253,11 +253,27 @@ endfunction " modify from someone's .vimrc -function! codequery#filter_qf_results(query) abort +function! codequery#filter_qf_results(args) abort + let args = split(a:args, ' ') + if len(args) > 1 + let query = args[1] + let reverse_filter = 1 + else + let query = args[0] + let reverse_filter = 0 + endif + echom query + let results = getqflist() for d in results - if bufname(d['bufnr']) !~ a:query && d['text'] !~ a:query - call remove(results, index(results, d)) + if reverse_filter + if bufname(d['bufnr']) =~ query || d['text'] =~ query + call remove(results, index(results, d)) + endif + else + if bufname(d['bufnr']) !~ query && d['text'] !~ query + call remove(results, index(results, d)) + endif endif endfor call setqflist(results) From e85dcee79748df32f46c9d6d7d670f2ecdd178c5 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 1 Nov 2016 23:35:42 +0800 Subject: [PATCH 72/81] add option => g:codequery_enable_not_so_magic_menu --- autoload/codequery/menu.vim | 9 ++++++++- plugin/codequery.vim | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/autoload/codequery/menu.vim b/autoload/codequery/menu.vim index a4185a0..edfc1bc 100644 --- a/autoload/codequery/menu.vim +++ b/autoload/codequery/menu.vim @@ -69,7 +69,14 @@ function! codequery#menu#use_unite_menu(magic) abort endif let menu_description = 'CodeQuery Magic Menu' - if cword =~# '\C^[A-Z].*' + if g:codequery_enable_not_so_magic_menu + let cmd_candidates = menu_frequent_cmds + \ + menu_function_cmds + \ + menu_class_cmds + \ + menu_other_cmds + \ + menu_show_qf + \ + menu_goto_full + elseif cword =~# '\C^[A-Z].*' let cmd_candidates = menu_frequent_cmds \ + menu_class_cmds \ + menu_other_cmds diff --git a/plugin/codequery.vim b/plugin/codequery.vim index c3a7d93..adfb665 100644 --- a/plugin/codequery.vim +++ b/plugin/codequery.vim @@ -27,6 +27,9 @@ endif if !exists('g:codequery_disable_qf_key_bindings') let g:codequery_disable_qf_key_bindings = 0 endif +if !exists('g:codequery_enable_not_so_magic_menu') + let g:codequery_enable_not_so_magic_menu = 0 +endif From 7130bdaaaf95fecef273cfa0b3f379c25174fa9c Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 2 Nov 2016 00:30:26 +0800 Subject: [PATCH 73/81] show query word in result report --- autoload/codequery/query.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index bde8563..7c8cf24 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -50,13 +50,14 @@ function! s:create_grep_options(word) abort endfunction -function! s:show_result() abort +function! s:show_result(word) abort let results = getqflist() call codequery#query#prettify_qf_layout_and_map_keys(results) if !empty(results) echom 'Found ' . len(results) . ' result' . (len(results) > 1 ? 's' : '') + \. ' /' . a:word . '/' else - echom 'Result Not Found' + echom 'Result Not Found /' . a:word . '/' endif endfunction @@ -226,7 +227,7 @@ function! codequery#query#do_query(word) abort let &l:grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"' silent execute grepcmd redraw! - call s:show_result() + call s:show_result(a:word) finally let &l:grepprg = l:grepprg_bak let &grepformat = l:grepformat_bak @@ -244,7 +245,7 @@ function! codequery#query#do_query_callback(job, status) dict else execute "cgetfile " . self.target_file endif - call s:show_result() + call s:show_result(self.word) finally let g:codequery_last_query_word = self.word let g:last_query_fuzzy = g:codequery_fuzzy From b73af5c51b0b66ec63637ec51c5169e4ea992e7e Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Wed, 2 Nov 2016 01:29:28 +0800 Subject: [PATCH 74/81] Update README.md --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2230229..da9c484 100644 --- a/README.md +++ b/README.md @@ -134,13 +134,13 @@ Plug 'mileszs/ack.vim' #### 2. Search -* **Find symbol under cursor** +* **Find symbol under your cursor** ```vim :CodeQuery ``` -* **Find `?` under cursor** +* **Find word (by subcommands) under your cursor** ```vim :CodeQuery [SubCommand] @@ -154,13 +154,13 @@ Plug 'mileszs/ack.vim' :CodeQuery [SubCommand] [word] ``` -* **Find `?` again with the same word** +* **Find again with the same word** ```vim :CodeQueryAgain [SubCommand] ``` -* **With fuzzy Option** +* **Use fuzzy Option** ```vim :CodeQuery [SubCommand] [word] -f @@ -168,7 +168,7 @@ Plug 'mileszs/ack.vim' " [word] can be: get_* or *user_info or find_*_by_id ``` -* **With append Option** (results will be added to current Quickfix) +* **Use append Option** (results will be added to the current Quickfix) ```vim :CodeQuery [SubCommand] [word] -a @@ -217,9 +217,9 @@ Plug 'mileszs/ack.vim' #### 4. Open Menu -Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love and use it a lot ⭐. There are two types of menu: +Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.vim) menu because I love it ⭐. There are two types of menu: -* **Open a full Unite menu** +* **Full Unite menu** ```vim :CodeQueryMenu Unite Full @@ -230,22 +230,22 @@ Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.v ``` -* **Open a magic Unite menu** +* **Magic Unite menu** ```vim :CodeQueryMenu Unite Magic " This menu changes dynamically: -" 1. If word under cursor is capital (possible be class): remove [F] actions -" 2. If word under cursor is non-capital (possible be function): remove [C] actions -" 3. Show reasonable actions only within Quickfix +" 1. If the word under your cursor begins with a capital letter (possible be class): show [C] actions +" 2. vice versa (possible be function): show [F] actions +" 3. Show reasonable actions within Quickfix ```
## Tips -#### Open Menu Smartly +#### Open Menu ```vim nnoremap c :CodeQueryMenu Unite Full nnoremap ; :CodeQueryMenu Unite Magic @@ -254,13 +254,25 @@ nnoremap ; :CodeQueryMenu Unite Magic nnoremap \ :CodeQueryMenu Unite MagicA ``` -#### Query Smartly +#### Query ```vim nnoremap :CodeQuery Symbol " Chain commands to find possible tests (for python) nnoremap t :CodeQuery Caller:CodeQueryFilter test_ ``` + +#### Filter +```vim +" Filter reversely by adding '!' +:CodeQueryFilter ! [word] +``` + +#### Build +```vim +" Trigger db building (in current filetype) when your query fails +let g:codequery_trigger_build_db_when_db_not_found = 1 +``` #### Find Text ```vim @@ -268,8 +280,12 @@ nnoremap t :CodeQuery Caller:CodeQueryFilter test_ let g:codequery_find_text_cmd = 'Ack!' let g:codequery_find_text_from_current_file_dir = 0 -" 0 => search from project dir (git root directory / the directory containing xxx.db file) +" 0 => search from project dir (git root directory -> then the directory containing xxx.db file) " 1 => search from the directory containing current file + +" If you use ':CodeQuery Symbol' in a txt file, of course, it will fail due to wrong filetype. +" With the following option set to 1, ':CodeQuery Text' will be automatically sent when your query fails. +let g:codequery_auto_switch_to_find_text_for_wrong_filetype = 0 ``` #### Load Ctags File @@ -285,8 +301,9 @@ set tags+=./c_tags;/ #### Clean Ctags, Cscope ... Files by Languages ```vim -" It accpepts a list of your languages written in lowercase let g:codequery_enable_auto_clean_languages = ['python'] + +" It accpepts a list of your languages written in lowercase ``` #### Custom Database Building @@ -300,6 +317,16 @@ let g:codequery_build_java_db_cmd = '...' let g:codequery_build_c_db_cmd = '...' ``` + +#### Others +```vim +" You can disable key binding within quickfix +let g:codequery_disable_qf_key_bindings = 1 + +" if your function usually begins with a capital letter ..., you can change your magic menu to a not-so-magic one +let g:codequery_enable_not_so_magic_menu = 1 +``` +
## FAQ From 1ac02b580d0f01112c2e0be758b417406b37840c Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Fri, 20 Jan 2017 19:47:57 +0800 Subject: [PATCH 75/81] Update README.md 1. Correct the status of this project. (it's "released") 2. No need to show "completeness". --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da9c484..65dc175 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,17 @@ Now vim-codequery works better than what you see by using Vim8's async feature. ## Schedule -> **This project is almost ready to be released.** +> **This project is released.** > > Main TODO: > * ~~Use Vim8's new features to enhance usability.~~ > * ~~Do lazy-loading.~~ -> * Enhance usability. -> * Test it. +> * ~~Enhance usability.~~ +> * ~~Test it.~~ +> * Add **explain** command in v1.0.0 > * Doc it. > -> Completeness: 94% -> Current Version: v0.9 +> Current Version: v0.9.1 > > Welcome to try it! 👌 From 020a8a83457b2a60c66ba4e9cd83897d509a120c Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Sun, 2 Jul 2017 15:02:47 +0800 Subject: [PATCH 76/81] Update README.md Added installation guide for using Vim8's package system. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65dc175..e40091a 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,13 @@ Plug 'tpope/vim-dispatch' " if you don't have an :Ack (or :Ag) liked command Plug 'mileszs/ack.vim' ``` - +* In case you prefer to use Vim8's native package manager to manage plugins manually. Here comes an installation guide for that: + 1. Go to `~/.vim` + 2. Run `mkdir -p pack/vim-codequery/start/` and then go to `start` directory + 3. Run `git clone https://github.com/devjoe/vim-codequery` to get latest vim-codequery code + 4. It's done. 😎 Now `vim-codequery` will be loaded when your Vim starts. You can install [unite](https://github.com/Shougo/unite.vim) in the same way + 5. Learn more about Vim8's package system by typing `:help package | only` +  
## Usage From 745321f0ac613c493b9c4857cf6ba637da5d3567 Mon Sep 17 00:00:00 2001 From: excusemejoe Date: Mon, 1 Jan 2018 16:27:50 +0800 Subject: [PATCH 77/81] Update README.md Use github.io instead of dropbox to host static files --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e40091a..517081f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![](https://github.com/ruben2020/codequery/raw/master/doc/logotitle.png) - + > Choose what you want to know! 😼 ```vim @@ -46,11 +46,11 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com `Choose a query from menu ➙ Get results` -![](https://db.tt/rf6fO2eJ) +![](https://devjoe.github.io/public/cq_demo1.gif) `... ➙ Switch to different query ➙ Get results ... ➙ Filter them ➙ Get Results ➙ Undo ➙ Redo` -![](https://db.tt/KoZORec3) +![](https://devjoe.github.io/public/ca_demo2.gif) [more demo and screenshots](https://github.com/devjoe/vim-codequery/wiki/Screenshots-and-Demo) @@ -234,7 +234,7 @@ Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.v " [F] means this action is for 'function variable only' " [C] is for 'class variable only' ``` - + * **Magic Unite menu** @@ -243,10 +243,10 @@ Currently, vim-codequery only provides [Unite](https://github.com/Shougo/unite.v " This menu changes dynamically: " 1. If the word under your cursor begins with a capital letter (possible be class): show [C] actions -" 2. vice versa (possible be function): show [F] actions +" 2. Vice versa (possible be function): show [F] actions " 3. Show reasonable actions within Quickfix ``` - +
@@ -365,8 +365,6 @@ let g:codequery_enable_not_so_magic_menu = 1 ## How to Contribute #### Use It -> And give me [feedback](https://goo.gl/forms/9r8sOS6xTCBjNQEW2) or [bug report](https://docs.google.com/spreadsheets/d/1eSweAzJKYdzeNdTUVfhujEAOy1RHq1_bEBSX8DQ6xvA/edit?usp=sharing). - #### Fork It > And give me PR. It would be better if you open an [issue](https://github.com/devjoe/vim-codequery/issues) and discuss with me before sending PR. From 0a07f54cad955f310680a5c3e7464838bcc2b112 Mon Sep 17 00:00:00 2001 From: syslot Date: Tue, 20 Mar 2018 14:36:29 +0800 Subject: [PATCH 78/81] modify neovim with sync method --- autoload/codequery.vim | 2 +- autoload/codequery/query.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index 973c6ff..bab9c2f 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -137,7 +137,7 @@ function! codequery#make_codequery_db(args) abort continue endif - if v:version >= 800 + if v:version >= 800 && !has('nvim') echom 'Making DB ...' let mydict = {'db_path': db_path, \'callback': function("codequery#db#make_db_callback")} diff --git a/autoload/codequery/query.vim b/autoload/codequery/query.vim index 7c8cf24..c144719 100644 --- a/autoload/codequery/query.vim +++ b/autoload/codequery/query.vim @@ -197,7 +197,7 @@ function! codequery#query#do_query(word) abort return endif - if v:version >= 800 + if v:version >= 800 && !has('nvim') echom 'Searching ... [' . a:word . ']' let job_dict = {'is_append': g:codequery_append_to_qf ? 1 : 0, From 6730879131d252d261e21510bd252fde8c9ea287 Mon Sep 17 00:00:00 2001 From: devjoe Date: Thu, 10 May 2018 00:58:39 +0800 Subject: [PATCH 79/81] apply johnzeng's patch according to https://github.com/devjoe/vim-codequery/issues/16 --- autoload/codequery.vim | 8 +++++++- autoload/codequery/db.vim | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/autoload/codequery.vim b/autoload/codequery.vim index bab9c2f..e267ec8 100644 --- a/autoload/codequery.vim +++ b/autoload/codequery.vim @@ -137,7 +137,13 @@ function! codequery#make_codequery_db(args) abort continue endif - if v:version >= 800 && !has('nvim') + if has('nvim') + echom 'Making DB ...' + let mydict = {'db_path': db_path, + \'callback': function("codequery#db#make_db_nvim_callback")} + let callbacks = {'on_exit': mydict.callback} + let s:build_job = jobstart(['/bin/sh', '-c', shell_cmd], callbacks) + elseif v:version >= 800 echom 'Making DB ...' let mydict = {'db_path': db_path, \'callback': function("codequery#db#make_db_callback")} diff --git a/autoload/codequery/db.vim b/autoload/codequery/db.vim index 3801e69..0534810 100644 --- a/autoload/codequery/db.vim +++ b/autoload/codequery/db.vim @@ -41,6 +41,11 @@ function! codequery#db#make_db_callback(job, status) dict endfunction +function! codequery#db#make_db_nvim_callback(job, data, status) dict + echom 'Done! Built codequery db!' +endfunction + + function! codequery#db#construct_python_db_build_cmd(db_path) abort let find_cmd = 'find . -iname "*.py" > python_cscope.files' let pycscope_cmd = 'pycscope -f "python_cscope.out" -i python_cscope.files' From 4ba24b83546c50a01e3c41ab7a9f12f967aee2d6 Mon Sep 17 00:00:00 2001 From: devjoe Date: Thu, 10 May 2018 01:07:09 +0800 Subject: [PATCH 80/81] update readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 517081f..4e559af 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This Vim plugin is built on top of the great tool [CodeQuery](https://github.com * Support asynchronous search (Vim version >= 8.0) 2. **Manage your database easily**. * Load, make and move your database file by custom Vim commands. - * Support asynchronous build (Vim version >= 8.0 or by `Dispatch` plugin) + * Support asynchronous build (Vim version >= 8.0 or NeoVim or by `Dispatch` plugin) * `Note: CodeQuery's SQLite database is built on top of ctags and cscope.` 3. **Know your code more instantly**. * (TBD) @@ -69,10 +69,12 @@ Now vim-codequery works better than what you see by using Vim8's async feature. > * ~~Do lazy-loading.~~ > * ~~Enhance usability.~~ > * ~~Test it.~~ +> * ~~Support NeoVim at a certain level.~~ > * Add **explain** command in v1.0.0 +> * Make UI be optional > * Doc it. > -> Current Version: v0.9.1 +> Current Version: v0.9.2 > > Welcome to try it! 👌 From 17ea93d6de13fff03abc58b3c7d53aeb85266f51 Mon Sep 17 00:00:00 2001 From: devjoe Date: Thu, 10 May 2018 01:24:53 +0800 Subject: [PATCH 81/81] add contributors to readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 4e559af..a30a5a5 100644 --- a/README.md +++ b/README.md @@ -377,6 +377,13 @@ let g:codequery_enable_not_so_magic_menu = 1
+## Contributors +* [devjoe](https://github.com/devjoe) +* [johnzeng](https://github.com/johnzeng) +* [syslot](https://github.com/syslot) + +
+ ## Credits Thank all for working on these great projects!