mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 01:00:05 +08:00
Fix task manager (#3853)
This commit is contained in:
parent
2a35ca445e
commit
c0b9b721ce
@ -1,7 +1,7 @@
|
||||
{
|
||||
"autoload/SpaceVim/api/*.vim": {
|
||||
"alternate": "test/api/{}.vader",
|
||||
"doc" : "docs/api/{}.md"
|
||||
"doc": "docs/api/{}.md"
|
||||
},
|
||||
"autoload/SpaceVim/plugins/a.vim": { "alternate": "test/plugin/a.vader" },
|
||||
"test/plugin/a.vader": { "alternate": "autoload/SpaceVim/plugins/a.vim" },
|
||||
@ -97,16 +97,16 @@
|
||||
"docs/_posts/2019-07-16-Asynchronous-todo-manager.md": {
|
||||
"alternate": "docs/_posts/2019-07-17-Asynchronous-todo-manager.md"
|
||||
},
|
||||
"docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md" : {
|
||||
"docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md": {
|
||||
"alternate": "docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md"
|
||||
},
|
||||
"docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md" : {
|
||||
"docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md": {
|
||||
"alternate": "docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md"
|
||||
},
|
||||
"README.md" : {
|
||||
"alternate" : "README.cn.md"
|
||||
"README.md": {
|
||||
"alternate": "README.cn.md"
|
||||
},
|
||||
"README.cn.md" : {
|
||||
"alternate" : "README.md"
|
||||
"README.cn.md": {
|
||||
"alternate": "README.md"
|
||||
}
|
||||
}
|
||||
|
@ -397,13 +397,17 @@ function! SpaceVim#plugins#runner#run_task(task) abort
|
||||
if !empty(args) && !empty(cmd)
|
||||
let cmd = cmd . ' ' . join(args, ' ')
|
||||
endif
|
||||
let opt = {}
|
||||
if !empty(opts) && has_key(opts, 'cwd') && !empty(opts.cwd)
|
||||
let opts = {'cwd' : opts.cwd}
|
||||
call extend(opt, {'cwd' : opts.cwd})
|
||||
endif
|
||||
if !empty(opts) && has_key(opts, 'env') && !empty(opts.env)
|
||||
call extend(opt, {'env' : opts.env})
|
||||
endif
|
||||
if isBackground
|
||||
call s:run_backgroud(cmd, opts)
|
||||
call s:run_backgroud(cmd, opt)
|
||||
else
|
||||
call SpaceVim#plugins#runner#open(cmd, opts)
|
||||
call SpaceVim#plugins#runner#open(cmd, opt)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -20,6 +20,7 @@ let s:FILE = SpaceVim#api#import('file')
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
let s:SYS = SpaceVim#api#import('system')
|
||||
let s:MENU = SpaceVim#api#import('cmdlinemenu')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
|
||||
" task object
|
||||
|
||||
@ -106,6 +107,9 @@ function! SpaceVim#plugins#tasks#get()
|
||||
if has_key(task, 'command') && type(task.command) ==# 1
|
||||
let task.command = s:replace_variables(task.command)
|
||||
endif
|
||||
if has_key(task, 'args') && s:VIM.is_list(task.args)
|
||||
let task.args = map(task.args, 's:replace_variables(v:val)')
|
||||
endif
|
||||
if has_key(task, 'options') && type(task.options) ==# 4
|
||||
if has_key(task.options, 'cwd') && type(task.options.cwd) ==# 1
|
||||
let task.options.cwd = s:replace_variables(task.options.cwd)
|
||||
|
@ -81,9 +81,9 @@ lang: zh
|
||||
- [自定义跳转文件](#自定义跳转文件)
|
||||
- [标签管理](#标签管理)
|
||||
- [任务管理](#任务管理)
|
||||
- [自定义任务](#自定义任务)
|
||||
- [任务自动识别](#任务自动识别)
|
||||
- [任务提供源](#任务提供源)
|
||||
- [自定义任务](#自定义任务)
|
||||
- [Iedit 多光标编辑](#iedit-多光标编辑)
|
||||
- [Iedit 快捷键](#iedit-快捷键)
|
||||
- [高亮光标下变量](#高亮光标下变量)
|
||||
@ -1863,13 +1863,75 @@ endfunction
|
||||
### 任务管理
|
||||
|
||||
通过内置的任务管理系统,可以快速集成外部命令工具,类似于 vscode 的任务管理系统,
|
||||
支持项目局部配置文件(`.SpaceVim.d/tasks.toml`)和全局配置文件(`~/.SpaceVim.d/tasks.toml`),项目局部配置文件具有更高的优先权:
|
||||
在 SpaceVim 中,目前支持的任务配置文件包括两种:
|
||||
|
||||
- `~/.SpaceVim.d/tasks.toml`:全局配置文件
|
||||
- `.SpaceVim.d/tasks.toml`:项目局部配置文件
|
||||
|
||||
全局配置中定义的任务,默认会被项目局部配置文件中定义的任务覆盖掉。
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ----------- | ---------------- |
|
||||
| `SPC p t e` | 编辑任务配置文件 |
|
||||
| `SPC p t r` | 选定任务并执行 |
|
||||
|
||||
#### 自定义任务
|
||||
|
||||
以下为一个简单的任务配置示例,异步运行 `echo hello world`,并将结果打印至输出窗口。
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
```
|
||||
|
||||
![task hello world](https://user-images.githubusercontent.com/13142418/74582981-74049900-4ffd-11ea-9b38-7858042225b9.png)
|
||||
|
||||
对于不需要打印输出结果,后台运行的任务,可以设置 `isBackground` 为 `true`:
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
isBackground = true
|
||||
```
|
||||
|
||||
任务的配置,可以设置如下关键字:
|
||||
|
||||
- **command**: 需要运行的命令。
|
||||
- **args**: 传递给命令的参数,值为字符串数组
|
||||
- **options**: 设置命令运行的一些选项,比如 `cwd`,`env` 或者 `shell`。
|
||||
- **isBackground**: 可设定的值为 `true` 或者 `false`, 默认是 `false`,
|
||||
设置是否需要后台运行任务
|
||||
|
||||
在编辑任务配置文件时,可以使用一些预设定的变量,以下列出目前已经支持的预设定变量:
|
||||
|
||||
- **\${workspaceFolder}**: - 当前项目的根目录;
|
||||
- **\${workspaceFolderBasename}**: - 当前项目根目录所在父目录的文件夹名称;
|
||||
- **\${file}**: - 当前文件的绝对路径;
|
||||
- **\${relativeFile}**: - 当前文件相对项目根目录的相对路径;
|
||||
- **\${relativeFileDirname}**: - 当前文件所在的文件夹相对项目根目录的相对路径;
|
||||
- **\${fileBasename}**: - 当前文件的文件名
|
||||
- **\${fileBasenameNoExtension}**: - 当前文件的文件名,不包括后缀名
|
||||
- **\${fileDirname}**: - 当前文件所在的目录的绝对路径
|
||||
- **\${fileExtname}**: - 当前文件的后缀名
|
||||
- **\${lineNumber}**: - 光标所在行号
|
||||
|
||||
例如:假定目前正在编辑文件 `/home/your-username/your-project/folder/file.ext` ,光标位于第十行;
|
||||
该文件所在的项目根目录为 `/home/your-username/your-project`,那么任务系统的预设定变量的值为:
|
||||
|
||||
- **\${workspaceFolder}**: - `/home/your-username/your-project/`
|
||||
- **\${workspaceFolderBasename}**: - `your-project`
|
||||
- **\${file}**: - `/home/your-username/your-project/folder/file.ext`
|
||||
- **\${relativeFile}**: - `folder/file.ext`
|
||||
- **\${relativeFileDirname}**: - `folder/`
|
||||
- **\${fileBasename}**: - `file.ext`
|
||||
- **\${fileBasenameNoExtension}**: - `file`
|
||||
- **\${fileDirname}**: - `/home/your-username/your-project/folder/`
|
||||
- **\${fileExtname}**: - `.ext`
|
||||
- **\${lineNumber}**: - `10`
|
||||
|
||||
|
||||
#### 任务自动识别
|
||||
|
||||
SpaceVim 目前支持自动识别以下构建系统的任务:npm。
|
||||
@ -1920,60 +1982,6 @@ call SpaceVim#plugins#tasks#reg_provider(funcref('s:make_tasks'))
|
||||
|
||||
![task-make](https://user-images.githubusercontent.com/13142418/75105016-084cac80-564b-11ea-9fe6-75d86a0dbb9b.png)
|
||||
|
||||
#### 自定义任务
|
||||
|
||||
以下为一个简单的任务配置示例,异步运行 `echo hello world`,并将结果打印至输出窗口。
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
```
|
||||
|
||||
![task hello world](https://user-images.githubusercontent.com/13142418/74582981-74049900-4ffd-11ea-9b38-7858042225b9.png)
|
||||
|
||||
对于不需要打印输出结果,后台运行的任务,可以设置 `isBackground` 为 `true`:
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
isBackground = true
|
||||
```
|
||||
|
||||
任务的配置,可以设置如下关键字:
|
||||
|
||||
- **command**: 需要运行的命令。
|
||||
- **args**: 传递给命令的参数,可以省略。
|
||||
- **options**: 设置命令运行的一些选项,比如 `cwd`,`env` 或者 `shell`。
|
||||
|
||||
在编辑任务配置文件时,可以使用一些预设定的变量,以下列出目前已经支持的预设定变量:
|
||||
|
||||
- **\${workspaceFolder}**: - 当前项目的根目录;
|
||||
- **\${workspaceFolderBasename}**: - 当前项目根目录所在父目录的文件夹名称;
|
||||
- **\${file}**: - 当前文件的绝对路径;
|
||||
- **\${relativeFile}**: - 当前文件相对项目根目录的相对路径;
|
||||
- **\${relativeFileDirname}**: - 当前文件所在的文件夹相对项目根目录的相对路径;
|
||||
- **\${fileBasename}**: - 当前文件的文件名
|
||||
- **\${fileBasenameNoExtension}**: - 当前文件的文件名,不包括后缀名
|
||||
- **\${fileDirname}**: - 当前文件所在的目录的绝对路径
|
||||
- **\${fileExtname}**: - 当前文件的后缀名
|
||||
- **\${lineNumber}**: - 光标所在行号
|
||||
|
||||
例如:假定目前正在编辑文件 `/home/your-username/your-project/folder/file.ext` ,光标位于第十行;
|
||||
该文件所在的项目根目录为 `/home/your-username/your-project`,那么任务系统的预设定变量的值为:
|
||||
|
||||
- **\${workspaceFolder}**: - `/home/your-username/your-project/`
|
||||
- **\${workspaceFolderBasename}**: - `your-project`
|
||||
- **\${file}**: - `/home/your-username/your-project/folder/file.ext`
|
||||
- **\${relativeFile}**: - `folder/file.ext`
|
||||
- **\${relativeFileDirname}**: - `folder/`
|
||||
- **\${fileBasename}**: - `file.ext`
|
||||
- **\${fileBasenameNoExtension}**: - `file`
|
||||
- **\${fileDirname}**: - `/home/your-username/your-project/folder/`
|
||||
- **\${fileExtname}**: - `.ext`
|
||||
- **\${lineNumber}**: - `10`
|
||||
|
||||
### Iedit 多光标编辑
|
||||
|
||||
SpaceVim 内置了 iedit 多光标模式,可快速进行多光标编辑。这一功能引入了两个新的模式:`iedit-Normal` 模式和 `iedit-Insert`。
|
||||
|
@ -80,9 +80,9 @@ description: "General documentation about how to using SpaceVim, including the q
|
||||
- [Custom alternate file](#custom-alternate-file)
|
||||
- [Bookmarks management](#bookmarks-management)
|
||||
- [Tasks](#tasks)
|
||||
- [Custom tasks](#custom-tasks)
|
||||
- [Task auto-detection](#task-auto-detection)
|
||||
- [Task provider](#task-provider)
|
||||
- [Custom tasks](#custom-tasks)
|
||||
- [Replace text with iedit](#replace-text-with-iedit)
|
||||
- [iedit states key bindings](#iedit-states-key-bindings)
|
||||
- [Code runner and REPL](#code-runner-and-repl)
|
||||
@ -1907,16 +1907,84 @@ endfunction
|
||||
|
||||
To integrate with external tools, SpaceVim introduce a task manager system,
|
||||
which is similar to vscode tasks-manager. There are two kinds of task configuration
|
||||
file: global tasks configuration(`~/.SpaceVim.d/tasks.toml`) and local configuration(`.SpaceVim.d/tasks.toml`).
|
||||
file:
|
||||
|
||||
- `~/.SpaceVim.d/tasks.toml`: global tasks configuration
|
||||
- `.SpaceVim.d/tasks.toml`: project local tasks configuration
|
||||
|
||||
The task defined in global tasks configuration can be overrided by project local
|
||||
tasks configuration.
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------ | ----------------------------- |
|
||||
| `SPC p t e` | edit tasks configuration file |
|
||||
| `SPC p t r` | select task to run |
|
||||
|
||||
|
||||
#### Custom tasks
|
||||
|
||||
This is basic task configuration for running `echo hello world`,
|
||||
and print results to runner windows.
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
```
|
||||
|
||||
![task hello world](https://user-images.githubusercontent.com/13142418/74582981-74049900-4ffd-11ea-9b38-7858042225b9.png)
|
||||
|
||||
To run task in the background, you need to set `isBackground` to `true`:
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
isBackground = true
|
||||
```
|
||||
|
||||
The task's properties have the following semantic:
|
||||
|
||||
- **command**: the actual command to execute.
|
||||
- **args**: the arguments passed to the command, it shoud be an array a string list and can be omitted.
|
||||
- **options**: override the defaults for `cwd`,`env` or `shell`.
|
||||
- **isBackground**: `true` or `false`, specifies whether background running is required,
|
||||
by default, it is `false`.
|
||||
|
||||
SpaceVim supports variable substitution in task, The following predefined variables are supported:
|
||||
|
||||
- **\${workspaceFolder}**: - the project root directory
|
||||
- **\${workspaceFolderBasename}**: - the parent directory name of current project root
|
||||
- **\${file}**: - the path of current file
|
||||
- **\${relativeFile}**: - the current file relative to project root
|
||||
- **\${relativeFileDirname}**: - the current file's dirname relative to workspaceFolder
|
||||
- **\${fileBasename}**: - the current file's basename
|
||||
- **\${fileBasenameNoExtension}**: - the current file's basename without file extension
|
||||
- **\${fileDirname}**: - the current file's dirname
|
||||
- **\${fileExtname}**: - the current file's extension
|
||||
- **\${cwd}**: - the task runner's current working directory on startup
|
||||
- **\${lineNumber}**: - the current selected line number in the active file
|
||||
|
||||
for example: Supposing that you have the following requirements:
|
||||
|
||||
A file located at `/home/your-username/your-project/folder/file.ext` opened in your editor;
|
||||
The directory `/home/your-username/your-project` opened as your root workspace.
|
||||
So you will have the following values for each variable:
|
||||
|
||||
- **\${workspaceFolder}**: - `/home/your-username/your-project/`
|
||||
- **\${workspaceFolderBasename}**: - `your-project`
|
||||
- **\${file}**: - `/home/your-username/your-project/folder/file.ext`
|
||||
- **\${relativeFile}**: - `folder/file.ext`
|
||||
- **\${relativeFileDirname}**: - `folder/`
|
||||
- **\${fileBasename}**: - `file.ext`
|
||||
- **\${fileBasenameNoExtension}**: - `file`
|
||||
- **\${fileDirname}**: - `/home/your-username/your-project/folder/`
|
||||
- **\${fileExtname}**: - `.ext`
|
||||
- **\${lineNumber}**: - line number of the cursor
|
||||
|
||||
#### Task auto-detection
|
||||
|
||||
SpaceVim currently auto-detects tasks for npm.
|
||||
Currently, SpaceVim can auto-detect tasks for npm.
|
||||
the tasks manager will paser the `package.json` file for npm systems.
|
||||
If you have cloned the [eslint-starter](https://github.com/spicydonuts/eslint-starter) example,
|
||||
then pressing `SPC p t r` shows the following list:
|
||||
@ -1966,64 +2034,6 @@ with above configuration, you will see following tasks in SpaceVim repo:
|
||||
|
||||
![task-make](https://user-images.githubusercontent.com/13142418/75105016-084cac80-564b-11ea-9fe6-75d86a0dbb9b.png)
|
||||
|
||||
#### Custom tasks
|
||||
|
||||
this is basic task configuration for running `echo hello world`, and print results to runner windows.
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
```
|
||||
|
||||
![task hello world](https://user-images.githubusercontent.com/13142418/74582981-74049900-4ffd-11ea-9b38-7858042225b9.png)
|
||||
|
||||
To run task in the background, you need to set `isBackground` to `true`:
|
||||
|
||||
```toml
|
||||
[my-task]
|
||||
command = 'echo'
|
||||
args = ['hello world']
|
||||
isBackground = true
|
||||
```
|
||||
|
||||
The task's properties have the following semantic:
|
||||
|
||||
- **command**: the actual command to execute.
|
||||
- **args**: the arguments passed to the command. can be omitted.
|
||||
- **options**: override the defaults for `cwd`,`env` or `shell`.
|
||||
|
||||
SpaceVim supports variable substitution in task, The following predefined variables are supported:
|
||||
|
||||
- **\${workspaceFolder}**: - the project root directory
|
||||
- **\${workspaceFolderBasename}**: - the parent directory name of current project root
|
||||
- **\${file}**: - the path of current file
|
||||
- **\${relativeFile}**: - the current file relative to project root
|
||||
- **\${relativeFileDirname}**: - the current file's dirname relative to workspaceFolder
|
||||
- **\${fileBasename}**: - the current file's basename
|
||||
- **\${fileBasenameNoExtension}**: - the current file's basename without file extension
|
||||
- **\${fileDirname}**: - the current file's dirname
|
||||
- **\${fileExtname}**: - the current file's extension
|
||||
- **\${cwd}**: - the task runner's current working directory on startup
|
||||
- **\${lineNumber}**: - the current selected line number in the active file
|
||||
|
||||
for example: Supposing that you have the following requirements:
|
||||
|
||||
A file located at `/home/your-username/your-project/folder/file.ext` opened in your editor;
|
||||
The directory `/home/your-username/your-project` opened as your root workspace.
|
||||
So you will have the following values for each variable:
|
||||
|
||||
- **\${workspaceFolder}**: - `/home/your-username/your-project/`
|
||||
- **\${workspaceFolderBasename}**: - `your-project`
|
||||
- **\${file}**: - `/home/your-username/your-project/folder/file.ext`
|
||||
- **\${relativeFile}**: - `folder/file.ext`
|
||||
- **\${relativeFileDirname}**: - `folder/`
|
||||
- **\${fileBasename}**: - `file.ext`
|
||||
- **\${fileBasenameNoExtension}**: - `file`
|
||||
- **\${fileDirname}**: - `/home/your-username/your-project/folder/`
|
||||
- **\${fileExtname}**: - `.ext`
|
||||
- **\${lineNumber}**: - line number of the cursor
|
||||
|
||||
### Replace text with iedit
|
||||
|
||||
SpaceVim uses a powerful iedit mode to quick edit multiple occurrences of a symbol or selection.
|
||||
|
Loading…
Reference in New Issue
Block a user