Skip to content

Commit

Permalink
revert: rollback to str.format for long lines (>120 chars)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Apr 21, 2024
1 parent cb1af4f commit 391562b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def format_completion(
details: list[str] = []
if can_resolve_completion_items or item.get('documentation'):
# Not using "make_command_link" in a hot path to avoid slow json.dumps.
args = f'{{"view_id":{view_id},"command":"lsp_resolve_docs","args":{{"index":{index},"session_name":"{session_name}"}}}}'
args = '{{"view_id":{},"command":"lsp_resolve_docs","args":{{"index":{},"session_name":"{}"}}}}'.format(
view_id, index, session_name)
href = f'subl:lsp_run_text_command_helper {args}'
details.append(f"<a href='{href}'>More</a>")
if lsp_label_detail and (lsp_label + lsp_label_detail).startswith(lsp_filter_text):
Expand Down
3 changes: 2 additions & 1 deletion plugin/core/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def record_crash(self, config_name: str, exit_code: int, exception: Exception |
self._crashes[config_name].append(now)
timeout = now - RETRY_COUNT_TIMEDELTA
crash_count = len([crash for crash in self._crashes[config_name] if crash > timeout])
printf(f"{config_name} crashed ({crash_count} / {RETRY_MAX_COUNT} times in the last {RETRY_COUNT_TIMEDELTA.total_seconds()} seconds), exit code {exit_code}, exception: {exception}")
printf("{} crashed ({} / {} times in the last {} seconds), exit code {}, exception: {}".format(
config_name, crash_count, RETRY_MAX_COUNT, RETRY_COUNT_TIMEDELTA.total_seconds(), exit_code, exception))
return crash_count < RETRY_MAX_COUNT

def _reenable_disabled_for_session(self, config_name: str) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def decode_semantic_token(
# this approach is limited to consider at most one modifier for the scope lookup
key = f"{token_type}.{token_modifier}"
if key in tokens_scope_map_dict:
scope = tokens_scope_map_dict[key] + f" meta.semantic-token.{token_type.lower()}.{token_modifier.lower()}.lsp"
scope = tokens_scope_map_dict[key] + " meta.semantic-token.{}.{}.lsp".format(
token_type.lower(), token_modifier.lower())
break # first match wins (in case of multiple modifiers)
else:
scope = tokens_scope_map_dict[token_type]
Expand Down
6 changes: 4 additions & 2 deletions plugin/core/tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def html(self, sheet_name: str, indent_level: int) -> str:
icon_html = '<span class="{}" title="{}">{}</span>'.format(
self._kind_class_name(self.kind[0]), self.kind[2], self.kind[1] if self.kind[1] else '&nbsp;')
if self.command_url and self.tooltip:
label_html = f'<a class="label" href="{self.command_url}" title="{html.escape(self.tooltip)}">{html.escape(self.label)}</a>'
label_html = '<a class="label" href="{}" title="{}">{}</a>'.format(
self.command_url, html.escape(self.tooltip), html.escape(self.label))
elif self.command_url:
label_html = f'<a class="label" href="{self.command_url}">{html.escape(self.label)}</a>'
elif self.tooltip:
Expand All @@ -70,7 +71,8 @@ def html(self, sheet_name: str, indent_level: int) -> str:
label_html = f'<span class="label">{html.escape(self.label)}</span>'
description_html = f'<span class="description">{html.escape(self.description)}</span>' if \
self.description else ''
return f'<div class="tree-view-row">{indent_html + disclosure_button_html + icon_html + label_html + description_html}</div>'
return '<div class="tree-view-row">{}</div>'.format(
indent_html + disclosure_button_html + icon_html + label_html + description_html)

@staticmethod
def _kind_class_name(kind_id: int) -> str:
Expand Down
3 changes: 2 additions & 1 deletion plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ def format_diagnostics_for_annotation(
message = text2html(diagnostic.get('message') or '')
source = diagnostic.get('source')
line = f"[{text2html(source)}] {message}" if source else message
content = f'<body id="annotation" class="{lsp_css().annotations_classname}"><style>{lsp_css().annotations}</style><div class="{css_class}">{line}</div></body>'
content = '<body id="annotation" class="{}"><style>{}</style><div class="{}">{}</div></body>'.format(
lsp_css().annotations_classname, lsp_css().annotations, css_class, line)
annotations.append(content)
return (annotations, color)

Expand Down
3 changes: 2 additions & 1 deletion plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ def incoming_notification(self, method: str, params: Any, unhandled: bool) -> No
self.log(self._format_notification(direction, method), params)

def _format_response(self, direction: str, request_id: Any, duration: str) -> str:
return f"[{RequestTimeTracker.formatted_now()}] {direction} {self._server_name} ({request_id}) (duration: {duration})"
return "[{}] {} {} ({}) (duration: {})".format(
RequestTimeTracker.formatted_now(), direction, self._server_name, request_id, duration)

def _format_request(self, direction: str, method: str, request_id: Any) -> str:
return f"[{RequestTimeTracker.formatted_now()}] {direction} {self._server_name} {method} ({request_id})"
Expand Down
4 changes: 2 additions & 2 deletions plugin/goto_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def open_location(session: Session, location: Location, flags: int = 0, group: i
def diagnostic_html(config: ClientConfig, diagnostic: Diagnostic, base_dir: Path | None) -> sublime.Html:
content = format_diagnostic_for_html(
config, truncate_message(diagnostic), None if base_dir is None else str(base_dir))
return sublime.Html(f'<style>{PREVIEW_PANE_CSS}</style><div class="diagnostics {format_severity(diagnostic_severity(diagnostic))}">{content}</div>')

return sublime.Html('<style>{}</style><div class="diagnostics {}">{}</div>'.format(
PREVIEW_PANE_CSS, format_severity(diagnostic_severity(diagnostic)), content))

def truncate_message(diagnostic: Diagnostic, max_lines: int = 6) -> Diagnostic:
lines = diagnostic["message"].splitlines()
Expand Down

0 comments on commit 391562b

Please sign in to comment.