diff --git a/LSP.sublime-settings b/LSP.sublime-settings
index 0bf0e6902..4a5a7c141 100644
--- a/LSP.sublime-settings
+++ b/LSP.sublime-settings
@@ -180,6 +180,10 @@
// or a custom keybinding.
"show_inlay_hints": false,
+ // Maximum length for inlay hints. Truncates exceeding characters and adds an ellipsis.
+ // Set to 0 for unlimited length.
+ "inlay_hints_max_length": 30,
+
// Highlighting style of "highlights": accentuating nearby text entities that
// are related to the one under your cursor.
// Valid values are "background", "underline", "stippled", "outline", or "".
diff --git a/plugin/core/types.py b/plugin/core/types.py
index ade41ed75..b5d5b932f 100644
--- a/plugin/core/types.py
+++ b/plugin/core/types.py
@@ -227,6 +227,7 @@ class Settings:
show_code_actions = cast(str, None)
show_code_lens = cast(str, None)
show_inlay_hints = cast(bool, None)
+ inlay_hints_max_length = cast(int, None)
show_diagnostics_in_hover = cast(bool, None)
show_code_actions_in_hover = cast(bool, None)
show_diagnostics_annotations_severity_level = cast(int, None)
@@ -272,6 +273,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None:
r("show_code_actions", "annotation")
r("show_code_lens", "annotation")
r("show_inlay_hints", False)
+ r("inlay_hints_max_length", 30)
r("show_diagnostics_in_hover", True)
r("show_code_actions_in_hover", True)
r("show_diagnostics_annotations_severity_level", 0)
diff --git a/plugin/inlay_hint.py b/plugin/inlay_hint.py
index bebffdb91..69ffc6a1c 100644
--- a/plugin/inlay_hint.py
+++ b/plugin/inlay_hint.py
@@ -123,6 +123,7 @@ def format_inlay_hint_tooltip(tooltip: str | MarkupContent | None) -> str:
def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uuid: str) -> str:
+ truncate_limit = userprefs().inlay_hints_max_length
tooltip = format_inlay_hint_tooltip(inlay_hint.get("tooltip"))
result = ""
can_resolve_inlay_hint = session.has_capability('inlayHintProvider.resolveProvider')
@@ -140,13 +141,21 @@ def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uui
}
})
result += f''
+ truncated = len(label) > truncate_limit and truncate_limit > 0
+ truncated_label = label[:truncate_limit - 1] + '…' if truncated else label
instruction_text = '\nDouble-click to insert' if has_text_edits else ""
- result += f'{html.escape(label)}'
+ truncation_tooltip = f'\n{html.escape(label)}' if truncated else ""
+ result_tooltip = (tooltip + instruction_text + truncation_tooltip).strip()
+ result += f'{html.escape(truncated_label)}'
if is_clickable:
result += ""
return result
-
+ remaining_truncate_limit = truncate_limit
+ full_label = "".join(label_part['value'] for label_part in label)
+ full_label_truncated = len(full_label) > truncate_limit and truncate_limit > 0
for label_part in label:
+ if remaining_truncate_limit < 0 and truncate_limit > 0:
+ break
value = ""
tooltip = format_inlay_hint_tooltip(label_part.get("tooltip"))
has_command = bool(label_part.get('command'))
@@ -161,10 +170,15 @@ def format_inlay_hint_label(inlay_hint: InlayHint, session: Session, phantom_uui
}
})
value += f''
- value += html.escape(label_part['value'])
+ raw_label = label_part['value']
+ truncated = len(raw_label) > remaining_truncate_limit and truncate_limit > 0
+ truncated_label = raw_label[:remaining_truncate_limit - 1] + '…' if truncated else raw_label
+ remaining_truncate_limit -= len(raw_label)
+ value += html.escape(truncated_label)
if has_command:
value += ""
# InlayHintLabelPart.location is not supported
instruction_text = '\nDouble-click to execute' if has_command else ""
- result += f"{value}"
+ truncation_tooltip = f'\n{html.escape(full_label)}' if full_label_truncated else ""
+ result += f"{value}"
return result
diff --git a/sublime-package.json b/sublime-package.json
index 023541fe8..f98b52c50 100644
--- a/sublime-package.json
+++ b/sublime-package.json
@@ -739,6 +739,12 @@
"default": false,
"markdownDescription": "Show inlay hints in the editor. Inlay hints are short annotations within the code, which show variable types or parameter names.\nThis is the default value used for new windows but can be overriden per-window using the `LSP: Toggle Inlay Hints` command from the Command Palette, Main Menu or a custom keybinding."
},
+ "inlay_hints_max_length": {
+ "type": "integer",
+ "default": 30,
+ "minimum": 0,
+ "markdownDescription": "Maximum length for inlay hints. Truncates exceeding characters and adds an ellipsis. Set to 0 for unlimited length."
+ },
"initially_folded": {
"type": "array",
"items": {