Skip to content

Ensure signature help label contains parameter substrings per LSP spec - #728

Open
SoulSniper-V2 wants to merge 1 commit into
python-lsp:developfrom
SoulSniper-V2:fix/signature-help-param-labels
Open

SoulSniper-V2 wants to merge 1 commit into
python-lsp:developfrom
SoulSniper-V2:fix/signature-help-param-labels

Conversation

@SoulSniper-V2

@SoulSniper-V2 SoulSniper-V2 commented Sep 26, 2026 •

Copy link
Copy Markdown

Problem

When signature help is requested for callable objects whose docstring header does not explicitly list the parameter signature (for example, callable class instances or C-extensions/ufuncs), pylsp could return a truncated label like MyCallable() or ufunc() while parameters lists parameter names like ['a', 'b'] or ['args', 'kwargs'].

According to the LSP 3.17 specification:

Note: a label of type string should be a substring of its containing signature label. Its intended use case is to highlight the parameter label part in the SignatureInformation.label.

Because parameter labels were not substrings of the signature label, strict LSP clients (such as YouCompleteMe) report a protocol error / invalid signature message.

Reported in #678.

Root cause

In pylsp/plugins/signature.py:

  1. function_sig was parsed by splitting s.docstring() on \n\n and taking the first line/paragraph. For callable instances or objects whose docstring begins with a class or type header without parameter names (e.g. ufunc()), this produced a header without parameters.
  2. s.params was populated with parameter objects whose names (p.name) were not contained in the truncated label.

Fix

  1. Use Jedi's s.to_string() to obtain the canonical signature string (e.g. MyCallable(a, b=1)), falling back to docstring parsing if to_string() is empty or unavailable.
  2. If s.params is present and any parameter name is not a substring of function_sig, construct the label as f"{name}({param_list})" so that all parameter names are guaranteed to be substrings of the signature label.
  3. As an additional safeguard, ensure parameter entries in sig["parameters"] are only included if their label is a substring of the containing signature label per the LSP specification.

Test

Added unit tests in test/plugins/test_signature.py:

  • test_callable_instance_signature: Verifies that signature help for a callable class instance includes its parameters in the signature label and that all parameter labels are substrings of the signature label.
  • test_signature_fallback_when_label_missing_params: Verifies fallback formatting when a signature label would otherwise omit parameter names.

Fixes #678

Copilot AI lite review requested due to automatic review settings September 26, 2026 23:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid signature message received from the LSP server

2 participants