mirror of
https://github.com/powerline/powerline.git
synced 2025-04-08 19:25:04 +02:00
Add support for literal segments to linter
This commit is contained in:
parent
bfd9a21bbb
commit
72f8b59998
@ -172,6 +172,15 @@ Detailed description of used dictionary keys:
|
||||
<config-themes-seg-after>`, :ref:`before <config-themes-seg-before>`) will
|
||||
be ignored.
|
||||
|
||||
.. note::
|
||||
If target is inclusion of the segment in powerline upstream all segment
|
||||
functions that output *only* subsegments with ``literal_contents`` key
|
||||
must contain the following string in documentation::
|
||||
|
||||
No highlight groups are used (literal segment).
|
||||
|
||||
String must be present on the separate line.
|
||||
|
||||
.. _dev-segments-draw_inner_divider:
|
||||
|
||||
``draw_hard_divider``, ``draw_soft_divider``, ``draw_inner_divider``
|
||||
|
@ -381,7 +381,10 @@ def check_segment_function(function_name, data, context, echoerr):
|
||||
hl_groups = []
|
||||
divider_hl_group = None
|
||||
|
||||
hadproblem = False
|
||||
|
||||
if func.__doc__:
|
||||
NO_H_G_USED_STR = 'No highlight groups are used (literal segment).'
|
||||
H_G_USED_STR = 'Highlight groups used: '
|
||||
LHGUS = len(H_G_USED_STR)
|
||||
D_H_G_USED_STR = 'Divider highlight group used: '
|
||||
@ -391,6 +394,20 @@ def check_segment_function(function_name, data, context, echoerr):
|
||||
for i, line in enumerate(func.__doc__.split('\n')):
|
||||
if H_G_USED_STR in line:
|
||||
idx = line.index(H_G_USED_STR) + LHGUS
|
||||
if hl_groups is None:
|
||||
idx -= LHGUS
|
||||
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
|
||||
echoerr(
|
||||
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||
context_mark=function_name.mark,
|
||||
problem=(
|
||||
'found highlight group definition in addition to sentense stating that '
|
||||
'no highlight groups are used'
|
||||
),
|
||||
problem_mark=mark,
|
||||
)
|
||||
hadproblem = True
|
||||
continue
|
||||
hl_groups.append((
|
||||
line[idx:],
|
||||
(mark_name, i + 1, idx + 1, func.__doc__),
|
||||
@ -400,10 +417,24 @@ def check_segment_function(function_name, data, context, echoerr):
|
||||
idx = line.index(D_H_G_USED_STR) + LDHGUS + 2
|
||||
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
|
||||
divider_hl_group = MarkedUnicode(line[idx:-3], mark)
|
||||
elif NO_H_G_USED_STR in line:
|
||||
idx = line.index(NO_H_G_USED_STR)
|
||||
if hl_groups:
|
||||
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
|
||||
echoerr(
|
||||
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||
context_mark=function_name.mark,
|
||||
problem=(
|
||||
'found sentense stating that no highlight groups are used '
|
||||
'in addition to highlight group definition'
|
||||
),
|
||||
problem_mark=mark,
|
||||
)
|
||||
hadproblem = True
|
||||
continue
|
||||
hl_groups = None
|
||||
pointer += len(line) + len('\n')
|
||||
|
||||
hadproblem = False
|
||||
|
||||
if divider_hl_group:
|
||||
r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True)
|
||||
if r:
|
||||
@ -466,7 +497,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
||||
h[0], list_sep.join(r))
|
||||
)
|
||||
hadproblem = True
|
||||
else:
|
||||
elif hl_groups is not None:
|
||||
r = hl_exists(function_name, data, context, echoerr, allow_gradients=True)
|
||||
if r:
|
||||
echoerr(
|
||||
|
@ -748,6 +748,8 @@ def tab(pl, segment_info, end=False):
|
||||
|
||||
:param bool end:
|
||||
In place of starting region for the current tab end it.
|
||||
|
||||
No highlight groups are used (literal segment).
|
||||
'''
|
||||
try:
|
||||
return [{
|
||||
|
Loading…
x
Reference in New Issue
Block a user