Merge remote-tracking branch 'origin/echo-string-format'
This commit is contained in:
commit
56894b432e
37
README.md
37
README.md
@ -76,20 +76,23 @@ vimrc file for all given linters is as follows:
|
|||||||
|
|
||||||
| Option | Description | Default |
|
| Option | Description | Default |
|
||||||
| ------ | ----------- | ------- |
|
| ------ | ----------- | ------- |
|
||||||
| `g:ale_linters` | a dictionary of linters to whitelist | _not set_ |
|
| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` |
|
||||||
| `g:ale_lint_on_text_changed` | lint while typing | `1` |
|
| `g:ale_echo_msg_format` | string format to use for the echoed message | `'%s'` |
|
||||||
|
| `g:ale_echo_msg_error_str` | string used for error severity in echoed message | `'Error'` |
|
||||||
|
| `g:ale_echo_msg_warning_str` | string used for warning severity in echoed message | `'Warning'` |
|
||||||
| `g:ale_lint_delay` | milliseconds to wait before linting | `200` |
|
| `g:ale_lint_delay` | milliseconds to wait before linting | `200` |
|
||||||
|
| `g:ale_linters` | a dictionary of linters to whitelist | _not set_ |
|
||||||
| `g:ale_lint_on_enter` | lint when opening a file | `1` |
|
| `g:ale_lint_on_enter` | lint when opening a file | `1` |
|
||||||
| `g:ale_lint_on_save` | lint when saving a file | `0` |
|
| `g:ale_lint_on_save` | lint when saving a file | `0` |
|
||||||
|
| `g:ale_lint_on_text_changed` | lint while typing | `1` |
|
||||||
| `g:ale_set_loclist` | set the loclist with errors | `1` |
|
| `g:ale_set_loclist` | set the loclist with errors | `1` |
|
||||||
| `g:ale_set_signs` | set gutter signs with error markers | `has('signs')` |
|
| `g:ale_set_signs` | set gutter signs with error markers | `has('signs')` |
|
||||||
| `g:ale_sign_column_always` | always show the sign gutter | `0` |
|
| `g:ale_sign_column_always` | always show the sign gutter | `0` |
|
||||||
| `g:ale_sign_error` | the text to use for errors in the gutter | `'>>'` |
|
| `g:ale_sign_error` | the text to use for errors in the gutter | `'>>'` |
|
||||||
| `g:ale_sign_warning` | the text to use for warnings in the gutter | `'--'` |
|
|
||||||
| `g:ale_sign_offset` | an offset for sign ids | `1000000` |
|
| `g:ale_sign_offset` | an offset for sign ids | `1000000` |
|
||||||
| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` |
|
| `g:ale_sign_warning` | the text to use for warnings in the gutter | `'--'` |
|
||||||
|
| `g:ale_statusline_format` | string format to use in statusline flag | `['%d error(s)', '%d warning(s)', 'OK']` |
|
||||||
| `g:ale_warn_about_trailing_whitespace` | enable trailing whitespace warnings for some linters | `1` |
|
| `g:ale_warn_about_trailing_whitespace` | enable trailing whitespace warnings for some linters | `1` |
|
||||||
| `g:ale_statusline_format` | String format to use in statusline flag | `['%d error(s)', '%d warning(s)', 'OK']` |
|
|
||||||
|
|
||||||
### Selecting Particular Linters
|
### Selecting Particular Linters
|
||||||
|
|
||||||
@ -155,6 +158,30 @@ let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
|
|||||||
![Statusline with issues](img/issues.png)
|
![Statusline with issues](img/issues.png)
|
||||||
![Statusline with no issues](img/no_issues.png)
|
![Statusline with no issues](img/no_issues.png)
|
||||||
|
|
||||||
|
|
||||||
|
### Customize echoed message
|
||||||
|
|
||||||
|
There are 3 global options that allow customizing the echoed message.
|
||||||
|
|
||||||
|
- `g:ale_echo_msg_format` where:
|
||||||
|
* `%s` is the error message itself
|
||||||
|
* `%linter%` is the linter name
|
||||||
|
* `%severity` is the severity type
|
||||||
|
- `g:ale_echo_msg_error_str` is the string used for error severity.
|
||||||
|
- `g:ale_echo_msg_warning_str` is the string used for warning severity.
|
||||||
|
|
||||||
|
So for example this:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:ale_echo_msg_error_str = 'E'
|
||||||
|
let g:ale_echo_msg_error_str = 'W'
|
||||||
|
let g:ale_echo_msg_fomat = '[%linter%] %s [%severity%]'
|
||||||
|
```
|
||||||
|
|
||||||
|
Will give you:
|
||||||
|
|
||||||
|
![Echoed message](img/echo.png)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
To install this plugin, you should use one of the following methods.
|
To install this plugin, you should use one of the following methods.
|
||||||
|
@ -27,7 +27,7 @@ function! ale_linters#coffee#coffeelint#Handle(buffer, lines)
|
|||||||
let line = l:match[1] + 0
|
let line = l:match[1] + 0
|
||||||
let column = 1
|
let column = 1
|
||||||
let type = l:match[3] ==# 'error' ? 'E' : 'W'
|
let type = l:match[3] ==# 'error' ? 'E' : 'W'
|
||||||
let text = l:match[3] . ': ' . l:match[4]
|
let text = l:match[4]
|
||||||
|
|
||||||
" vcol is needed to indicate that the column is a character
|
" vcol is needed to indicate that the column is a character
|
||||||
call add(output, {
|
call add(output, {
|
||||||
|
@ -23,7 +23,7 @@ function! ale_linters#yaml#yamllint#Handle(buffer, lines)
|
|||||||
let line = match[1] + 0
|
let line = match[1] + 0
|
||||||
let col = match[2] + 0
|
let col = match[2] + 0
|
||||||
let type = match[3]
|
let type = match[3]
|
||||||
let text = printf('[%s]%s', type, match[4])
|
let text = match[4]
|
||||||
|
|
||||||
" vcol is Needed to indicate that the column is a character.
|
" vcol is Needed to indicate that the column is a character.
|
||||||
call add(output, {
|
call add(output, {
|
||||||
|
39
doc/ale.txt
39
doc/ale.txt
@ -1,7 +1,7 @@
|
|||||||
*ale.txt* For Vim version 8.0. Last change: 2016 October 7
|
*ale.txt* For Vim version 8.0. Last change: 2016 October 10
|
||||||
*ale*
|
*ale*
|
||||||
|
|
||||||
ALE - Asychronous Lint Engine
|
ALE - Asynchronous Lint Engine
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
CONTENTS *ale-contents*
|
CONTENTS *ale-contents*
|
||||||
@ -157,7 +157,7 @@ g:ale_set_signs *g:ale_set_signs*
|
|||||||
|
|
||||||
When this option is set to `1`, the |sign| column will be populated with
|
When this option is set to `1`, the |sign| column will be populated with
|
||||||
signs marking where errors and warnings appear in the file. The
|
signs marking where errors and warnings appear in the file. The
|
||||||
'ALEErrorSign' and 'ALEWarningSign' highlight groups will be used to provide
|
`ALEErrorSign` and `ALEWarningSign` highlight groups will be used to provide
|
||||||
highlighting for the signs. The text used for signs can be customised with
|
highlighting for the signs. The text used for signs can be customised with
|
||||||
the |g:ale_sign_error| and |g:ale_sign_warning| options.
|
the |g:ale_sign_error| and |g:ale_sign_warning| options.
|
||||||
|
|
||||||
@ -216,6 +216,39 @@ g:ale_echo_cursor *g:ale_echo_cursor*
|
|||||||
error at a column nearest to the cursor when the cursor is resting on a line
|
error at a column nearest to the cursor when the cursor is resting on a line
|
||||||
which contains a warning or error. This option can be set to `0` to disable
|
which contains a warning or error. This option can be set to `0` to disable
|
||||||
this behaviour.
|
this behaviour.
|
||||||
|
The format of the message can be customizable in |g:ale_echo_msg_format|.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_echo_msg_format *g:ale_echo_msg_format*
|
||||||
|
|
||||||
|
Type: |String|
|
||||||
|
Default: `%s`
|
||||||
|
|
||||||
|
This variable defines the format of the echoed message. The `%s` is the
|
||||||
|
error message itself, and it can contain the following handlers:
|
||||||
|
- `%linter%` for linter's name
|
||||||
|
- `%severity%` for the type of severity
|
||||||
|
Note |`g:ale_echo_cursor`| should be setted to 1
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_echo_msg_error_str *g:ale_echo_msg_error_str*
|
||||||
|
|
||||||
|
Type: |String|
|
||||||
|
Default: `Error`
|
||||||
|
|
||||||
|
The string used for error severity in the echoed message.
|
||||||
|
Note |`g:ale_echo_cursor`| should be setted to 1
|
||||||
|
Note |`g:ale_echo_msg_format`| should contain the `%severity%` handler
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_echo_msg_warning_str *g:ale_echo_msg_warning_str*
|
||||||
|
|
||||||
|
Type: |String|
|
||||||
|
Default: `Warning`
|
||||||
|
|
||||||
|
The string used for warning severity in the echoed message.
|
||||||
|
Note |`g:ale_echo_cursor`| should be setted to 1
|
||||||
|
Note |`g:ale_echo_msg_format`| should contain the `%severity%` handler
|
||||||
|
|
||||||
|
|
||||||
g:ale_warn_about_trailing_whitespace *g:ale_warn_about_trailing_whitespace*
|
g:ale_warn_about_trailing_whitespace *g:ale_warn_about_trailing_whitespace*
|
||||||
|
BIN
img/echo.png
Normal file
BIN
img/echo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
@ -48,3 +48,12 @@ let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
|
|||||||
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
|
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
|
||||||
\ ['%d error(s)', '%d warning(s)', 'OK']
|
\ ['%d error(s)', '%d warning(s)', 'OK']
|
||||||
\)
|
\)
|
||||||
|
|
||||||
|
" String format for the echoed message
|
||||||
|
" A %s is mandatory
|
||||||
|
" It can contain 2 handlers: %linter%, %severity%
|
||||||
|
let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%s')
|
||||||
|
|
||||||
|
" Strings used for severity in the echoed message
|
||||||
|
let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error')
|
||||||
|
let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning')
|
||||||
|
@ -7,6 +7,23 @@ endif
|
|||||||
|
|
||||||
let g:loaded_ale_cursor = 1
|
let g:loaded_ale_cursor = 1
|
||||||
|
|
||||||
|
" Return a formatted message according to g:ale_echo_msg_format variable
|
||||||
|
function! s:GetMessage(linter, type, text) abort
|
||||||
|
let msg = g:ale_echo_msg_format
|
||||||
|
let type = a:type ==# 'E'
|
||||||
|
\ ? g:ale_echo_msg_error_str
|
||||||
|
\ : g:ale_echo_msg_warning_str
|
||||||
|
" Capitalize the 1st character
|
||||||
|
let text = toupper(a:text[0]) . a:text[1:-1]
|
||||||
|
|
||||||
|
" Replace handlers if they exist
|
||||||
|
for [k, v] in items({'linter': a:linter, 'severity': type})
|
||||||
|
let msg = substitute(msg, '\V%' . k . '%', v, '')
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return printf(msg, text)
|
||||||
|
endfunction
|
||||||
|
|
||||||
" This function will perform a binary search to find a message from the
|
" This function will perform a binary search to find a message from the
|
||||||
" loclist to echo when the cursor moves.
|
" loclist to echo when the cursor moves.
|
||||||
function! s:BinarySearch(loclist, line, column)
|
function! s:BinarySearch(loclist, line, column)
|
||||||
@ -81,7 +98,9 @@ function! ale#cursor#EchoCursorWarning(...)
|
|||||||
let index = s:BinarySearch(loclist, pos[1], pos[2])
|
let index = s:BinarySearch(loclist, pos[1], pos[2])
|
||||||
|
|
||||||
if index >= 0
|
if index >= 0
|
||||||
call ale#cursor#TruncatedEcho(loclist[index]['text'])
|
let l = loclist[index]
|
||||||
|
let msg = s:GetMessage(l.linter_name, l.type, l.text)
|
||||||
|
call ale#cursor#TruncatedEcho(msg)
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
endif
|
endif
|
||||||
|
@ -137,6 +137,11 @@ function! s:HandleExit(job)
|
|||||||
" Make some adjustments to the loclists to fix common problems.
|
" Make some adjustments to the loclists to fix common problems.
|
||||||
call s:FixLoclist(buffer, linter_loclist)
|
call s:FixLoclist(buffer, linter_loclist)
|
||||||
|
|
||||||
|
" Remember which linter returned these items for later use.
|
||||||
|
for obj in linter_loclist
|
||||||
|
let obj.linter_name = linter.name
|
||||||
|
endfor
|
||||||
|
|
||||||
if g:ale_buffer_should_reset_map[buffer]
|
if g:ale_buffer_should_reset_map[buffer]
|
||||||
let g:ale_buffer_should_reset_map[buffer] = 0
|
let g:ale_buffer_should_reset_map[buffer] = 0
|
||||||
let g:ale_buffer_loclist_map[buffer] = []
|
let g:ale_buffer_loclist_map[buffer] = []
|
||||||
|
Loading…
Reference in New Issue
Block a user