mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 13:10:04 +08:00
Update lang#ruby
layer (#4164)
This commit is contained in:
parent
b64eb80789
commit
504a646f05
@ -28,18 +28,18 @@
|
||||
" ''
|
||||
" ]
|
||||
" <
|
||||
" 2. ruby_repl_command: the REPL command for ruby
|
||||
" 2. repl_command: the REPL command for ruby
|
||||
" >
|
||||
" [[layers]]
|
||||
" name = 'lang#ruby'
|
||||
" ruby_repl_command = '~/download/bin/ruby_repl'
|
||||
" repl_command = '~/download/bin/ruby_repl'
|
||||
" <
|
||||
" 3. format_on_save: enable/disable code formation when save ruby file. This
|
||||
" options is disabled by default, to enable it:
|
||||
" >
|
||||
" [[layers]]
|
||||
" name = 'lang#ruby'
|
||||
" ruby_repl_command = '~/download/bin/ruby_repl'
|
||||
" repl_command = '~/download/bin/ruby_repl'
|
||||
" format_on_save = true
|
||||
" <
|
||||
" @subsection Key bindings
|
||||
@ -72,7 +72,8 @@ else
|
||||
\ ''
|
||||
\ ]
|
||||
let s:format_on_save = 0
|
||||
|
||||
let s:lint_on_save = 0
|
||||
let s:enabled_linters = ['rubylint']
|
||||
endif
|
||||
|
||||
function! SpaceVim#layers#lang#ruby#plugins() abort
|
||||
@ -95,12 +96,32 @@ function! SpaceVim#layers#lang#ruby#config() abort
|
||||
else
|
||||
call SpaceVim#plugins#repl#reg('ruby', 'irb')
|
||||
endif
|
||||
if g:spacevim_lint_engine ==# 'neomake'
|
||||
let g:neomake_ruby_enabled_makers = s:enabled_linters
|
||||
for lint in g:neomake_ruby_enabled_makers
|
||||
let g:neomake_ruby_{lint}_remove_invalid_entries = 1
|
||||
endfor
|
||||
endif
|
||||
" Format on save
|
||||
if s:format_on_save
|
||||
call SpaceVim#layers#format#add_filetype({
|
||||
\ 'filetype' : 'ruby',
|
||||
\ 'enable' : 1,
|
||||
\ })
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#lang#ruby#set_variable(var) abort
|
||||
let s:ruby_repl_command = get(a:var, 'repl_command', '')
|
||||
let s:ruby_file_head = get(a:var, 'ruby-file-head', s:ruby_file_head)
|
||||
" add backward compatible for ruby-file-head
|
||||
let s:ruby_file_head = get(a:var,
|
||||
\ 'ruby_file_head',
|
||||
\ get(a:var,
|
||||
\ 'ruby-file-head',
|
||||
\ s:ruby_file_head))
|
||||
let s:format_on_save = get(a:var, 'format_on_save', s:format_on_save)
|
||||
let s:lint_on_save = get(a:var, 'lint_on_save', s:lint_on_save)
|
||||
let s:enabled_linters = get(a:var, 'enabled_linters', s:enabled_linters)
|
||||
endfunction
|
||||
|
||||
function! s:language_specified_mappings() abort
|
||||
@ -126,11 +147,6 @@ function! s:language_specified_mappings() abort
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 's'],
|
||||
\ 'call SpaceVim#plugins#repl#send("selection")',
|
||||
\ 'send selection and keep code buffer focused', 1)
|
||||
let g:_spacevim_mappings_space.l.c = {'name' : '+RuboCop'}
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','c', 'f'],
|
||||
\ 'Neoformat rubocop',
|
||||
\ 'Runs RuboCop on the currently visited file', 1)
|
||||
let g:neomake_ruby_rubylint_remove_invalid_entries = 1
|
||||
endfunction
|
||||
|
||||
function! s:go_to_def() abort
|
||||
@ -144,6 +160,6 @@ endfunction
|
||||
function! SpaceVim#layers#lang#ruby#get_options() abort
|
||||
return [
|
||||
\ 'repl_command',
|
||||
\ 'ruby-file-head'
|
||||
\ 'ruby_file_head'
|
||||
\ ]
|
||||
endfunction
|
||||
|
@ -80,5 +80,9 @@ let s:bash_file_head = ['#!/usr/bin/env bash',
|
||||
\ ]
|
||||
|
||||
function! SpaceVim#layers#lang#sh#set_variable(var) abort
|
||||
let s:bash_file_head = get(a:var, 'bash-file-head', s:bash_file_head)
|
||||
let s:bash_file_head = get(a:var,
|
||||
\ 'bash_file_head',
|
||||
\ get(a:var,
|
||||
\ 'bash-file-head',
|
||||
\ s:bash_file_head))
|
||||
endfunction
|
||||
|
@ -3018,19 +3018,19 @@ OPTIONS
|
||||
''
|
||||
]
|
||||
<
|
||||
2. ruby_repl_command: the REPL command for ruby
|
||||
2. repl_command: the REPL command for ruby
|
||||
|
||||
>
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
ruby_repl_command = '~/download/bin/ruby_repl'
|
||||
repl_command = '~/download/bin/ruby_repl'
|
||||
<
|
||||
3. format_on_save: enable/disable code formation when save ruby file. This
|
||||
options is disabled by default, to enable it:
|
||||
>
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
ruby_repl_command = '~/download/bin/ruby_repl'
|
||||
repl_command = '~/download/bin/ruby_repl'
|
||||
format_on_save = true
|
||||
<
|
||||
KEY BINDINGS
|
||||
|
@ -10,11 +10,11 @@ lang: zh
|
||||
|
||||
- [模块描述](#模块描述)
|
||||
- [依赖安装及启用模块](#依赖安装及启用模块)
|
||||
- [启用模块](#启用模块)
|
||||
- [依赖安装](#依赖安装)
|
||||
- [启用模块](#启用模块)
|
||||
- [模块选项](#模块选项)
|
||||
- [快捷键](#快捷键)
|
||||
- [交互式编程](#交互式编程)
|
||||
- [RuboCop](#rubocop)
|
||||
- [运行当前脚本](#运行当前脚本)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -25,6 +25,14 @@ lang: zh
|
||||
|
||||
## 依赖安装及启用模块
|
||||
|
||||
### 依赖安装
|
||||
|
||||
为了启用 Ruby 语法检查和代码格式化,需要安装 [cobocop](https://github.com/bbatsov/rubocop)。
|
||||
|
||||
```sh
|
||||
gem install rubocop
|
||||
```
|
||||
|
||||
### 启用模块
|
||||
|
||||
可通过在配置文件内加入如下配置来启用该模块:
|
||||
@ -34,14 +42,38 @@ lang: zh
|
||||
name = "lang#ruby"
|
||||
```
|
||||
|
||||
### 依赖安装
|
||||
## 模块选项
|
||||
|
||||
为了启用 Ruby 语法检查和代码格式化,需要安装 [cobocop](https://github.com/bbatsov/rubocop)。
|
||||
- `ruby_file_head`: 设置新建 Ruby 文件时的默认文件头。
|
||||
默认情况下,当新建一个 Ruby 文件时,SpaceVim 会自动在文件顶部添加文件头信息。
|
||||
如果需要修改默认的文件头模板,可以使用 `ruby_file_head` 选项:
|
||||
|
||||
```sh
|
||||
gem install rubocop
|
||||
```
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#python"
|
||||
ruby_file_head = [
|
||||
'#!/usr/bin/ruby -w',
|
||||
'# -*- coding: utf-8 -*-',
|
||||
'',
|
||||
''
|
||||
]
|
||||
```
|
||||
|
||||
- `format_on_save`: 启用/禁用保存 Ruby 文件时的自动格式化,默认为 `false`,
|
||||
若需要启用该功能,可将值设为 `true`。
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
format_on_save = true
|
||||
```
|
||||
|
||||
- `enabled_linters`: 设置 Ruby 语言默认的语法检查工具,默认为 `['rubylint']`,
|
||||
若需要添加其他的语法检查工具,可以修改值为:
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
enabled_linters = ['rubylint', 'rubocop']
|
||||
```
|
||||
## 快捷键
|
||||
|
||||
### 交互式编程
|
||||
@ -56,12 +88,6 @@ gem install rubocop
|
||||
| `SPC l s l` | 发送当前行内容至 REPL |
|
||||
| `SPC l s s` | 发送已选中的内容至 REPL |
|
||||
|
||||
### RuboCop
|
||||
|
||||
| 快捷键 | 按键描述 |
|
||||
| ----------- | ------------------------- |
|
||||
| `SPC l c f` | 使用 RuboCop 处理当前文件 |
|
||||
|
||||
### 运行当前脚本
|
||||
|
||||
在编辑 Ruby 文件时,可通过快捷键 `SPC l r` 快速异步运行当前文件,运行结果会展示在一个独立的执行窗口内。
|
||||
|
@ -142,7 +142,7 @@ you need to add following snippet into your spacevim configuration file.
|
||||
python_interpreter = 'D:\scoop\shims\python.exe'
|
||||
```
|
||||
|
||||
- `python_linters`: Set the default linters for python language, by default it is `['python']`. You can change
|
||||
- `enabled_linters`: Set the default linters for python language, by default it is `['python']`. You can change
|
||||
it to `['python', 'pylint']`.
|
||||
```toml
|
||||
[[layers]]
|
||||
|
@ -10,10 +10,9 @@ description: "This layer is for Ruby development, provide autocompletion, syntax
|
||||
- [Description](#description)
|
||||
- [Install](#install)
|
||||
- [Layer](#layer)
|
||||
- [Syntax checking && Code formatting](#syntax-checking--code-formatting)
|
||||
- [Layer options](#layer-options)
|
||||
- [Key bindings](#key-bindings)
|
||||
- [Inferior REPL process](#inferior-repl-process)
|
||||
- [RuboCop](#rubocop)
|
||||
- [Running current script](#running-current-script)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -33,20 +32,66 @@ To use this configuration layer, update custom configuration file with:
|
||||
name = "lang#ruby"
|
||||
```
|
||||
|
||||
### Syntax checking && Code formatting
|
||||
The default syntax linter for ruby is [rubylint](https://gitlab.com/yorickpeterse/ruby-lint).
|
||||
|
||||
To enable syntax checking and code formatting in spacevim, you need to install [rubocop](https://github.com/bbatsov/rubocop).
|
||||
```
|
||||
gem install ruby-lint
|
||||
```
|
||||
|
||||
The default code formatter is [rubocop](https://github.com/bbatsov/rubocop).
|
||||
|
||||
```sh
|
||||
gem install rubocop
|
||||
```
|
||||
|
||||
## Layer options
|
||||
|
||||
- `ruby_file_head`: Default file head when create new ruby file.
|
||||
|
||||
By default, when create a new ruby file, SpaceVim will insert file head automatically.
|
||||
to change the file head, use `ruby_file_head` option:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#python"
|
||||
ruby_file_head = [
|
||||
'#!/usr/bin/ruby -w',
|
||||
'# -*- coding: utf-8 -*-',
|
||||
'',
|
||||
''
|
||||
]
|
||||
```
|
||||
|
||||
- `repl_command`: Set the REPL command for ruby.
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
repl_command = '~/download/bin/ruby_repl'
|
||||
```
|
||||
|
||||
- `format_on_save`: Enable/disable code formatting when saving ruby file. Default is `false`.
|
||||
To enable this feature:
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
format_on_save = true
|
||||
```
|
||||
|
||||
- `enabled_linters`: Set the default linters for ruby language, by default it is `['rubylint']`. You can change
|
||||
it to `['rubylint, 'rubocop']`.
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
enabled_linters = ['rubylint', 'rubocop']
|
||||
```
|
||||
|
||||
## Key bindings
|
||||
|
||||
### Inferior REPL process
|
||||
|
||||
Start a `irb` inferior REPL process with `SPC l s i`. You may change the REPL command by layer option `repl_command`. For example, if you want to use `pry`, load this layer via:
|
||||
Start a `irb` inferior REPL process with `SPC l s i`.
|
||||
You may change the REPL command by layer option `repl_command`.
|
||||
For example, if you want to use `pry`, load this layer via:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
@ -59,7 +104,7 @@ however, if the executable is not on your $PATH, then you need to specify a comp
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#ruby"
|
||||
repl_command = "/NOT/IN/YOUR/PATH/rubocop"
|
||||
repl_command = "/path/to/pry"
|
||||
```
|
||||
|
||||
Send code to inferior process commands:
|
||||
@ -70,12 +115,6 @@ Send code to inferior process commands:
|
||||
| `SPC l s l` | send line and keep code buffer focused |
|
||||
| `SPC l s s` | send selection text and keep code buffer focused |
|
||||
|
||||
### RuboCop
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------ | ------------------------------------------ |
|
||||
| `SPC l c f` | Runs RuboCop on the currently visited file |
|
||||
|
||||
### Running current script
|
||||
|
||||
To running a Ruby script, you can press `SPC l r` to run current file without loss focus, and the result will be shown in a runner buffer.
|
||||
|
Loading…
Reference in New Issue
Block a user