mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 22:20:06 +08:00
Improve runner plugin (#2397)
This commit is contained in:
parent
bf8181deb4
commit
992584d8b8
@ -331,6 +331,18 @@ let g:spacevim_statusline_inactive_separator = 'arrow'
|
||||
" Enable/Disable showing full path of current buffer on statusline
|
||||
let g:spacevim_enable_statusline_bfpath = 0
|
||||
|
||||
""
|
||||
" @section enable_statusline_tag, options-enable_statusline_tag
|
||||
" @parentsection options
|
||||
" Enable/Disable showing current tag on statusline
|
||||
" >
|
||||
" enable_statusline_tag = false
|
||||
" <
|
||||
|
||||
""
|
||||
" Enable/Disable showing current tag on statusline
|
||||
let g:spacevim_enable_statusline_tag = 1
|
||||
|
||||
""
|
||||
" Define the left section of statusline in active windows. By default:
|
||||
" >
|
||||
|
@ -66,7 +66,7 @@ function! s:self.build(left_sections, right_sections, lsep, rsep, fname, tag, hi
|
||||
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:lsep . '%='
|
||||
endif
|
||||
endif
|
||||
if self.check_width(len, a:tag, a:winwidth)
|
||||
if self.check_width(len, a:tag, a:winwidth) && g:spacevim_enable_statusline_tag
|
||||
let l .= '%#' . a:hi_z . '#' . a:tag
|
||||
endif
|
||||
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:rsep
|
||||
|
@ -22,7 +22,15 @@ function! s:open_win() abort
|
||||
botright split __runner__
|
||||
let lines = &lines * 30 / 100
|
||||
exe 'resize ' . lines
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist
|
||||
\ noswapfile
|
||||
\ nowrap
|
||||
\ cursorline
|
||||
\ nospell
|
||||
\ nonu
|
||||
\ norelativenumber
|
||||
\ winfixheight
|
||||
\ nomodifiable
|
||||
set filetype=SpaceVimRunner
|
||||
nnoremap <silent><buffer> q :call SpaceVim#plugins#runner#close()<cr>
|
||||
let s:bufnr = bufnr('%')
|
||||
@ -34,10 +42,11 @@ let s:target = ''
|
||||
function! s:async_run(runner) abort
|
||||
if type(a:runner) == type('')
|
||||
try
|
||||
let cmd = printf(a:runner, bufname('%'))
|
||||
let cmd = printf(a:runner, get(s:, 'selected_file', bufname('%')))
|
||||
catch
|
||||
let cmd = a:runner
|
||||
endtry
|
||||
call SpaceVim#logger#info(' cmd:' . string(cmd))
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[Running] ' . cmd, '', repeat('-', 20)])
|
||||
let s:lines += 3
|
||||
let s:start_time = reltime()
|
||||
@ -63,7 +72,8 @@ function! s:async_run(runner) abort
|
||||
\ })
|
||||
elseif type(a:runner) == type({})
|
||||
let exe = call(a:runner.exe, [])
|
||||
let cmd = exe + a:runner.opt + [bufname('%')]
|
||||
let cmd = exe + a:runner.opt + [get(s:, 'selected_file', bufname('%'))]
|
||||
call SpaceVim#logger#info(' cmd:' . string(cmd))
|
||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[Running] ' . join(cmd), '', repeat('-', 20)])
|
||||
let s:lines += 3
|
||||
let s:start_time = reltime()
|
||||
@ -104,9 +114,14 @@ endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#reg_runner(ft, runner) abort
|
||||
let s:runners[a:ft] = a:runner
|
||||
let desc = '[' . a:ft . '] ' . string(a:runner)
|
||||
let cmd = "call SpaceVim#plugins#runner#set_language('" . a:ft . "')"
|
||||
call add(g:unite_source_menu_menus.RunnerLanguage.command_candidates, [desc,cmd])
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#open() abort
|
||||
" this func should support specific a runner
|
||||
" the runner can be a string
|
||||
function! SpaceVim#plugins#runner#open(...) abort
|
||||
let s:lines = 0
|
||||
let s:status = {
|
||||
\ 'is_running' : 0,
|
||||
@ -114,7 +129,8 @@ function! SpaceVim#plugins#runner#open() abort
|
||||
\ 'has_errors' : 0,
|
||||
\ 'exit_code' : 0
|
||||
\ }
|
||||
let runner = get(s:runners, &filetype, '')
|
||||
let s:selected_language = get(s:, 'selected_language', &filetype)
|
||||
let runner = get(a:000, 0, get(s:runners, empty(s:selected_language) ? &filetype : s:selected_language , ''))
|
||||
if !empty(runner)
|
||||
call s:open_win()
|
||||
call s:async_run(runner)
|
||||
@ -199,6 +215,7 @@ function! SpaceVim#plugins#runner#status() abort
|
||||
elseif s:status.is_exit == 1
|
||||
return 'exit code : ' . s:status.exit_code
|
||||
\ . ' time: ' . s:STRING.trim(reltimestr(s:end_time))
|
||||
\ . ' language: ' . get(s:, 'selected_language', &ft)
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
@ -209,3 +226,44 @@ function! SpaceVim#plugins#runner#close() abort
|
||||
endif
|
||||
exe 'bd ' s:bufnr
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#select_file() abort
|
||||
let s:lines = 0
|
||||
let s:status = {
|
||||
\ 'is_running' : 0,
|
||||
\ 'is_exit' : 0,
|
||||
\ 'has_errors' : 0,
|
||||
\ 'exit_code' : 0
|
||||
\ }
|
||||
let s:selected_file = browse(0,'select a file to run', getcwd(), '')
|
||||
let runner = get(a:000, 0, get(s:runners, &filetype, ''))
|
||||
let s:selected_language = &filetype
|
||||
if !empty(runner)
|
||||
call SpaceVim#logger#info('Code runner startting:')
|
||||
call SpaceVim#logger#info('selected file :' . s:selected_file)
|
||||
call s:open_win()
|
||||
call s:async_run(runner)
|
||||
call s:update_statusline()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let g:unite_source_menu_menus =
|
||||
\ get(g:,'unite_source_menu_menus',{})
|
||||
let g:unite_source_menu_menus.RunnerLanguage = {'description':
|
||||
\ 'Custom mapped keyboard shortcuts [SPC] p p'}
|
||||
let g:unite_source_menu_menus.RunnerLanguage.command_candidates =
|
||||
\ get(g:unite_source_menu_menus.RunnerLanguage,'command_candidates', [])
|
||||
|
||||
function! SpaceVim#plugins#runner#select_language()
|
||||
" @todo use denite or unite to select language
|
||||
" and set the s:selected_language
|
||||
" the all language is keys(s:runners)
|
||||
Denite menu:RunnerLanguage
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#runner#set_language(lang)
|
||||
" @todo use denite or unite to select language
|
||||
" and set the s:selected_language
|
||||
" the all language is keys(s:runners)
|
||||
let s:selected_language = a:lang
|
||||
endfunction
|
||||
|
@ -26,18 +26,19 @@ CONTENTS *SpaceVim-contents*
|
||||
6. enable_insert_leader..........|SpaceVim-options-enable_insert_leader|
|
||||
7. enable_neomake......................|SpaceVim-options-enable_neomake|
|
||||
8. enable_statusline_mode......|SpaceVim-options-enable_statusline_mode|
|
||||
9. enable_ycm..............................|SpaceVim-options-enable_ycm|
|
||||
10. error_symbol.........................|SpaceVim-options-error_symbol|
|
||||
11. guifont...................................|SpaceVim-options-guifont|
|
||||
12. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly|
|
||||
13. max_column.............................|SpaceVim-options-max_column|
|
||||
14. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir|
|
||||
15. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes|
|
||||
16. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide|
|
||||
17. relativenumber.....................|SpaceVim-options-relativenumber|
|
||||
18. sidebar_width.......................|SpaceVim-options-sidebar_width|
|
||||
19. snippet_engine.....................|SpaceVim-options-snippet_engine|
|
||||
20. windows_leader.....................|SpaceVim-options-windows_leader|
|
||||
9. enable_statusline_tag........|SpaceVim-options-enable_statusline_tag|
|
||||
10. enable_ycm.............................|SpaceVim-options-enable_ycm|
|
||||
11. error_symbol.........................|SpaceVim-options-error_symbol|
|
||||
12. guifont...................................|SpaceVim-options-guifont|
|
||||
13. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly|
|
||||
14. max_column.............................|SpaceVim-options-max_column|
|
||||
15. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir|
|
||||
16. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes|
|
||||
17. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide|
|
||||
18. relativenumber.....................|SpaceVim-options-relativenumber|
|
||||
19. sidebar_width.......................|SpaceVim-options-sidebar_width|
|
||||
20. snippet_engine.....................|SpaceVim-options-snippet_engine|
|
||||
21. windows_leader.....................|SpaceVim-options-windows_leader|
|
||||
3. Configuration...........................................|SpaceVim-config|
|
||||
4. Commands..............................................|SpaceVim-commands|
|
||||
5. Functions............................................|SpaceVim-functions|
|
||||
@ -179,6 +180,14 @@ statusline. To enable this feature:
|
||||
enable_statusline_mode = true
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
ENABLE_STATUSLINE_TAG *SpaceVim-options-enable_statusline_tag*
|
||||
|
||||
Enable/Disable showing current tag on statusline
|
||||
>
|
||||
enable_statusline_tag = false
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
ENABLE_YCM *SpaceVim-options-enable_ycm*
|
||||
|
||||
@ -418,6 +427,9 @@ See more details in: http://spacevim.org/documentation/#statusline
|
||||
*g:spacevim_enable_statusline_bfpath*
|
||||
Enable/Disable showing full path of current buffer on statusline
|
||||
|
||||
*g:spacevim_enable_statusline_tag*
|
||||
Enable/Disable showing current tag on statusline
|
||||
|
||||
*g:spacevim_statusline_left_sections*
|
||||
Define the left section of statusline in active windows. By default:
|
||||
>
|
||||
|
@ -87,6 +87,7 @@ lang: cn
|
||||
- [Examples](#examples)
|
||||
- [注释(Commentings)](#注释commentings)
|
||||
- [多方式编码](#多方式编码)
|
||||
- [异步运行器和交互式编程](#异步运行器和交互式编程)
|
||||
- [错误处理](#错误处理)
|
||||
- [工程管理](#工程管理)
|
||||
- [Searching files in project](#searching-files-in-project)
|
||||
@ -1696,6 +1697,28 @@ set enc=utf-8
|
||||
write
|
||||
```
|
||||
|
||||
### 异步运行器和交互式编程
|
||||
|
||||
SpaceVim 提供了一个异步执行命令和交互式编程的插件,
|
||||
在大多数语言模块中,已经为该语言定义了默认的执行命令,通常快捷键为`SPC l r`。
|
||||
如果需要添加额外的命令,可以使用启动函数。比如:添加使用 F5 按键异步编译当前项目。
|
||||
|
||||
```viml
|
||||
nnoremap <silent> <F5> :call SpaceVim#plugins#runner#open('make')
|
||||
```
|
||||
|
||||
目前,SpaceVim 支持如下特性:
|
||||
|
||||
- 使用默认命令一键运行当前文件
|
||||
- 使用系统文件管理器选择文件并执行
|
||||
- 根据文件顶部标识,选择合适解析器
|
||||
- 中断代码运行
|
||||
- 底部窗口异步展示运行结果
|
||||
- 设置默认的运行语言
|
||||
- 选择指定语言来运行
|
||||
- 支持交互式编程
|
||||
- 运行选择的代码片段
|
||||
|
||||
### 错误处理
|
||||
|
||||
SpaceVim 通过 [neomake](https://github.com/neomake/neomake) fly 工具来进行错误反馈. 默认在操作保存时进行错误检查.
|
||||
|
@ -85,6 +85,7 @@ description: "General documentation about how to using SpaceVim, including the q
|
||||
- [Examples](#examples)
|
||||
- [Commenting](#commenting)
|
||||
- [Multi-Encodings](#multi-encodings)
|
||||
- [Code runner and REPL](#code-runner-and-repl)
|
||||
- [Errors handling](#errors-handling)
|
||||
- [Managing projects](#managing-projects)
|
||||
- [Searching files in project](#searching-files-in-project)
|
||||
@ -1738,6 +1739,29 @@ set enc=utf-8
|
||||
write
|
||||
```
|
||||
|
||||
### Code runner and REPL
|
||||
|
||||
SpaceVim provides an asynchronously code runner plugin. In most language layer,
|
||||
we have defind a key bidning `SPC l r` for running current
|
||||
buffer. If you need to add new command, you can use bootstrap func. for example:
|
||||
use `F5` to build project asynchronously.
|
||||
|
||||
```viml
|
||||
nnoremap <silent> <F5> :call SpaceVim#plugins#runner#open('make')
|
||||
```
|
||||
|
||||
These following features have been added to runner and repl plugin:
|
||||
|
||||
- Run current file with default command
|
||||
- Run code file through system file explorer, only supported in gvim.
|
||||
- Run code per Shebang
|
||||
- Stop code running
|
||||
- View output in Output Window
|
||||
- Set default language to run
|
||||
- Select language to run
|
||||
- REPL support
|
||||
- Run selected code snippet
|
||||
|
||||
### Errors handling
|
||||
|
||||
SpaceVim uses [neomake](https://github.com/neomake/neomake) to gives error feedback on the fly.
|
||||
|
Loading…
Reference in New Issue
Block a user