1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 10:20:05 +08:00

Fix flygerp support in windows (#2371)

* Fix flygerp support in windows

* Fix path

* Add option for config command line prompt

Add new SpaceVim option commandline_prompt, this option is for
changging denite and flygrep command line prompt, by default it is
➭

* Remove spacevim before prompt

* Add getjumplist compatible function

* Update getjumplist function

* Implement split max func

* Update test

* Fix compatible function

* Fix rg support in flygrep_windows

in window and neovim-qt, rg need a '.' at the end if no dir specific

* Fix ag support

* Update wiki

* Update notes

* Add note for install rg and ag in windows
This commit is contained in:
Wang Shidong 2018-12-22 22:18:19 +08:00 committed by GitHub
parent 22b9807b63
commit ecab6eb52b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 107 additions and 11 deletions

View File

@ -630,6 +630,10 @@ let g:spacevim_project_rooter_patterns = ['.git/', '_darcs/', '.hg/', '.bzr/', '
" Enable/Disable changing directory automatically. Enabled by default.
let g:spacevim_project_rooter_automatically = 1
""
" Config the command line prompt for flygrep and denite etc.
let g:spacevim_commandline_prompt = '➭'
""
" @section lint_on_the_fly, options-lint_on_the_fly
" @parentsection options

View File

@ -7,6 +7,16 @@
" License: GPLv3
"=============================================================================
""
" @section data#string, api-data-string
" @parentsection api
"
" @subsection Functions
"
" split(str [, sep [, keepempty[, max]]])
"
" run vim command, and return the output of such command.
let s:self = {}
function! s:self.trim(str) abort
@ -125,6 +135,28 @@ function! s:self.strB2Q(str) abort
endfunction
function! s:self.split(str, ...) abort
let sep = get(a:000, 0, '')
let keepempty = get(a:000, 1, 0)
let max = get(a:000, 2, -1)
let rlist = split(a:str, sep, keepempty)
if max >= 2
let rst = []
for item in rlist
if len(rst) >= max - 1
break
endif
call add(rst, item)
endfor
let last = join(rlist[max-1:], sep)
call add(rst, last)
return rst
else
return rlist
endif
endfunction
function! SpaceVim#api#data#string#get() abort
return deepcopy(s:self)
endfunction

View File

@ -141,7 +141,7 @@ endf
func! s:self._build_prompt() abort
normal! :
let ident = repeat(' ', self.__cmp.win_screenpos(0)[1])
let ident = repeat(' ', self.__cmp.win_screenpos(0)[1] - 1)
echohl Comment | echon ident . self._prompt.mpt
echohl None | echon self._prompt.begin
echohl Wildmenu | echon self._prompt.cursor

View File

@ -27,6 +27,15 @@
" has(feature)
"
" check if {feature} is supported in current version.
"
" getjumplist()
"
" return a list of jump position, like result of |:jump|
" Load SpaceVim API:
let s:STRING = SpaceVim#api#import('data#string')
let s:self = {}
@ -249,9 +258,31 @@ else
endif
function! s:self.set_buf_line() abort
endfunction
if exists('*getjumplist')
function! s:self.getjumplist() abort
return getjumplist()
endfunction
else
function! s:self.getjumplist() abort
let jumpinfo = split(self.execute(':jumps'), "\n")[1:-2]
let result = []
" 20 281 23 -invalid-
for info in jumpinfo
let [jump, line, col, file_text] = s:STRING.split(info, '', 0, 4)
call add(result, {
\ 'bufnr' : jump,
\ 'lnum' : line,
\ 'col' : col,
\ })
endfor
return result
endfunction
endif
function! SpaceVim#api#vim#compatible#get() abort
return deepcopy(s:self)
endfunction

View File

@ -24,7 +24,7 @@ let s:search_tools.a = {}
let s:search_tools.a.command = 'ag'
let s:search_tools.a.default_opts =
\ [
\ '-i', '--column', '--hidden', '--ignore',
\ '-i', '--nocolor', '--filename', '--noheading', '--column', '--hidden', '--ignore',
\ '.hg', '--ignore', '.svn', '--ignore', '.git', '--ignore', '.bzr',
\ ]
let s:search_tools.a.recursive_opt = []

View File

@ -43,6 +43,7 @@ function! s:grep_timer(timer) abort
endif
let cmd = s:get_search_cmd(s:current_grep_pattern)
call SpaceVim#logger#info('grep cmd: ' . string(cmd))
call SpaceVim#logger#info('full cmd: ' . join(cmd))
let s:grepid = s:JOB.start(cmd, {
\ 'on_stdout' : function('s:grep_stdout'),
\ 'on_stderr' : function('s:grep_stderr'),
@ -64,17 +65,28 @@ function! s:get_search_cmd(expr) abort
endif
let cmd += s:grep_expr_opt
if !empty(s:grep_files) && type(s:grep_files) == 3
" grep files is a list, which mean to use flygrep searching in
" multiple files
let cmd += [a:expr] + s:grep_files
elseif !empty(s:grep_files) && type(s:grep_files) == 1
" grep file is a single file
let cmd += [a:expr] + [s:grep_files]
elseif !empty(s:grep_dir)
" grep dir is not a empty string
if s:grep_exe == 'findstr'
let cmd += [s:grep_dir] + [a:expr] + ['%CD%\*']
else
let cmd += [a:expr] + [s:grep_dir]
endif
else
let cmd += [a:expr] + s:grep_ropt
" if grep dir is empty, grep files is empty, which means searhing in
" current directory.
let cmd += [a:expr]
" in window, when using rg, ag, need to add '.' at the end.
if s:SYS.isWindows && (s:grep_exe == 'rg' || s:grep_exe == 'ag' )
let cmd += ['.']
endif
let cmd += s:grep_ropt
endif
" let cmd = map(cmd, 'shellescape(v:val)')
" if has('win32')
@ -211,7 +223,7 @@ endfunction
" }}}
" API: MPT._prompt {{{
let s:MPT._prompt.mpt = ' '
let s:MPT._prompt.mpt = g:spacevim_commandline_prompt . ' '
" }}}
" API: MPT._onclose {{{
@ -250,6 +262,8 @@ function! s:grep_stdout(id, data, event) abort
let datas =filter(a:data, '!empty(v:val)')
" let datas = s:LIST.uniq_by_func(datas, function('s:file_line'))
if bufnr('%') == s:flygrep_buffer_id
" You probably split lines by \n, but Windows ses \r\n, so the \r (displayed via ^M) is still left.
" ag support is broken in windows + neovim-qt
if getline(1) ==# ''
call setline(1, datas)
else

View File

@ -13,7 +13,7 @@ let s:denite_options = {
\ 'highlight_matched_range' : 'MoreMsg',
\ 'direction': 'rightbelow',
\ 'statusline' : has('patch-7.4.1154') ? v:false : 0,
\ 'prompt' : '➭',
\ 'prompt' : g:spacevim_commandline_prompt,
\ }}
function! s:profile(opts) abort

View File

@ -20,6 +20,18 @@ SpaceVim 中代码检索采用的是 FlyGrep 这个插件,包括了常用的
![searching project](https://user-images.githubusercontent.com/13142418/35278709-7856ed62-0010-11e8-8b1e-e6cc6374b0dc.gif)
## 安装搜索工具
FlyGrep 异步调用搜索工具,搜索并展示结果,目前支持的搜索工具包括:`rg`, `ag`, `pt`, `grep`, `findstr`, `ack`
以上这些工具在 Linux 系统下默认包含了 `grep`Windows 系统下默认包含了 `findstr`。其他工具安装方式如下:
### Windows
在 Windows 下,可以直接下载解压,可执行文件所在目录加入 `PATH` 即可。
- rg: [ripgrep releases](https://github.com/BurntSushi/ripgrep/releases)
- ag: [the_silver_searcher-win32](https://github.com/k-takata/the_silver_searcher-win32/releases)
## 特性
- 实时检索全工程文件

View File

@ -1,5 +1,6 @@
Execute ( SpaceVim api: data#string ):
let str = SpaceVim#api#import('data#string')
AssertEqual str.split(' 20 281 23 -invalid-', '', 0, 4)[2], '23'
AssertEqual str.trim(' s b '), 's b'
AssertEqual str.trim_start(' s b '), 's b '
AssertEqual str.trim_end(' s b '), ' s b'

View File

@ -45,7 +45,7 @@
- Fix FlyGrep syntax to support different outputs ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2363), [`0b26f40`](https://github.com/SpaceVim/SpaceVim/commit/0b26f407d879427505418f5c3b4c1d753f3f4317))
- Fix `project_rooter_automatically = 0` option to not change directory to project root ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2365))
- Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369))
- Fix flygrep and neovim support in windows os ([#2371](https://github.com/SpaceVim/SpaceVim/pull/2371))
### 移除的功能
@ -57,7 +57,6 @@
## 上一个版本
SpaceVim 于 2018-09-26 发布 v0.9.0 版本,可查阅办法发布文章:
SpaceVim 于 2018-09-26 发布 v0.9.0 版本,可查阅版本发布文章:
- [SpaceVim 发布 v0.9.0 版本](https://spacevim.org/SpaceVim-release-v0.9.0/)

View File

@ -41,9 +41,11 @@ The next release is v1.0.0.
- Fix dein-ui error, add syntax ([#2352](https://github.com/SpaceVim/SpaceVim/pull/2352), [`c9e1d4c`](https://github.com/SpaceVim/SpaceVim/commit/c9e1d4c9635c483bb3334c00ed36026d18950070))
- Fix fullscreen key binding ([#2351](https://github.com/SpaceVim/SpaceVim/pull/2351))
- Added missed syntax for detached FlyGrep ([#2353](https://github.com/SpaceVim/SpaceVim/pull/2353), [`08d0713`](https://github.com/SpaceVim/SpaceVim/commit/08d0713c4494ca401942a6ca10a48a1ac8484ce1))
- Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369))
- Fix FlyGrep syntax to support different outputs ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2363), [`0b26f40`](https://github.com/SpaceVim/SpaceVim/commit/0b26f407d879427505418f5c3b4c1d753f3f4317))
- Fix `project_rooter_automatically = 0` option to not change directory to project root ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2365))
- Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369))
- Fix flygrep and neovim support in windows os ([#2371](https://github.com/SpaceVim/SpaceVim/pull/2371))
### Removed
@ -55,5 +57,6 @@ The next release is v1.0.0.
## Latest Release
SpaceVim releases v0.9.0 at 2018-09-26, please check the
[release page](https://spacevim.org/SpaceVim-release-v0.9.0/) for all the details
SpaceVim releases v0.9.0 at 2018-09-26, please check the release page:
- [SpaceVim releases v0.9.0](https://spacevim.org/SpaceVim-release-v0.9.0/) for all the details