From c8f361c9ca64712c0a8ab684635f5896e1fa0385 Mon Sep 17 00:00:00 2001 From: Pablo Acosta-Serafini Date: Mon, 23 Oct 2017 12:45:02 -0400 Subject: [PATCH 1/3] Added Vim segment plugin for the Asynchronous Linter Engine (ALE). This segment has the same functionality and interface as the Syntastic Vim segment plugin, and the code is largely adapted from it. Documentation stub is also included --- docs/source/configuration/segments/vim.rst | 6 ++ powerline/segments/vim/plugin/ale.py | 97 ++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 powerline/segments/vim/plugin/ale.py diff --git a/docs/source/configuration/segments/vim.rst b/docs/source/configuration/segments/vim.rst index b0f52c18..5df70d6c 100644 --- a/docs/source/configuration/segments/vim.rst +++ b/docs/source/configuration/segments/vim.rst @@ -9,6 +9,12 @@ Vim segments Plugin-specific segments ======================== +Asynchronous Linter Engine (ALE) segments +----------------------------------------- + +.. automodule:: powerline.segments.vim.plugin.ale + :members: + Syntastic segments ------------------ diff --git a/powerline/segments/vim/plugin/ale.py b/powerline/segments/vim/plugin/ale.py new file mode 100644 index 00000000..c7fb97a3 --- /dev/null +++ b/powerline/segments/vim/plugin/ale.py @@ -0,0 +1,97 @@ +# vim:fileencoding=utf-8:noet +""" +Asynchronous Lint Engine (ALE) plugin + +Largely adapted from Sytastic plugin +""" + +from __future__ import ( + unicode_literals, division, absolute_import, print_function +) +try: + import vim +except ImportError: + vim = object() +from powerline.bindings.vim import vim_global_exists +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 +def ale( + segment_info, + 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: + Format string for errors. + + :param str warn_format: + Format string for warnings. + + Highlight groups used: ``ale:warning`` or + ``warning``, ``ale:error`` or ``error``. + """ + # 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 + cmd = 'ale#statusline#Count({0}).total'.format(bufnr) + 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: + return + cmd = 'ale#engine#GetLoclist({0})'.format(bufnr) + if debug: + pl.info('cmd: {0}'.format(cmd)) + issues = vim.eval(cmd) + errors, warnings = [], [] + for issue in issues: + if issue['type'] == 'E': + errors.append(issue) + elif issue['type'] == 'W': + warnings.append(issue) + segments = [] + if errors: + segments.append( + { + 'contents': err_format.format( + first_line=errors[0]['lnum'], num=len(errors) + ), + 'highlight_groups': ['ale:error', 'error'], + } + ) + if warnings: + segments.append( + { + 'contents': warn_format.format( + first_line=warnings[0]['lnum'], num=len(warnings) + ), + 'highlight_groups': ['ale:warning', 'warning'], + } + ) + return segments From 67683ecbb8792fb2b558af1b60f950d9f44e5152 Mon Sep 17 00:00:00 2001 From: Pablo Acosta-Serafini Date: Tue, 24 Oct 2017 04:40:03 -0400 Subject: [PATCH 2/3] Introduced requested chanages --- powerline/segments/vim/plugin/ale.py | 100 ++++++++------------------- 1 file changed, 27 insertions(+), 73 deletions(-) diff --git a/powerline/segments/vim/plugin/ale.py b/powerline/segments/vim/plugin/ale.py index c7fb97a3..959c1c53 100644 --- a/powerline/segments/vim/plugin/ale.py +++ b/powerline/segments/vim/plugin/ale.py @@ -1,42 +1,17 @@ -# vim:fileencoding=utf-8:noet -""" -Asynchronous Lint Engine (ALE) plugin +from __future__ import (unicode_literals, division, absolute_import, print_function) -Largely adapted from Sytastic plugin -""" - -from __future__ import ( - unicode_literals, division, absolute_import, print_function -) try: import vim except ImportError: vim = object() + from powerline.bindings.vim import vim_global_exists 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 -def ale( - segment_info, - 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 +def ale(segment_info, pl, err_format='ERR: ln {first_line} ({num}) ', warn_format='WARN: ln {first_line} ({num}) '): + '''Show whether ALE has found any errors or warnings :param str err_format: Format string for errors. @@ -44,54 +19,33 @@ def ale( :param str warn_format: Format string for warnings. - Highlight groups used: ``ale:warning`` or - ``warning``, ``ale:error`` or ``error``. - """ - # 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: + Highlight groups used: ``ale:warning`` or ``warning``, ``ale:error`` or ``error``. + ''' + if not (vim_global_exists('ale_enabled') and int(vim.eval('g:ale_enabled'))): return None - cmd = 'ale#statusline#Count({0}).total'.format(bufnr) - if debug: - pl.info('cmd: {0}'.format(cmd)) - has_errors = int(vim.eval(cmd)) - if debug: - pl.info('has_errors: {0}'.format(has_errors)) + has_errors = int(vim.eval('ale#statusline#Count('+str(segment_info['bufnr'])+').total')) if not has_errors: return - cmd = 'ale#engine#GetLoclist({0})'.format(bufnr) - if debug: - pl.info('cmd: {0}'.format(cmd)) - issues = vim.eval(cmd) - errors, warnings = [], [] - for issue in issues: + error = None + warning = None + errors_count = 0 + warnings_count = 0 + for issue in vim.eval('ale#engine#GetLoclist('+str(segment_info['bufnr'])+')'): if issue['type'] == 'E': - errors.append(issue) + error = error or issue + errors_count += 1 elif issue['type'] == 'W': - warnings.append(issue) + warning = warning or issue + warnings_count += 1 segments = [] - if errors: - segments.append( - { - 'contents': err_format.format( - first_line=errors[0]['lnum'], num=len(errors) - ), - 'highlight_groups': ['ale:error', 'error'], - } - ) - if warnings: - segments.append( - { - 'contents': warn_format.format( - first_line=warnings[0]['lnum'], num=len(warnings) - ), - 'highlight_groups': ['ale:warning', 'warning'], - } - ) + if error: + segments.append({ + 'contents': err_format.format(first_line=error['lnum'], num=errors_count), + 'highlight_groups': ['ale:error', 'error'], + }) + if warning: + segments.append({ + 'contents': warn_format.format(first_line=warning['lnum'], num=warnings_count), + 'highlight_groups': ['ale:warning', 'warning'], + }) return segments From 421a71ee530a5319f0f24b63cfd655d92679227c Mon Sep 17 00:00:00 2001 From: Pablo Acosta-Serafini Date: Fri, 27 Oct 2017 08:44:47 -0400 Subject: [PATCH 3/3] Brought back modeline and added spaces around plus signs --- powerline/segments/vim/plugin/ale.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/powerline/segments/vim/plugin/ale.py b/powerline/segments/vim/plugin/ale.py index 959c1c53..4f4bdee4 100644 --- a/powerline/segments/vim/plugin/ale.py +++ b/powerline/segments/vim/plugin/ale.py @@ -1,3 +1,4 @@ +# vim:fileencoding=utf-8:noet from __future__ import (unicode_literals, division, absolute_import, print_function) try: @@ -23,14 +24,14 @@ def ale(segment_info, pl, err_format='ERR: ln {first_line} ({num}) ', warn_forma ''' if not (vim_global_exists('ale_enabled') and int(vim.eval('g:ale_enabled'))): return None - has_errors = int(vim.eval('ale#statusline#Count('+str(segment_info['bufnr'])+').total')) + has_errors = int(vim.eval('ale#statusline#Count(' + str(segment_info['bufnr']) + ').total')) if not has_errors: return error = None warning = None errors_count = 0 warnings_count = 0 - for issue in vim.eval('ale#engine#GetLoclist('+str(segment_info['bufnr'])+')'): + for issue in vim.eval('ale#engine#GetLoclist(' + str(segment_info['bufnr']) + ')'): if issue['type'] == 'E': error = error or issue errors_count += 1