mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 15:19:12 +08:00
Update rust post
This commit is contained in:
parent
c67e32b033
commit
bc415d2b7c
@ -23,6 +23,7 @@ Each of the following sections will be covered:
|
||||
- [Code formatting](#code-formatting)
|
||||
- [running code](#running-code)
|
||||
- [REPL support](#repl-support)
|
||||
- [Tasks manager](#tasks-manager)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -86,3 +87,39 @@ send code to inferior process. All key bindings prefix with `SPC l s`, including
|
||||
send whole buffer.
|
||||
|
||||

|
||||
|
||||
### Tasks manager
|
||||
|
||||
The tasks manager provides a function to register task provider. Adding following vim script
|
||||
into bootstrap function, then SpaceVim can detect the cargo tasks.
|
||||
|
||||
```viml
|
||||
function! s:cargo_task() abort
|
||||
if filereadable('Cargo.toml')
|
||||
let commands = ['build', 'run', 'test']
|
||||
let conf = {}
|
||||
for cmd in commands
|
||||
call extend(conf, {
|
||||
\ cmd : {
|
||||
\ 'command': 'cargo',
|
||||
\ 'args' : [cmd],
|
||||
\ 'isDetected' : 1,
|
||||
\ 'detectedName' : 'cargo:'
|
||||
\ }
|
||||
\ })
|
||||
endfor
|
||||
return conf
|
||||
else
|
||||
return {}
|
||||
endif
|
||||
endfunction
|
||||
call SpaceVim#plugins#tasks#reg_provider(funcref('s:cargo_task'))
|
||||
```
|
||||
|
||||
Open SpaceVim with a rust file, after pressing `SPC p t r`, you will see the following tasks menu.
|
||||
|
||||

|
||||
|
||||
The task will run asynchronously, and the results will be shown in the runner buffer.
|
||||
|
||||

|
||||
|
@ -25,6 +25,7 @@ SpaceVim 是一个模块化的 Vim IDE,针对 Rust 这一语言的支持主要
|
||||
- [代码格式化](#代码格式化)
|
||||
- [快速运行](#快速运行)
|
||||
- [交互式编程](#交互式编程)
|
||||
- [任务管理](#任务管理)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -116,3 +117,39 @@ rustup component add rustfmt
|
||||
之后使用快捷键将代码发送至解释器。默认快捷键都以 `SPC l s` 为前缀。
|
||||
|
||||

|
||||
|
||||
### 任务管理
|
||||
|
||||
任务管理器提供了相应的接口,可以根据实际情况自动添加 cargo 任务。比如,
|
||||
在启动函数内添加:
|
||||
|
||||
```viml
|
||||
function! s:cargo_task() abort
|
||||
if filereadable('Cargo.toml')
|
||||
let commands = ['build', 'run', 'test']
|
||||
let conf = {}
|
||||
for cmd in commands
|
||||
call extend(conf, {
|
||||
\ cmd : {
|
||||
\ 'command': 'cargo',
|
||||
\ 'args' : [cmd],
|
||||
\ 'isDetected' : 1,
|
||||
\ 'detectedName' : 'cargo:'
|
||||
\ }
|
||||
\ })
|
||||
endfor
|
||||
return conf
|
||||
else
|
||||
return {}
|
||||
endif
|
||||
endfunction
|
||||
call SpaceVim#plugins#tasks#reg_provider(funcref('s:cargo_task'))
|
||||
```
|
||||
|
||||
打开 rust 项目,按下快捷键`SPC p t r`即可看到如下任务列表。
|
||||
|
||||

|
||||
|
||||
执行效果如下:
|
||||
|
||||

|
||||
|
Loading…
x
Reference in New Issue
Block a user