Skip to content

Commit

Permalink
Support negative, or zero truncate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Oct 2, 2024
1 parent 17591c1 commit 09162a2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugin/inlay_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uui
})
result += f'<a href="{inlay_hint_click_command}">'
instruction_text = '\nDouble-click to insert' if has_text_edits else ""
truncated = len(label) >= truncate_limit
truncated = len(label) >= truncate_limit and truncate_limit > 0
truncated_label = label[:truncate_limit] + '…' if truncated else label
result_tooltip = (tooltip + instruction_text).strip()
result += f'<span title="{result_tooltip}">{html.escape(truncated_label)}</span>'
Expand All @@ -158,7 +158,7 @@ def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uui

remaining_truncate_limit = truncate_limit
for label_part in label:
if remaining_truncate_limit <= 0:
if remaining_truncate_limit <= 0 and truncate_limit > 0:
break
value = ""
tooltip = format_inlay_hint_tooltip(label_part.get("tooltip"))
Expand All @@ -175,7 +175,7 @@ def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uui
})
value += f'<a href="{inlay_hint_click_command}">'
raw_label = label_part['value']
truncated = len(raw_label) >= remaining_truncate_limit
truncated = len(raw_label) >= remaining_truncate_limit and truncate_limit > 0
truncated_label = raw_label[:remaining_truncate_limit] + '…' if truncated else raw_label
remaining_truncate_limit -= len(raw_label)
value += html.escape(truncated_label)
Expand Down

0 comments on commit 09162a2

Please sign in to comment.