Add vim plugin coc.nvim segments. (#2057)

* Add vim plugin coc.nvim segments.

* Add coc highlight group to colorschemes: default, solarized, solarizedlight.

* Fix coc highlight group in colorschemes: solarized, solarizedlight.

* Add document for segments.vim.plugin.coc.coc
This commit is contained in:
沈煜 2019-12-01 23:09:22 +08:00 committed by Philip Wellnitz
parent 4b24e715dc
commit d498f29261
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
try:
import vim
except ImportError:
vim = object()
from powerline.bindings.vim import vim_command_exists
from powerline.theme import requires_segment_info
# coc_status's format: E1 W2
def parse_coc_status(coc_status):
# type(coc_status) is tuple
errors_count = 0
warnings_count = 0
if len(coc_status) <= 0:
return errors_count, warnings_count
status_str = coc_status[0]
if len(status_str) <= 0:
return errors_count, warnings_count
status_list = status_str.split(' ')
for item in status_list:
if len(item) > 0 and item[0] == 'E':
errors_count = int(item[1:])
if len(item) > 0 and item[0] == 'W':
warnings_count = int(item[1:])
return errors_count, warnings_count
@requires_segment_info
def coc(segment_info, pl):
'''Show whether coc.nvim has found any errors or warnings
Highlight groups used: ``coc:warning`` or ``warning``, ``coc:error`` or ``error``.
'''
segments = []
if not vim_command_exists('CocCommand'):
return segments
coc_status = vim.eval('coc#status()'),
errors_count, warnings_count = parse_coc_status(coc_status)
if errors_count > 0:
segments.append({
'contents': 'E:' + str(errors_count),
'highlight_groups': ['coc:error', 'error'],
})
if warnings_count > 0:
segments.append({
'contents': 'W:' + str(warnings_count),
'highlight_groups': ['coc:warning', 'warning'],
})
return segments