mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Introduced requested chanages
This commit is contained in:
parent
c8f361c9ca
commit
67683ecbb8
@ -1,42 +1,17 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
"""
|
|
||||||
Asynchronous Lint Engine (ALE) plugin
|
|
||||||
|
|
||||||
Largely adapted from Sytastic plugin
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import (
|
|
||||||
unicode_literals, division, absolute_import, print_function
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
import vim
|
import vim
|
||||||
except ImportError:
|
except ImportError:
|
||||||
vim = object()
|
vim = object()
|
||||||
|
|
||||||
from powerline.bindings.vim import vim_global_exists
|
from powerline.bindings.vim import vim_global_exists
|
||||||
from powerline.theme import requires_segment_info
|
from powerline.theme import requires_segment_info
|
||||||
|
|
||||||
|
|
||||||
# To turn on logging, in the Powerline configuration fie config.json,
|
|
||||||
# in the "common" key, add log_file and log_level key-value pairs as
|
|
||||||
# appropriate and desired, for example:
|
|
||||||
#
|
|
||||||
# "common": {
|
|
||||||
# "term_truecolor": false,
|
|
||||||
# "log_file": "/mylogdir/powerline.log",
|
|
||||||
# "log_level": "INFO"
|
|
||||||
# },
|
|
||||||
#
|
|
||||||
# and then turn on debug internal variable to True
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def ale(
|
def ale(segment_info, pl, err_format='ERR: ln {first_line} ({num}) ', warn_format='WARN: ln {first_line} ({num}) '):
|
||||||
segment_info,
|
'''Show whether ALE has found any errors or warnings
|
||||||
pl,
|
|
||||||
err_format='ERR: {first_line} ({num}) ',
|
|
||||||
warn_format='WARN: {first_line} ({num}) '
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Show whether Asynchronous Lint Engine (ALE) has found any errors
|
|
||||||
or warnings
|
|
||||||
|
|
||||||
:param str err_format:
|
:param str err_format:
|
||||||
Format string for errors.
|
Format string for errors.
|
||||||
@ -44,54 +19,33 @@ def ale(
|
|||||||
:param str warn_format:
|
:param str warn_format:
|
||||||
Format string for warnings.
|
Format string for warnings.
|
||||||
|
|
||||||
Highlight groups used: ``ale:warning`` or
|
Highlight groups used: ``ale:warning`` or ``warning``, ``ale:error`` or ``error``.
|
||||||
``warning``, ``ale:error`` or ``error``.
|
'''
|
||||||
"""
|
if not (vim_global_exists('ale_enabled') and int(vim.eval('g:ale_enabled'))):
|
||||||
# pylint: disable=C0103,W0613
|
|
||||||
debug = False
|
|
||||||
bufnr = str(segment_info['bufnr'])
|
|
||||||
ale_enabled_exists = vim_global_exists('ale_enabled')
|
|
||||||
ale_enabled = ale_enabled_exists and int(vim.eval('g:ale_enabled'))
|
|
||||||
if debug:
|
|
||||||
pl.info('ale_enabled_exists: {0}'.format(ale_enabled_exists))
|
|
||||||
pl.info('ale_enabled: {0}'.format(ale_enabled))
|
|
||||||
if not ale_enabled:
|
|
||||||
return None
|
return None
|
||||||
cmd = 'ale#statusline#Count({0}).total'.format(bufnr)
|
has_errors = int(vim.eval('ale#statusline#Count('+str(segment_info['bufnr'])+').total'))
|
||||||
if debug:
|
|
||||||
pl.info('cmd: {0}'.format(cmd))
|
|
||||||
has_errors = int(vim.eval(cmd))
|
|
||||||
if debug:
|
|
||||||
pl.info('has_errors: {0}'.format(has_errors))
|
|
||||||
if not has_errors:
|
if not has_errors:
|
||||||
return
|
return
|
||||||
cmd = 'ale#engine#GetLoclist({0})'.format(bufnr)
|
error = None
|
||||||
if debug:
|
warning = None
|
||||||
pl.info('cmd: {0}'.format(cmd))
|
errors_count = 0
|
||||||
issues = vim.eval(cmd)
|
warnings_count = 0
|
||||||
errors, warnings = [], []
|
for issue in vim.eval('ale#engine#GetLoclist('+str(segment_info['bufnr'])+')'):
|
||||||
for issue in issues:
|
|
||||||
if issue['type'] == 'E':
|
if issue['type'] == 'E':
|
||||||
errors.append(issue)
|
error = error or issue
|
||||||
|
errors_count += 1
|
||||||
elif issue['type'] == 'W':
|
elif issue['type'] == 'W':
|
||||||
warnings.append(issue)
|
warning = warning or issue
|
||||||
|
warnings_count += 1
|
||||||
segments = []
|
segments = []
|
||||||
if errors:
|
if error:
|
||||||
segments.append(
|
segments.append({
|
||||||
{
|
'contents': err_format.format(first_line=error['lnum'], num=errors_count),
|
||||||
'contents': err_format.format(
|
'highlight_groups': ['ale:error', 'error'],
|
||||||
first_line=errors[0]['lnum'], num=len(errors)
|
})
|
||||||
),
|
if warning:
|
||||||
'highlight_groups': ['ale:error', 'error'],
|
segments.append({
|
||||||
}
|
'contents': warn_format.format(first_line=warning['lnum'], num=warnings_count),
|
||||||
)
|
'highlight_groups': ['ale:warning', 'warning'],
|
||||||
if warnings:
|
})
|
||||||
segments.append(
|
|
||||||
{
|
|
||||||
'contents': warn_format.format(
|
|
||||||
first_line=warnings[0]['lnum'], num=len(warnings)
|
|
||||||
),
|
|
||||||
'highlight_groups': ['ale:warning', 'warning'],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return segments
|
return segments
|
||||||
|
Loading…
x
Reference in New Issue
Block a user