1
0
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:
Shidong Wang 2020-03-14 22:31:25 +08:00
parent c67e32b033
commit bc415d2b7c
2 changed files with 74 additions and 0 deletions

View File

@ -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.
![rustrepl](https://user-images.githubusercontent.com/13142418/75877531-ef19dc00-5e52-11ea-87c9-bf8b103a690d.png)
### 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.
![image](https://user-images.githubusercontent.com/13142418/76683906-957b9380-6642-11ea-906e-42b6e6a17841.png)
The task will run asynchronously, and the results will be shown in the runner buffer.
![image](https://user-images.githubusercontent.com/13142418/76683919-b04e0800-6642-11ea-8dd8-f7fc0ae7e0cd.png)

View File

@ -25,6 +25,7 @@ SpaceVim 是一个模块化的 Vim IDE针对 Rust 这一语言的支持主要
- [代码格式化](#代码格式化)
- [快速运行](#快速运行)
- [交互式编程](#交互式编程)
- [任务管理](#任务管理)
<!-- vim-markdown-toc -->
@ -116,3 +117,39 @@ rustup component add rustfmt
之后使用快捷键将代码发送至解释器。默认快捷键都以 `SPC l s` 为前缀。
![rustrepl](https://user-images.githubusercontent.com/13142418/75877531-ef19dc00-5e52-11ea-87c9-bf8b103a690d.png)
### 任务管理
任务管理器提供了相应的接口,可以根据实际情况自动添加 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`即可看到如下任务列表。
![image](https://user-images.githubusercontent.com/13142418/76683906-957b9380-6642-11ea-906e-42b6e6a17841.png)
执行效果如下:
![image](https://user-images.githubusercontent.com/13142418/76683919-b04e0800-6642-11ea-8dd8-f7fc0ae7e0cd.png)