Skip to content

Commit

Permalink
Merge pull request #1541 from SublimeLinter/auto-columns-for-panel-view
Browse files Browse the repository at this point in the history
Calculate column widths in the error panel
  • Loading branch information
kaste committed Feb 1, 2019
2 parents 952d62a + d959b2f commit caaa24e
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions panel_view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import chain
import os
import sublime
import sublime_plugin
Expand Down Expand Up @@ -329,11 +330,23 @@ def run_update_panel_cmd(panel, text=None):
panel.run_command(cmd, {'text': text, 'clear_sel': clear_sel})


def format_row(item):
def format_row(
item, error_type_width=7, linter_name_width=12, line_width=5,
col_width=4, code_width=12
):
line = item["line"] + 1
start = item["start"] + 1
code = ":{code:12}".format(**item) if item['code'] else ''
tmpl = " {LINE:>5}:{START:<4} {error_type:7} {linter:>12}{CODE} {msg}"
code_tmpl = ":{{code:{}}}".format(code_width)
code = (
code_tmpl.format(**item)
if item['code']
else ' ' * (code_width + (1 if code_width else 0)) # + 1 for the ':'
)
tmpl = (
" {{LINE:>{}}}:{{START:<{}}} {{error_type:{}}} "
"{{linter:<{}}}{{CODE}} {{msg}}"
.format(line_width, col_width, error_type_width, linter_name_width)
)
return tmpl.format(LINE=line, START=start, CODE=code, **item)


Expand All @@ -352,14 +365,32 @@ def fill_panel(window):
settings.set("result_base_dir", base_dir)

to_render = []
widths = dict(
zip(
('line_width', 'col_width', 'error_type_width', 'linter_name_width', 'code_width'),
map(
max,
zip(*[
(
len(str(error['line'])),
len(str(error['start'])),
len(error['error_type']),
len(error['linter']),
len(error['code']),
)
for error in chain(*errors_by_bid.values())
])
)
)
)
for bid, buf_errors in errors_by_bid.items():
# append header
to_render.append(format_header(path_dict[bid]))

# append lines
base_lineno = len(to_render)
for i, item in enumerate(buf_errors):
to_render.append(format_row(item))
to_render.append(format_row(item, **widths))
item["panel_line"] = base_lineno + i

# insert empty line between views sections
Expand Down

0 comments on commit caaa24e

Please sign in to comment.