mirror of
https://github.com/powerline/powerline.git
synced 2025-07-22 13:25:13 +02:00
Improve shown errors
This commit is contained in:
parent
fee328666f
commit
ae691b7cd8
@ -894,10 +894,12 @@ def check_args(get_segment_variants, args, data, context, echoerr):
|
|||||||
|
|
||||||
if not count:
|
if not count:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
new_echoerr.echo_all()
|
if new_echoerr:
|
||||||
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context_key(context)),
|
new_echoerr.echo_all()
|
||||||
context_mark=context[-2][1].mark,
|
else:
|
||||||
problem='no suitable segments found')
|
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context_key(context)),
|
||||||
|
context_mark=context[-2][1].mark,
|
||||||
|
problem='no suitable segments found')
|
||||||
|
|
||||||
return True, False, hadproblem
|
return True, False, hadproblem
|
||||||
|
|
||||||
@ -912,7 +914,7 @@ def get_one_segment_variant(data, context, echoerr):
|
|||||||
|
|
||||||
def get_all_possible_segments(data, context, echoerr):
|
def get_all_possible_segments(data, context, echoerr):
|
||||||
name = context[-2][0]
|
name = context[-2][0]
|
||||||
module, name = (gen_marked_value(value, name.mark) for value in name.rpartition('.')[::2])
|
module, name = name.rpartition('.')[::2]
|
||||||
if module:
|
if module:
|
||||||
func = import_segment(name, data, context, echoerr, module=module)
|
func = import_segment(name, data, context, echoerr, module=module)
|
||||||
if func:
|
if func:
|
||||||
|
@ -29,6 +29,9 @@ class Mark:
|
|||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
self.pointer = pointer
|
self.pointer = pointer
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
return Mark(self.name, self.line, self.column, self.buffer, self.pointer)
|
||||||
|
|
||||||
def get_snippet(self, indent=4, max_length=75):
|
def get_snippet(self, indent=4, max_length=75):
|
||||||
if self.buffer is None:
|
if self.buffer is None:
|
||||||
return None
|
return None
|
||||||
|
@ -1,17 +1,71 @@
|
|||||||
__all__ = ['gen_marked_value', 'MarkedValue']
|
__all__ = ['gen_marked_value', 'MarkedValue']
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from __builtin__ import unicode
|
||||||
|
except ImportError:
|
||||||
|
unicode = str
|
||||||
|
|
||||||
|
|
||||||
|
def gen_new(cls):
|
||||||
|
def __new__(arg_cls, value, mark):
|
||||||
|
r = super(arg_cls, arg_cls).__new__(arg_cls, value)
|
||||||
|
r.mark = mark
|
||||||
|
r.value = value
|
||||||
|
return r
|
||||||
|
return __new__
|
||||||
|
|
||||||
|
|
||||||
|
class MarkedUnicode(unicode):
|
||||||
|
__new__ = gen_new(unicode)
|
||||||
|
|
||||||
|
def _proc_partition(self, part_result):
|
||||||
|
pointdiff = 1
|
||||||
|
r = []
|
||||||
|
for s in part_result:
|
||||||
|
mark = self.mark.copy()
|
||||||
|
# XXX Does not work properly with escaped strings, but this requires
|
||||||
|
# saving much more information in mark.
|
||||||
|
mark.column += pointdiff
|
||||||
|
mark.pointer += pointdiff
|
||||||
|
r.append(MarkedUnicode(s, mark))
|
||||||
|
pointdiff += len(s)
|
||||||
|
return tuple(r)
|
||||||
|
|
||||||
|
def rpartition(self, sep):
|
||||||
|
return self._proc_partition(super(MarkedUnicode, self).rpartition(sep))
|
||||||
|
|
||||||
|
def partition(self, sep):
|
||||||
|
return self._proc_partition(super(MarkedUnicode, self).partition(sep))
|
||||||
|
|
||||||
|
|
||||||
|
class MarkedInt(int):
|
||||||
|
__new__ = gen_new(int)
|
||||||
|
|
||||||
|
|
||||||
|
class MarkedFloat(float):
|
||||||
|
__new__ = gen_new(float)
|
||||||
|
|
||||||
|
|
||||||
class MarkedValue:
|
class MarkedValue:
|
||||||
def __init__(self, value, mark):
|
def __init__(self, value, mark):
|
||||||
self.mark = mark
|
self.mark = mark
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
|
|
||||||
|
specialclasses = {
|
||||||
|
unicode: MarkedUnicode,
|
||||||
|
int: MarkedInt,
|
||||||
|
float: MarkedFloat,
|
||||||
|
}
|
||||||
|
|
||||||
classcache = {}
|
classcache = {}
|
||||||
|
|
||||||
|
|
||||||
def gen_marked_value(value, mark):
|
def gen_marked_value(value, mark, use_special_classes=True):
|
||||||
if value.__class__ in classcache:
|
if use_special_classes and value.__class__ in specialclasses:
|
||||||
|
Marked = specialclasses[value.__class__]
|
||||||
|
elif value.__class__ in classcache:
|
||||||
Marked = classcache[value.__class__]
|
Marked = classcache[value.__class__]
|
||||||
else:
|
else:
|
||||||
class Marked(MarkedValue):
|
class Marked(MarkedValue):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user